[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: -import stat cmd
From: |
gnunet |
Subject: |
[gnunet] branch master updated: -import stat cmd |
Date: |
Sun, 19 May 2024 16:43:39 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new e252eefcc -import stat cmd
e252eefcc is described below
commit e252eefcc163dd8129aa583888847d8aae61d95c
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun May 19 16:43:31 2024 +0200
-import stat cmd
---
src/include/gnunet_testing_lib.h | 36 +++++++-
src/lib/testing/Makefile.am | 1 +
src/lib/testing/testing_api_cmd_stat.c | 161 +++++++++++++++++++++++++++++++++
src/lib/testing/testing_api_loop.c | 34 +++++++
4 files changed, 229 insertions(+), 3 deletions(-)
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index 0050bd01a..be3fcc9bf 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -394,6 +394,35 @@ void
GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
+/**
+ * Callback over commands of an interpreter.
+ *
+ * @param cls closure
+ * @param cmd a command to process
+ */
+typedef void
+(*GNUNET_TESTING_CommandIterator)(
+ void *cls,
+ const struct GNUNET_TESTING_Command *cmd);
+
+
+/**
+ * Iterates over all of the top-level commands of an
+ * interpreter.
+ *
+ * @param[in] is interpreter to iterate over
+ * @param asc true in execution order, false for reverse execution order
+ * @param cb function to call on each command
+ * @param cb_cls closure for cb
+ */
+void
+GNUNET_TESTING_iterate (
+ struct GNUNET_TESTING_Interpreter *is,
+ bool asc,
+ GNUNET_TESTING_CommandIterator cb,
+ void *cb_cls);
+
+
/* ************** Fundamental interpreter commands ************ */
@@ -456,12 +485,13 @@ struct GNUNET_TESTING_Timer
/**
* Obtain performance data from the interpreter.
*
- * @param[in,out] timers what commands (by label) to obtain runtimes for
+ * @param label command label.
+ * @param[in,out] timers NULL-prefix terminated array that specifies what
commands (by label) to obtain runtimes for
* @return the command
*/
-// FIXME: review this API, seems, well, dangerous!
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
+GNUNET_TESTING_cmd_stat (const char *label,
+ struct GNUNET_TESTING_Timer *timers);
/**
diff --git a/src/lib/testing/Makefile.am b/src/lib/testing/Makefile.am
index 5035d286f..ec88359f3 100644
--- a/src/lib/testing/Makefile.am
+++ b/src/lib/testing/Makefile.am
@@ -33,6 +33,7 @@ libgnunettesting_la_SOURCES = \
testing_api_cmd_get_topo.c \
testing_api_cmd_netjail_start.c \
testing_api_cmd_netjail_start_cmds_helper.c \
+ testing_api_cmd_stat.c \
testing_api_cmds.c \
testing_api_loop.c testing_api_loop.h \
testing_api_main.c \
diff --git a/src/lib/testing/testing_api_cmd_stat.c
b/src/lib/testing/testing_api_cmd_stat.c
new file mode 100644
index 000000000..e8ad3c070
--- /dev/null
+++ b/src/lib/testing/testing_api_cmd_stat.c
@@ -0,0 +1,161 @@
+/*
+ This file is part of GNUnet
+ (C) 2018, 2024 GNUnet e.V.
+
+ GNUnet 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, or
+ (at your option) any later version.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_stat.c
+ * @brief command(s) to get performance statistics on other commands
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_testing_lib.h"
+#include "testing_api_cmd_batch.h"
+
+/**
+ * Run a "stat" CMD.
+ *
+ * @param cls closure.
+ * @param is the interpreter state.
+ */
+static void
+stat_run (void *cls,
+ struct GNUNET_TESTING_Interpreter *is);
+
+
+/**
+ * Add the time @a cmd took to the respective duration in @a timings.
+ *
+ * @param timings where to add up times
+ * @param cmd command to evaluate
+ */
+static void
+stat_cmd (struct GNUNET_TESTING_Timer *timings,
+ const struct GNUNET_TESTING_Command *cmd)
+{
+ struct GNUNET_TIME_Relative duration;
+ struct GNUNET_TIME_Relative lat;
+
+ if (GNUNET_TIME_absolute_cmp (cmd->start_time,
+ >,
+ cmd->finish_time))
+ {
+ /* This is a problem, except of course for
+ this command itself, as we clearly did not yet
+ finish... */
+ if (cmd->run != &stat_run)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Bad timings for `%s'\n",
+ cmd->label.value);
+ GNUNET_break (0);
+ }
+ return;
+ }
+ duration = GNUNET_TIME_absolute_get_difference (cmd->start_time,
+ cmd->finish_time);
+ lat = GNUNET_TIME_absolute_get_difference (cmd->last_req_time,
+ cmd->finish_time);
+ for (unsigned int i = 0;
+ NULL != timings[i].prefix;
+ i++)
+ {
+ if (0 == strncmp (timings[i].prefix,
+ cmd->label.value,
+ strlen (timings[i].prefix)))
+ {
+ timings[i].total_duration
+ = GNUNET_TIME_relative_add (duration,
+ timings[i].total_duration);
+ timings[i].success_latency
+ = GNUNET_TIME_relative_add (lat,
+ timings[i].success_latency);
+ timings[i].num_commands++;
+ timings[i].num_retries += cmd->num_tries;
+ break;
+ }
+ }
+}
+
+
+/**
+ * Obtain statistics for @a timings of @a cmd
+ *
+ * @param[in,out] cls what timings to get
+ * @param cmd command to process
+ */
+static void
+do_stat (void *cls,
+ const struct GNUNET_TESTING_Command *cmd)
+{
+ struct GNUNET_TESTING_Timer *timings = cls;
+
+ if (GNUNET_TESTING_cmd_is_batch_ (cmd))
+ {
+ struct GNUNET_TESTING_Command **bcmd;
+
+ if (GNUNET_OK !=
+ GNUNET_TESTING_get_trait_batch_cmds (cmd,
+ &bcmd))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ for (unsigned int j = 0;
+ NULL != bcmd[j]->run;
+ j++)
+ do_stat (timings,
+ bcmd[j]);
+ return;
+ }
+ stat_cmd (timings,
+ cmd);
+}
+
+
+/**
+ * Run a "stat" CMD.
+ *
+ * @param cls closure.
+ * @param cmd the command being run.
+ * @param is the interpreter state.
+ */
+static void
+stat_run (void *cls,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct GNUNET_TESTING_Timer *timings = cls;
+
+ GNUNET_TESTING_iterate (is,
+ true,
+ &do_stat,
+ timings);
+}
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_stat (const char *label,
+ struct GNUNET_TESTING_Timer *timers)
+{
+ return GNUNET_TESTING_command_new ((void *) timers,
+ label,
+ &stat_run,
+ NULL,
+ NULL);
+}
+
+
+/* end of testing_api_cmd_stat.c */
diff --git a/src/lib/testing/testing_api_loop.c
b/src/lib/testing/testing_api_loop.c
index 02bb43957..99ffe1143 100644
--- a/src/lib/testing/testing_api_loop.c
+++ b/src/lib/testing/testing_api_loop.c
@@ -786,4 +786,38 @@ GNUNET_TESTING_barrier_iterate_ (struct
GNUNET_TESTING_Interpreter *is,
}
+void
+GNUNET_TESTING_iterate (
+ struct GNUNET_TESTING_Interpreter *is,
+ bool asc,
+ GNUNET_TESTING_CommandIterator cb,
+ void *cb_cls)
+{
+ unsigned int start;
+ unsigned int end;
+ int inc;
+
+ if (asc)
+ {
+ inc = 1;
+ start = 0;
+ end = is->ip;
+ }
+ else
+ {
+ inc = -1;
+ start = is->ip;
+ end = 0;
+ }
+ for (unsigned int off = start; off != end + inc; off += inc)
+ {
+ const struct GNUNET_TESTING_Command *cmd
+ = &is->commands[off];
+
+ cb (cb_cls,
+ cmd);
+ }
+}
+
+
/* end of testing_api_loop.c */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: -import stat cmd,
gnunet <=