src/random.h \
src/server.c \
src/server.h \
+ src/stats.c \
+ src/stats.h \
src/util.c \
src/util.h \
src/worker.c \
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/timerfd.h>
-#include <time.h>
#include <unistd.h>
#include "client.h"
#include "logging.h"
#include "random.h"
#include "server.h"
-#include "util.h"
+#include "stats.h"
static int set_limits(struct fireperf_ctx* ctx) {
struct rlimit limit;
return r;
}
-int fireperf_dump_stats(struct fireperf_ctx* ctx, struct fireperf_stats* stats, int mode) {
- struct timespec now;
-
- // Fetch the time
- int r = clock_gettime(CLOCK_REALTIME, &now);
- if (r) {
- ERROR(ctx, "Could not fetch the time: %s\n", strerror(errno));
- return 1;
- }
-
- double delta = timespec_delta(&now, &stats->last_printed);
-
- // Called too soon again?
- if (delta < 0.1)
- return 0;
-
- // Format timestamp
- const char* timestamp = format_timespec(&now);
-
- INFO(ctx, "--- %s -------------------------\n", timestamp);
- INFO(ctx, " : %12s %12s\n", "RX", "TX");
- INFO(ctx, " %-20s: %25u\n", "Open Connection(s)", stats->open_connections);
- INFO(ctx, " %-20s: %23.2f/s\n", "New Connections", stats->connections / delta);
-
- // Show current bandwidth
- char* bps_received = format_size(stats->bytes_received * 8 / delta, FIREPERF_FORMAT_BITS);
- char* bps_sent = format_size(stats->bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS);
-
- if (bps_received || bps_sent) {
- INFO(ctx, " %-20s: %10s/s %10s/s\n", "Current Bandwidth", bps_received, bps_sent);
-
- if (bps_received)
- free(bps_received);
- if (bps_sent)
- free(bps_sent);
- }
-
- // Total bytes
- char* total_bytes_received = format_size(stats->total_bytes_received, FIREPERF_FORMAT_BYTES);
- char* total_bytes_sent = format_size(stats->total_bytes_sent, FIREPERF_FORMAT_BYTES);
-
- if (total_bytes_received || total_bytes_sent) {
- INFO(ctx, " %-20s: %12s %12s\n", "Total Bytes", total_bytes_received, total_bytes_sent);
-
- if (total_bytes_received)
- free(total_bytes_received);
- if (total_bytes_sent)
- free(total_bytes_sent);
- }
-
- // Empty line
- INFO(ctx, "\n");
-
- // Remember when this was printed last
- stats->last_printed = now;
-
- // Reset statistics
- stats->connections = 0;
- stats->bytes_received = 0;
- stats->bytes_sent = 0;
-
- return 0;
-}
-
int set_socket_buffer_sizes(struct fireperf_ctx* ctx, int fd) {
int r;
#ifndef FIREPERF_MAIN_H
#define FIREPERF_MAIN_H
-#include <time.h>
-
#include "ctx.h"
-
-// Struct to collect statistics
-struct fireperf_stats {
- struct timespec last_printed;
-
- // Total number of open connections
- unsigned int open_connections;
-
- // New connections
- unsigned int connections;
-
- // Total transferred data
- size_t bytes_received;
- size_t total_bytes_received;
- size_t bytes_sent;
- size_t total_bytes_sent;
-};
-
-int fireperf_dump_stats(struct fireperf_ctx* ctx, struct fireperf_stats* stats, int mode);
+#include "stats.h"
int set_socket_buffer_sizes(struct fireperf_ctx* ctx, int fd);
--- /dev/null
+/*#############################################################################
+# #
+# fireperf - A network benchmarking tool #
+# Copyright (C) 2024 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "ctx.h"
+#include "logging.h"
+#include "stats.h"
+#include "util.h"
+
+int fireperf_dump_stats(struct fireperf_ctx* ctx, struct fireperf_stats* stats, int mode) {
+ struct timespec now;
+
+ // Fetch the time
+ int r = clock_gettime(CLOCK_REALTIME, &now);
+ if (r) {
+ ERROR(ctx, "Could not fetch the time: %s\n", strerror(errno));
+ return 1;
+ }
+
+ double delta = timespec_delta(&now, &stats->last_printed);
+
+ // Called too soon again?
+ if (delta < 0.1)
+ return 0;
+
+ // Format timestamp
+ const char* timestamp = format_timespec(&now);
+
+ INFO(ctx, "--- %s -------------------------\n", timestamp);
+ INFO(ctx, " : %12s %12s\n", "RX", "TX");
+ INFO(ctx, " %-20s: %25u\n", "Open Connection(s)", stats->open_connections);
+ INFO(ctx, " %-20s: %23.2f/s\n", "New Connections", stats->connections / delta);
+
+ // Show current bandwidth
+ char* bps_received = format_size(stats->bytes_received * 8 / delta, FIREPERF_FORMAT_BITS);
+ char* bps_sent = format_size(stats->bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS);
+
+ if (bps_received || bps_sent) {
+ INFO(ctx, " %-20s: %10s/s %10s/s\n", "Current Bandwidth", bps_received, bps_sent);
+
+ if (bps_received)
+ free(bps_received);
+ if (bps_sent)
+ free(bps_sent);
+ }
+
+ // Total bytes
+ char* total_bytes_received = format_size(stats->total_bytes_received, FIREPERF_FORMAT_BYTES);
+ char* total_bytes_sent = format_size(stats->total_bytes_sent, FIREPERF_FORMAT_BYTES);
+
+ if (total_bytes_received || total_bytes_sent) {
+ INFO(ctx, " %-20s: %12s %12s\n", "Total Bytes", total_bytes_received, total_bytes_sent);
+
+ if (total_bytes_received)
+ free(total_bytes_received);
+ if (total_bytes_sent)
+ free(total_bytes_sent);
+ }
+
+ // Empty line
+ INFO(ctx, "\n");
+
+ // Remember when this was printed last
+ stats->last_printed = now;
+
+ // Reset statistics
+ stats->connections = 0;
+ stats->bytes_received = 0;
+ stats->bytes_sent = 0;
+
+ return 0;
+}
--- /dev/null
+/*#############################################################################
+# #
+# fireperf - A network benchmarking tool #
+# Copyright (C) 2024 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef FIREPERF_STATS_H
+#define FIREPERF_STATS_H
+
+#include <time.h>
+
+// Struct to collect statistics
+struct fireperf_stats {
+ struct timespec last_printed;
+
+ // Total number of open connections
+ unsigned int open_connections;
+
+ // New connections
+ unsigned int connections;
+
+ // Total transferred data
+ size_t bytes_received;
+ size_t total_bytes_received;
+ size_t bytes_sent;
+ size_t total_bytes_sent;
+};
+
+#include "ctx.h"
+
+int fireperf_dump_stats(struct fireperf_ctx* ctx, struct fireperf_stats* stats, int mode);
+
+#endif /* FIREPERF_STATS_H */