LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_stat.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 46 0.0 %
Date: 2021-08-30 06:43:37 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          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             :  * Cleanup the state from a "stat service" CMD.
      32             :  *
      33             :  * @param cls closure.
      34             :  * @param cmd the command which is being cleaned up.
      35             :  */
      36             : static void
      37           0 : stat_cleanup (void *cls,
      38             :               const struct TALER_TESTING_Command *cmd)
      39             : {
      40             :   (void) cls;
      41             :   (void) cmd;
      42             :   /* nothing to clean.  */
      43           0 : }
      44             : 
      45             : 
      46             : /**
      47             :  * No traits to offer, just provide a stub to be called when
      48             :  * some CMDs iterates through the list of all the commands.
      49             :  *
      50             :  * @param cls closure.
      51             :  * @param[out] ret result.
      52             :  * @param trait name of the trait.
      53             :  * @param index index number of the trait to return.
      54             :  * @return #GNUNET_OK on success.
      55             :  */
      56             : static int
      57           0 : stat_traits (void *cls,
      58             :              const void **ret,
      59             :              const char *trait,
      60             :              unsigned int index)
      61             : {
      62             :   (void) cls;
      63             :   (void) ret;
      64             :   (void) trait;
      65             :   (void) index;
      66           0 :   return GNUNET_NO;
      67             : }
      68             : 
      69             : 
      70             : /**
      71             :  * Add the time @a cmd took to the respective duration in @a timings.
      72             :  *
      73             :  * @param timings where to add up times
      74             :  * @param cmd command to evaluate
      75             :  */
      76             : static void
      77           0 : stat_cmd (struct TALER_TESTING_Timer *timings,
      78             :           const struct TALER_TESTING_Command *cmd)
      79             : {
      80             :   struct GNUNET_TIME_Relative duration;
      81             :   struct GNUNET_TIME_Relative lat;
      82             : 
      83           0 :   if (cmd->start_time.abs_value_us > cmd->finish_time.abs_value_us)
      84             :   {
      85           0 :     GNUNET_break (0);
      86           0 :     return;
      87             :   }
      88           0 :   duration = GNUNET_TIME_absolute_get_difference (cmd->start_time,
      89             :                                                   cmd->finish_time);
      90           0 :   lat = GNUNET_TIME_absolute_get_difference (cmd->last_req_time,
      91             :                                              cmd->finish_time);
      92           0 :   for (unsigned int i = 0;
      93           0 :        NULL != timings[i].prefix;
      94           0 :        i++)
      95             :   {
      96           0 :     if (0 == strncmp (timings[i].prefix,
      97             :                       cmd->label,
      98           0 :                       strlen (timings[i].prefix)))
      99             :     {
     100           0 :       timings[i].total_duration
     101           0 :         = GNUNET_TIME_relative_add (duration,
     102           0 :                                     timings[i].total_duration);
     103           0 :       timings[i].success_latency
     104           0 :         = GNUNET_TIME_relative_add (lat,
     105           0 :                                     timings[i].success_latency);
     106           0 :       timings[i].num_commands++;
     107           0 :       timings[i].num_retries += cmd->num_tries;
     108           0 :       break;
     109             :     }
     110             :   }
     111             : }
     112             : 
     113             : 
     114             : /**
     115             :  * Obtain statistics for @a timings of @a cmd
     116             :  *
     117             :  * @param timings what timings to get
     118             :  * @param cmd command to process
     119             :  */
     120             : static void
     121           0 : do_stat (struct TALER_TESTING_Timer *timings,
     122             :          const struct TALER_TESTING_Command *cmd)
     123             : {
     124           0 :   if (TALER_TESTING_cmd_is_batch (cmd))
     125             :   {
     126             : #define BATCH_INDEX 1
     127             :     struct TALER_TESTING_Command *bcmd;
     128             : 
     129           0 :     if (GNUNET_OK !=
     130           0 :         TALER_TESTING_get_trait_cmd (cmd,
     131             :                                      BATCH_INDEX,
     132             :                                      &bcmd))
     133             :     {
     134           0 :       GNUNET_break (0);
     135           0 :       return;
     136             :     }
     137             : 
     138           0 :     for (unsigned int j = 0; NULL != bcmd[j].label; j++)
     139           0 :       do_stat (timings,
     140           0 :                &bcmd[j]);
     141             :   }
     142             :   else
     143             :   {
     144           0 :     stat_cmd (timings,
     145             :               cmd);
     146             :   }
     147             : }
     148             : 
     149             : 
     150             : /**
     151             :  * Run a "stat" CMD.
     152             :  *
     153             :  * @param cls closure.
     154             :  * @param cmd the command being run.
     155             :  * @param is the interpreter state.
     156             :  */
     157             : static void
     158           0 : stat_run (void *cls,
     159             :           const struct TALER_TESTING_Command *cmd,
     160             :           struct TALER_TESTING_Interpreter *is)
     161             : {
     162           0 :   struct TALER_TESTING_Timer *timings = cls;
     163             : 
     164           0 :   for (unsigned int i = 0; NULL != is->commands[i].label; i++)
     165             :   {
     166           0 :     if (cmd == &is->commands[i])
     167           0 :       break; /* skip at our current command */
     168           0 :     do_stat (timings,
     169           0 :              &is->commands[i]);
     170             :   }
     171           0 :   TALER_TESTING_interpreter_next (is);
     172           0 : }
     173             : 
     174             : 
     175             : /**
     176             :  * Obtain performance data from the interpreter.
     177             :  *
     178             :  * @param timers what commands (by label) to obtain runtimes for
     179             :  * @return the command
     180             :  */
     181             : struct TALER_TESTING_Command
     182           0 : TALER_TESTING_cmd_stat (struct TALER_TESTING_Timer *timers)
     183             : {
     184           0 :   struct TALER_TESTING_Command cmd = {
     185             :     .label = "stat",
     186             :     .run = stat_run,
     187             :     .cleanup = stat_cleanup,
     188             :     .traits = stat_traits,
     189             :     .cls = (void *) timers
     190             :   };
     191             : 
     192           0 :   return cmd;
     193             : }
     194             : 
     195             : 
     196             : /* end of testing_api_cmd_sleep.c  */

Generated by: LCOV version 1.14