GNUnet 0.21.2
testing_api_cmd_stat.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 (C) 2018, 2024 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or
8 (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with GNUnet; see the file COPYING. If not, see
17 <http://www.gnu.org/licenses/>
18*/
24#include "platform.h"
25#include "gnunet_testing_lib.h"
27
34static void
35stat_run (void *cls,
37
38
45static void
47 const struct GNUNET_TESTING_Command *cmd)
48{
50 struct GNUNET_TIME_Relative lat;
51
53 >,
54 cmd->finish_time))
55 {
56 /* This is a problem, except of course for
57 this command itself, as we clearly did not yet
58 finish... */
59 if (cmd->run != &stat_run)
60 {
62 "Bad timings for `%s'\n",
63 cmd->label.value);
64 GNUNET_break (0);
65 }
66 return;
67 }
69 cmd->finish_time);
71 cmd->finish_time);
72 for (unsigned int i = 0;
73 NULL != timings[i].prefix;
74 i++)
75 {
76 if (0 == strncmp (timings[i].prefix,
77 cmd->label.value,
78 strlen (timings[i].prefix)))
79 {
80 timings[i].total_duration
82 timings[i].total_duration);
83 timings[i].success_latency
85 timings[i].success_latency);
86 timings[i].num_commands++;
87 timings[i].num_retries += cmd->num_tries;
88 break;
89 }
90 }
91}
92
93
100static void
101do_stat (void *cls,
102 const struct GNUNET_TESTING_Command *cmd)
103{
104 struct GNUNET_TESTING_Timer *timings = cls;
105
107 {
108 struct GNUNET_TESTING_Command **bcmd;
109
110 if (GNUNET_OK !=
112 &bcmd))
113 {
114 GNUNET_break (0);
115 return;
116 }
117 for (unsigned int j = 0;
118 NULL != (*bcmd)[j].run;
119 j++)
120 do_stat (timings,
121 &(*bcmd)[j]);
122 return;
123 }
124 stat_cmd (timings,
125 cmd);
126}
127
128
136static void
139{
140 struct GNUNET_TESTING_Timer *timings = cls;
141
143 true,
144 &do_stat,
145 timings);
146}
147
148
151 struct GNUNET_TESTING_Timer *timers)
152{
153 return GNUNET_TESTING_command_new ((void *) timers,
154 label,
155 &stat_run,
156 NULL,
157 NULL);
158}
159
160
161/* end of testing_api_cmd_stat.c */
static struct GNUNET_TESTING_Interpreter * is
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:66
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:90
void GNUNET_TESTING_interpreter_commands_iterate(struct GNUNET_TESTING_Interpreter *is, bool asc, GNUNET_TESTING_CommandIterator cb, void *cb_cls)
Iterates over all of the top-level commands of an interpreter.
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
Create a new command.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_batch_cmds(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Command ***ret)
#define GNUNET_log(kind,...)
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:585
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:421
A command to be run by the interpreter.
struct GNUNET_TIME_Absolute finish_time
When did the execution of this command finish?
struct GNUNET_TESTING_CommandLabel label
Label for the command.
struct GNUNET_TIME_Absolute last_req_time
When did we start the last run of this command? Delta to finish_time gives the latency for the last s...
GNUNET_TESTING_CommandRunRoutine run
Runs the command.
unsigned int num_tries
How often did we try to execute this command? (In case it is a request that is repated....
struct GNUNET_TIME_Absolute start_time
When did the execution of this command start?
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Performance counter.
unsigned int num_commands
Number of commands summed up.
const char * prefix
For which type of commands.
struct GNUNET_TIME_Relative total_duration
Total time spend in all commands of this type.
unsigned int num_retries
Number of retries summed up.
struct GNUNET_TIME_Relative success_latency
Total time spend waiting for the successful execution in all commands of this type.
Time for relative time used by GNUnet, in microseconds.
bool GNUNET_TESTING_cmd_is_batch_(const struct GNUNET_TESTING_Command *cmd)
Test if this command is a batch command.
static void stat_cmd(struct GNUNET_TESTING_Timer *timings, const struct GNUNET_TESTING_Command *cmd)
Add the time cmd took to the respective duration in timings.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stat(const char *label, struct GNUNET_TESTING_Timer *timers)
Obtain performance data from the interpreter.
static void stat_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run a "stat" CMD.
static void do_stat(void *cls, const struct GNUNET_TESTING_Command *cmd)
Obtain statistics for timings of cmd.