LCOV - code coverage report
Current view: top level - spdk/test/event/reactor_perf - reactor_perf.c (source / functions) Hit Total Coverage
Test: Combined Lines: 37 59 62.7 %
Date: 2024-07-10 22:01:07 Functions: 4 6 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 37 43.2 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2017 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : 
       8                 :            : #include "spdk/env.h"
       9                 :            : #include "spdk/event.h"
      10                 :            : #include "spdk/string.h"
      11                 :            : #include "spdk/thread.h"
      12                 :            : 
      13                 :            : static int g_time_in_sec;
      14                 :            : static int g_queue_depth;
      15                 :            : static struct spdk_poller *g_test_end_poller;
      16                 :            : static uint64_t g_call_count = 0;
      17                 :            : 
      18                 :            : static int
      19                 :         20 : __test_end(void *arg)
      20                 :            : {
      21         [ -  + ]:         20 :         printf("test_end\n");
      22                 :         20 :         spdk_poller_unregister(&g_test_end_poller);
      23                 :         20 :         spdk_app_stop(0);
      24                 :         20 :         return -1;
      25                 :            : }
      26                 :            : 
      27                 :            : static void
      28                 :    9088864 : __submit_next(void *arg1, void *arg2)
      29                 :            : {
      30                 :            :         struct spdk_event *event;
      31                 :            : 
      32                 :    9088864 :         g_call_count++;
      33                 :            : 
      34                 :    9088864 :         event = spdk_event_allocate(spdk_env_get_current_core(),
      35                 :            :                                     __submit_next, NULL, NULL);
      36                 :    9088864 :         spdk_event_call(event);
      37                 :    9088864 : }
      38                 :            : 
      39                 :            : static void
      40                 :         20 : test_start(void *arg1)
      41                 :            : {
      42                 :            :         int i;
      43                 :            : 
      44         [ -  + ]:         20 :         printf("test_start\n");
      45                 :            : 
      46                 :            :         /* Register a poller that will stop the test after the time has elapsed. */
      47                 :         20 :         g_test_end_poller = SPDK_POLLER_REGISTER(__test_end, NULL,
      48                 :            :                             g_time_in_sec * 1000000ULL);
      49                 :            : 
      50         [ +  + ]:         40 :         for (i = 0; i < g_queue_depth; i++) {
      51                 :         20 :                 __submit_next(NULL, NULL);
      52                 :            :         }
      53                 :         20 : }
      54                 :            : 
      55                 :            : static void
      56                 :          0 : test_cleanup(void)
      57                 :            : {
      58         [ #  # ]:          0 :         printf("test_abort\n");
      59                 :            : 
      60                 :          0 :         spdk_poller_unregister(&g_test_end_poller);
      61                 :          0 :         spdk_app_stop(0);
      62                 :          0 : }
      63                 :            : 
      64                 :            : static void
      65                 :          0 : usage(const char *program_name)
      66                 :            : {
      67         [ #  # ]:          0 :         printf("%s options\n", program_name);
      68         [ #  # ]:          0 :         printf("\t[-q Queue depth (default: 1)]\n");
      69         [ #  # ]:          0 :         printf("\t[-t time in seconds]\n");
      70                 :          0 : }
      71                 :            : 
      72                 :            : int
      73                 :         20 : main(int argc, char **argv)
      74                 :            : {
      75                 :         10 :         struct spdk_app_opts opts;
      76                 :            :         int op;
      77                 :            :         int rc;
      78                 :            :         long int val;
      79                 :            : 
      80                 :         20 :         spdk_app_opts_init(&opts, sizeof(opts));
      81                 :         20 :         opts.name = "reactor_perf";
      82                 :         20 :         opts.rpc_addr = NULL;
      83                 :            : 
      84                 :         20 :         g_time_in_sec = 0;
      85                 :         20 :         g_queue_depth = 1;
      86                 :            : 
      87   [ +  +  +  +  :         40 :         while ((op = getopt(argc, argv, "q:t:")) != -1) {
                   +  + ]
      88         [ -  + ]:         20 :                 if (op == '?') {
      89                 :          0 :                         usage(argv[0]);
      90                 :          0 :                         exit(1);
      91                 :            :                 }
      92                 :         20 :                 val = spdk_strtol(optarg, 10);
      93         [ -  + ]:         20 :                 if (val < 0) {
      94   [ #  #  #  # ]:          0 :                         fprintf(stderr, "Converting a string to integer failed\n");
      95                 :          0 :                         exit(1);
      96                 :            :                 }
      97      [ -  +  - ]:         20 :                 switch (op) {
      98                 :          0 :                 case 'q':
      99                 :          0 :                         g_queue_depth = val;
     100                 :          0 :                         break;
     101                 :         20 :                 case 't':
     102                 :         20 :                         g_time_in_sec = val;
     103                 :         20 :                         break;
     104                 :          0 :                 default:
     105                 :          0 :                         usage(argv[0]);
     106                 :          0 :                         exit(1);
     107                 :            :                 }
     108                 :            :         }
     109                 :            : 
     110         [ -  + ]:         20 :         if (!g_time_in_sec) {
     111                 :          0 :                 usage(argv[0]);
     112                 :          0 :                 exit(1);
     113                 :            :         }
     114                 :            : 
     115                 :         20 :         opts.shutdown_cb = test_cleanup;
     116                 :            : 
     117                 :         20 :         rc = spdk_app_start(&opts, test_start, NULL);
     118                 :            : 
     119                 :         20 :         spdk_app_fini();
     120                 :            : 
     121   [ -  +  -  + ]:         20 :         printf("Performance: %8ju events per second\n", g_call_count / g_time_in_sec);
     122                 :            : 
     123                 :         20 :         return rc;
     124                 :            : }

Generated by: LCOV version 1.14