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 "platform.h" 25 : #include "taler_json_lib.h" 26 : #include <gnunet/gnunet_curl_lib.h> 27 : #include "taler_testing_lib.h" 28 : 29 : 30 : /** 31 : * Add the time @a cmd took to the respective duration in @a timings. 32 : * 33 : * @param timings where to add up times 34 : * @param cmd command to evaluate 35 : */ 36 : static void 37 0 : stat_cmd (struct TALER_TESTING_Timer *timings, 38 : const struct TALER_TESTING_Command *cmd) 39 : { 40 : struct GNUNET_TIME_Relative duration; 41 : struct GNUNET_TIME_Relative lat; 42 : 43 0 : if (cmd->start_time.abs_value_us > cmd->finish_time.abs_value_us) 44 : { 45 0 : GNUNET_break (0); 46 0 : return; 47 : } 48 0 : duration = GNUNET_TIME_absolute_get_difference (cmd->start_time, 49 : cmd->finish_time); 50 0 : lat = GNUNET_TIME_absolute_get_difference (cmd->last_req_time, 51 : cmd->finish_time); 52 0 : for (unsigned int i = 0; 53 0 : NULL != timings[i].prefix; 54 0 : i++) 55 : { 56 0 : if (0 == strncmp (timings[i].prefix, 57 : cmd->label, 58 0 : strlen (timings[i].prefix))) 59 : { 60 0 : timings[i].total_duration 61 0 : = GNUNET_TIME_relative_add (duration, 62 0 : timings[i].total_duration); 63 0 : timings[i].success_latency 64 0 : = GNUNET_TIME_relative_add (lat, 65 0 : timings[i].success_latency); 66 0 : timings[i].num_commands++; 67 0 : timings[i].num_retries += cmd->num_tries; 68 0 : break; 69 : } 70 : } 71 : } 72 : 73 : 74 : /** 75 : * Obtain statistics for @a timings of @a cmd 76 : * 77 : * @param timings what timings to get 78 : * @param cmd command to process 79 : */ 80 : static void 81 0 : do_stat (struct TALER_TESTING_Timer *timings, 82 : const struct TALER_TESTING_Command *cmd) 83 : { 84 0 : if (TALER_TESTING_cmd_is_batch (cmd)) 85 : { 86 : struct TALER_TESTING_Command **bcmd; 87 : 88 0 : if (GNUNET_OK != 89 0 : TALER_TESTING_get_trait_batch_cmds (cmd, 90 : &bcmd)) 91 : { 92 0 : GNUNET_break (0); 93 0 : return; 94 : } 95 : 96 0 : for (unsigned int j = 0; 97 0 : NULL != (*bcmd)[j].label; 98 0 : j++) 99 0 : do_stat (timings, 100 0 : &(*bcmd)[j]); 101 : } 102 : else 103 : { 104 0 : stat_cmd (timings, 105 : cmd); 106 : } 107 : } 108 : 109 : 110 : /** 111 : * Run a "stat" CMD. 112 : * 113 : * @param cls closure. 114 : * @param cmd the command being run. 115 : * @param is the interpreter state. 116 : */ 117 : static void 118 0 : stat_run (void *cls, 119 : const struct TALER_TESTING_Command *cmd, 120 : struct TALER_TESTING_Interpreter *is) 121 : { 122 0 : struct TALER_TESTING_Timer *timings = cls; 123 : 124 0 : for (unsigned int i = 0; NULL != is->commands[i].label; i++) 125 : { 126 0 : if (cmd == &is->commands[i]) 127 0 : break; /* skip at our current command */ 128 0 : do_stat (timings, 129 0 : &is->commands[i]); 130 : } 131 0 : TALER_TESTING_interpreter_next (is); 132 0 : } 133 : 134 : 135 : struct TALER_TESTING_Command 136 0 : TALER_TESTING_cmd_stat (struct TALER_TESTING_Timer *timers) 137 : { 138 0 : struct TALER_TESTING_Command cmd = { 139 : .label = "stat", 140 : .run = stat_run, 141 : .cls = (void *) timers 142 : }; 143 : 144 0 : return cmd; 145 : } 146 : 147 : 148 : /* end of testing_api_cmd_sleep.c */