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 (4342B)


      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 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   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     if (cmd->run != &stat_run)
     64     {
     65       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     66                   "Bad timings for `%s'\n",
     67                   cmd->label);
     68       GNUNET_break (0);
     69     }
     70     return;
     71   }
     72   duration = GNUNET_TIME_absolute_get_difference (cmd->start_time,
     73                                                   cmd->finish_time);
     74   lat = GNUNET_TIME_absolute_get_difference (cmd->last_req_time,
     75                                              cmd->finish_time);
     76   for (unsigned int i = 0;
     77        NULL != timings[i].prefix;
     78        i++)
     79   {
     80     if (0 == strncmp (timings[i].prefix,
     81                       cmd->label,
     82                       strlen (timings[i].prefix)))
     83     {
     84       timings[i].total_duration
     85         = GNUNET_TIME_relative_add (duration,
     86                                     timings[i].total_duration);
     87       timings[i].success_latency
     88         = GNUNET_TIME_relative_add (lat,
     89                                     timings[i].success_latency);
     90       timings[i].num_commands++;
     91       timings[i].num_retries += cmd->num_tries;
     92       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 do_stat (void *cls,
    106          const struct TALER_TESTING_Command *cmd)
    107 {
    108   struct TALER_TESTING_Timer *timings = cls;
    109 
    110   if (TALER_TESTING_cmd_is_batch (cmd))
    111   {
    112     struct TALER_TESTING_Command *bcmd;
    113 
    114     if (GNUNET_OK !=
    115         TALER_TESTING_get_trait_batch_cmds (cmd,
    116                                             &bcmd))
    117     {
    118       GNUNET_break (0);
    119       return;
    120     }
    121     for (unsigned int j = 0;
    122          NULL != bcmd[j].label;
    123          j++)
    124       do_stat (timings,
    125                &bcmd[j]);
    126     return;
    127   }
    128   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 stat_run (void *cls,
    142           const struct TALER_TESTING_Command *cmd,
    143           struct TALER_TESTING_Interpreter *is)
    144 {
    145   struct TALER_TESTING_Timer *timings = cls;
    146 
    147   TALER_TESTING_iterate (is,
    148                          true,
    149                          &do_stat,
    150                          timings);
    151   TALER_TESTING_interpreter_next (is);
    152 }
    153 
    154 
    155 struct TALER_TESTING_Command
    156 TALER_TESTING_cmd_stat (struct TALER_TESTING_Timer *timers)
    157 {
    158   struct TALER_TESTING_Command cmd = {
    159     .label = "stat",
    160     .run = &stat_run,
    161     .cls = (void *) timers
    162   };
    163 
    164   return cmd;
    165 }
    166 
    167 
    168 /* end of testing_api_cmd_stat.c  */