exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_stat.c (4314B)


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