Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2018 Taler Systems SA
4 :
5 : TALER 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 : TALER 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 TALER; see the file COPYING. If not, see
17 : <http://www.gnu.org/licenses/>
18 : */
19 : /**
20 : * @file testing/testing_api_cmd_stat.c
21 : * @brief command(s) to get performance statistics on other commands
22 : * @author Christian Grothoff
23 : */
24 : #include "taler/platform.h"
25 : #include "taler/taler_json_lib.h"
26 : #include <gnunet/gnunet_curl_lib.h>
27 : #include "taler/taler_testing_lib.h"
28 :
29 :
30 : /**
31 : * Run a "stat" CMD.
32 : *
33 : * @param cls closure.
34 : * @param cmd the command being run.
35 : * @param is the interpreter state.
36 : */
37 : static void
38 : stat_run (void *cls,
39 : const struct TALER_TESTING_Command *cmd,
40 : struct TALER_TESTING_Interpreter *is);
41 :
42 :
43 : /**
44 : * Add the time @a cmd took to the respective duration in @a timings.
45 : *
46 : * @param timings where to add up times
47 : * @param cmd command to evaluate
48 : */
49 : static void
50 0 : stat_cmd (struct TALER_TESTING_Timer *timings,
51 : const struct TALER_TESTING_Command *cmd)
52 : {
53 : struct GNUNET_TIME_Relative duration;
54 : struct GNUNET_TIME_Relative lat;
55 :
56 0 : if (GNUNET_TIME_absolute_cmp (cmd->start_time,
57 : >,
58 : cmd->finish_time))
59 : {
60 : /* This is a problem, except of course for
61 : this command itself, as we clearly did not yet
62 : finish... */
63 0 : if (cmd->run != &stat_run)
64 : {
65 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
66 : "Bad timings for `%s'\n",
67 : cmd->label);
68 0 : GNUNET_break (0);
69 : }
70 0 : return;
71 : }
72 0 : duration = GNUNET_TIME_absolute_get_difference (cmd->start_time,
73 : cmd->finish_time);
74 0 : lat = GNUNET_TIME_absolute_get_difference (cmd->last_req_time,
75 : cmd->finish_time);
76 0 : for (unsigned int i = 0;
77 0 : NULL != timings[i].prefix;
78 0 : i++)
79 : {
80 0 : if (0 == strncmp (timings[i].prefix,
81 0 : cmd->label,
82 0 : strlen (timings[i].prefix)))
83 : {
84 0 : timings[i].total_duration
85 0 : = GNUNET_TIME_relative_add (duration,
86 0 : timings[i].total_duration);
87 0 : timings[i].success_latency
88 0 : = GNUNET_TIME_relative_add (lat,
89 0 : timings[i].success_latency);
90 0 : timings[i].num_commands++;
91 0 : timings[i].num_retries += cmd->num_tries;
92 0 : break;
93 : }
94 : }
95 : }
96 :
97 :
98 : /**
99 : * Obtain statistics for @a timings of @a cmd
100 : *
101 : * @param[in,out] cls what timings to get
102 : * @param cmd command to process
103 : */
104 : static void
105 0 : do_stat (void *cls,
106 : const struct TALER_TESTING_Command *cmd)
107 : {
108 0 : struct TALER_TESTING_Timer *timings = cls;
109 :
110 0 : if (TALER_TESTING_cmd_is_batch (cmd))
111 : {
112 : struct TALER_TESTING_Command *bcmd;
113 :
114 0 : if (GNUNET_OK !=
115 0 : TALER_TESTING_get_trait_batch_cmds (cmd,
116 : &bcmd))
117 : {
118 0 : GNUNET_break (0);
119 0 : return;
120 : }
121 0 : for (unsigned int j = 0;
122 0 : NULL != bcmd[j].label;
123 0 : j++)
124 0 : do_stat (timings,
125 0 : &bcmd[j]);
126 0 : return;
127 : }
128 0 : stat_cmd (timings,
129 : cmd);
130 : }
131 :
132 :
133 : /**
134 : * Run a "stat" CMD.
135 : *
136 : * @param cls closure.
137 : * @param cmd the command being run.
138 : * @param is the interpreter state.
139 : */
140 : static void
141 0 : stat_run (void *cls,
142 : const struct TALER_TESTING_Command *cmd,
143 : struct TALER_TESTING_Interpreter *is)
144 : {
145 0 : struct TALER_TESTING_Timer *timings = cls;
146 :
147 0 : TALER_TESTING_iterate (is,
148 : true,
149 : &do_stat,
150 : timings);
151 0 : TALER_TESTING_interpreter_next (is);
152 0 : }
153 :
154 :
155 : struct TALER_TESTING_Command
156 0 : TALER_TESTING_cmd_stat (struct TALER_TESTING_Timer *timers)
157 : {
158 0 : struct TALER_TESTING_Command cmd = {
159 : .label = "stat",
160 : .run = &stat_run,
161 : .cls = (void *) timers
162 : };
163 :
164 0 : return cmd;
165 : }
166 :
167 :
168 : /* end of testing_api_cmd_stat.c */
|