LCOV - code coverage report
Current view: top level - spdk/lib/trace_parser - trace.cpp (source / functions) Hit Total Coverage
Test: Combined Lines: 158 238 66.4 %
Date: 2024-11-15 12:48:11 Functions: 21 22 95.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 90 755 11.9 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2021 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk/likely.h"
       8                 :            : #include "spdk/log.h"
       9                 :            : #include "spdk/trace_parser.h"
      10                 :            : #include "spdk/util.h"
      11                 :            : #include "spdk/env.h"
      12                 :            : 
      13                 :            : #include <exception>
      14                 :            : #include <map>
      15                 :            : #include <new>
      16                 :            : 
      17                 :            : struct entry_key {
      18         [ #  # ]:    1064891 :         entry_key(uint16_t _lcore, uint64_t _tsc) : lcore(_lcore), tsc(_tsc) {}
      19                 :            :         uint16_t lcore;
      20                 :            :         uint64_t tsc;
      21                 :            : };
      22                 :            : 
      23                 :            : class compare_entry_key
      24                 :            : {
      25                 :            : public:
      26         [ #  # ]:   26839684 :         bool operator()(const entry_key &first, const entry_key &second) const
      27                 :            :         {
      28   [ -  +  #  #  :   26839684 :                 if (first.tsc == second.tsc) {
                   #  # ]
      29   [ #  #  #  # ]:          0 :                         return first.lcore < second.lcore;
      30                 :            :                 } else {
      31   [ #  #  #  # ]:   26839684 :                         return first.tsc < second.tsc;
      32                 :            :                 }
      33                 :          0 :         }
      34                 :            : };
      35                 :            : 
      36                 :            : typedef std::map<entry_key, spdk_trace_entry *, compare_entry_key> entry_map;
      37                 :            : 
      38                 :            : struct argument_context {
      39                 :            :         spdk_trace_entry        *entry;
      40                 :            :         spdk_trace_entry_buffer *buffer;
      41                 :            :         uint16_t                lcore;
      42                 :            :         size_t                  offset;
      43                 :            : 
      44         [ #  # ]:    1064891 :         argument_context(spdk_trace_entry *entry, uint16_t lcore) :
      45                 :    1064891 :                 entry(entry), lcore(lcore)
      46                 :            :         {
      47                 :    1064891 :                 buffer = reinterpret_cast<spdk_trace_entry_buffer *>(entry);
      48                 :            : 
      49                 :            :                 /* The first argument resides within the spdk_trace_entry structure, so the initial
      50                 :            :                  * offset needs to be adjusted to the start of the spdk_trace_entry.args array
      51                 :            :                  */
      52                 :    1064891 :                 offset = offsetof(spdk_trace_entry, args) -
      53                 :            :                          offsetof(spdk_trace_entry_buffer, data);
      54                 :    1064891 :         }
      55                 :            : };
      56                 :            : 
      57                 :          0 : struct object_stats {
      58                 :            :         std::map<uint64_t, uint64_t>      index;
      59                 :            :         std::map<uint64_t, uint64_t>      start;
      60                 :            :         uint64_t                        counter;
      61                 :            : 
      62         [ #  # ]:        512 :         object_stats() : counter(0) {}
      63                 :            : };
      64                 :            : 
      65                 :            : struct spdk_trace_parser {
      66                 :            :         spdk_trace_parser(const spdk_trace_parser_opts *opts);
      67                 :            :         ~spdk_trace_parser();
      68                 :            :         spdk_trace_parser(const spdk_trace_parser &) = delete;
      69                 :            :         spdk_trace_parser &operator=(const spdk_trace_parser &) = delete;
      70         [ #  # ]:          2 :         const spdk_trace_file *file() const { return _trace_file; }
      71         [ #  # ]:          2 :         uint64_t tsc_offset() const { return _tsc_offset; }
      72                 :            :         bool next_entry(spdk_trace_parser_entry *entry);
      73                 :            :         uint64_t entry_count(uint16_t lcore) const;
      74                 :            : private:
      75                 :            :         spdk_trace_entry_buffer *get_next_buffer(spdk_trace_entry_buffer *buf, uint16_t lcore);
      76                 :            :         bool build_arg(argument_context *argctx, const spdk_trace_argument *arg, int argid,
      77                 :            :                        spdk_trace_parser_entry *pe);
      78                 :            :         void populate_events(spdk_trace_history *history, int num_entries, bool overflowed);
      79                 :            :         bool init(const spdk_trace_parser_opts *opts);
      80                 :            :         void cleanup();
      81                 :            : 
      82                 :            :         spdk_trace_file         *_trace_file;
      83                 :            :         size_t                  _map_size;
      84                 :            :         int                     _fd;
      85                 :            :         uint64_t                _tsc_offset;
      86                 :            :         entry_map               _entries;
      87                 :            :         entry_map::iterator     _iter;
      88                 :            :         object_stats            _stats[SPDK_TRACE_MAX_OBJECT];
      89                 :            : };
      90                 :            : 
      91                 :            : uint64_t
      92         [ #  # ]:       2048 : spdk_trace_parser::entry_count(uint16_t lcore) const
      93                 :            : {
      94                 :            :         spdk_trace_history *history;
      95                 :            : 
      96         [ -  + ]:       2048 :         if (lcore >= SPDK_TRACE_MAX_LCORE) {
      97                 :          0 :                 return 0;
      98                 :            :         }
      99                 :            : 
     100                 :       2048 :         history = spdk_get_per_lcore_history(_trace_file, lcore);
     101                 :            : 
     102   [ +  +  #  #  :       2048 :         return history == NULL ? 0 : history->num_entries;
                   #  # ]
     103                 :          0 : }
     104                 :            : 
     105                 :            : spdk_trace_entry_buffer *
     106         [ #  # ]:     149106 : spdk_trace_parser::get_next_buffer(spdk_trace_entry_buffer *buf, uint16_t lcore)
     107                 :            : {
     108                 :            :         spdk_trace_history *history;
     109                 :            : 
     110                 :     149106 :         history = spdk_get_per_lcore_history(_trace_file, lcore);
     111   [ -  +  #  # ]:     149106 :         assert(history);
     112                 :            : 
     113   [ -  +  #  #  :     149106 :         if (spdk_unlikely(static_cast<void *>(buf) ==
          #  #  #  #  #  
                      # ]
     114                 :            :                           static_cast<void *>(&history->entries[history->num_entries - 1]))) {
     115         [ #  # ]:          0 :                 return reinterpret_cast<spdk_trace_entry_buffer *>(&history->entries[0]);
     116                 :            :         } else {
     117         [ #  # ]:     149106 :                 return buf + 1;
     118                 :            :         }
     119                 :          0 : }
     120                 :            : 
     121                 :            : bool
     122         [ #  # ]:     831541 : spdk_trace_parser::build_arg(argument_context *argctx, const spdk_trace_argument *arg, int argid,
     123                 :            :                              spdk_trace_parser_entry *pe)
     124                 :            : {
     125   [ #  #  #  # ]:     831541 :         spdk_trace_entry *entry = argctx->entry;
     126   [ #  #  #  # ]:     831541 :         spdk_trace_entry_buffer *buffer = argctx->buffer;
     127                 :            :         size_t curlen, argoff;
     128                 :            : 
     129                 :     831541 :         argoff = 0;
     130   [ #  #  #  #  :     831541 :         pe->args[argid].is_related = false;
             #  #  #  # ]
     131                 :            :         /* Make sure that if we only copy a 4-byte integer, that the upper bytes have already been
     132                 :            :          * zeroed.
     133                 :            :          */
     134   [ #  #  #  #  :     831541 :         pe->args[argid].u.integer = 0;
          #  #  #  #  #  
                      # ]
     135   [ +  +  #  #  :    1663082 :         while (argoff < arg->size) {
                   #  # ]
     136   [ +  +  #  #  :     831541 :                 if (argctx->offset == sizeof(buffer->data)) {
                   #  # ]
     137   [ #  #  #  # ]:     149106 :                         buffer = get_next_buffer(buffer, argctx->lcore);
     138   [ +  -  -  +  :     149106 :                         if (spdk_unlikely(buffer->tpoint_id != SPDK_TRACE_MAX_TPOINT_ID ||
          -  +  #  #  #  
          #  #  #  #  #  
                   #  # ]
     139                 :            :                                           buffer->tsc != entry->tsc)) {
     140                 :          0 :                                 return false;
     141                 :            :                         }
     142                 :            : 
     143   [ #  #  #  # ]:     149106 :                         argctx->offset = 0;
     144   [ #  #  #  # ]:     149106 :                         argctx->buffer = buffer;
     145                 :          0 :                 }
     146                 :            : 
     147   [ #  #  #  #  :     831541 :                 curlen = spdk_min(sizeof(buffer->data) - argctx->offset, arg->size - argoff);
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     148         [ +  - ]:     831541 :                 if (argoff < sizeof(pe->args[0].u.string)) {
     149   [ -  +  -  +  :     831541 :                         memcpy(&pe->args[argid].u.string[argoff], &buffer->data[argctx->offset],
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     150         [ #  # ]:     831541 :                                spdk_min(curlen, sizeof(pe->args[0].u.string) - argoff));
     151                 :          0 :                 }
     152                 :            : 
     153   [ #  #  #  # ]:     831541 :                 argctx->offset += curlen;
     154                 :     831541 :                 argoff += curlen;
     155                 :            :         }
     156                 :            : 
     157                 :     831541 :         return true;
     158                 :          0 : }
     159                 :            : 
     160                 :            : bool
     161         [ #  # ]:    1064893 : spdk_trace_parser::next_entry(spdk_trace_parser_entry *pe)
     162                 :            : {
     163                 :            :         spdk_trace_tpoint *tpoint;
     164                 :            :         spdk_trace_entry *entry;
     165                 :            :         object_stats *stats;
     166                 :    1064893 :         std::map<uint64_t, uint64_t>::iterator related_kv;
     167                 :            : 
     168   [ +  +  #  #  :    1064893 :         if (_iter == _entries.end()) {
                   #  # ]
     169                 :          2 :                 return false;
     170                 :            :         }
     171                 :            : 
     172   [ #  #  #  #  :    1064891 :         pe->entry = entry = _iter->second;
          #  #  #  #  #  
                      # ]
     173   [ #  #  #  #  :    1064891 :         pe->lcore = _iter->first.lcore;
          #  #  #  #  #  
                #  #  # ]
     174                 :            :         /* Set related index to the max value to indicate "empty" state */
     175   [ #  #  #  # ]:    1064891 :         pe->related_index = UINT64_MAX;
     176   [ #  #  #  # ]:    1064891 :         pe->related_type = OBJECT_NONE;
     177   [ #  #  #  #  :    1064891 :         tpoint = &_trace_file->tpoint[entry->tpoint_id];
          #  #  #  #  #  
                      # ]
     178   [ #  #  #  #  :    1064891 :         stats = &_stats[tpoint->object_type];
                   #  # ]
     179                 :            : 
     180   [ +  +  #  #  :    1064891 :         if (tpoint->new_object) {
                   #  # ]
     181   [ +  -  #  #  :     303543 :                 stats->index[entry->object_id] = stats->counter++;
          #  #  #  #  #  
                #  #  # ]
     182   [ +  -  #  #  :     303543 :                 stats->start[entry->object_id] = entry->tsc;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     183                 :          0 :         }
     184                 :            : 
     185   [ +  +  #  #  :    1064891 :         if (tpoint->object_type != OBJECT_NONE) {
                   #  # ]
     186   [ +  -  +  -  :     877376 :                 if (spdk_likely(stats->start.find(entry->object_id) != stats->start.end())) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     187   [ +  -  #  #  :     877376 :                         pe->object_index = stats->index[entry->object_id];
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     188   [ +  -  #  #  :     877376 :                         pe->object_start = stats->start[entry->object_id];
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     189                 :          0 :                 } else {
     190   [ #  #  #  # ]:          0 :                         pe->object_index = UINT64_MAX;
     191   [ #  #  #  # ]:          0 :                         pe->object_start = UINT64_MAX;
     192                 :            :                 }
     193                 :          0 :         }
     194                 :            : 
     195   [ #  #  #  # ]:    1064891 :         argument_context argctx(entry, pe->lcore);
     196   [ +  +  #  #  :    1896432 :         for (uint8_t i = 0; i < tpoint->num_args; ++i) {
                   #  # ]
     197   [ +  -  -  +  :     831541 :                 if (!build_arg(&argctx, &tpoint->args[i], i, pe)) {
             #  #  #  # ]
     198         [ #  # ]:          0 :                         SPDK_ERRLOG("Failed to parse tracepoint argument\n");
     199                 :          0 :                         return false;
     200                 :            :                 }
     201                 :          0 :         }
     202                 :            : 
     203         [ +  - ]:    1375123 :         for (uint8_t i = 0; i < SPDK_TRACE_MAX_RELATIONS; ++i) {
     204                 :            :                 /* The relations are stored inside a tpoint, which means there might be
     205                 :            :                  * multiple objects bound to a single tpoint. */
     206   [ +  +  #  #  :    1375123 :                 if (tpoint->related_objects[i].object_type == OBJECT_NONE) {
          #  #  #  #  #  
                      # ]
     207                 :     841741 :                         break;
     208                 :            :                 }
     209   [ #  #  #  #  :     533382 :                 stats = &_stats[tpoint->related_objects[i].object_type];
          #  #  #  #  #  
                      # ]
     210   [ +  -  #  # ]:    1066764 :                 related_kv = stats->index.find(reinterpret_cast<uint64_t>
     211   [ #  #  #  #  :     533382 :                                                (pe->args[tpoint->related_objects[i].arg_index].u.pointer));
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     212                 :            :                 /* To avoid parsing the whole array, object index and type are stored
     213                 :            :                  * directly inside spdk_trace_parser_entry. */
     214   [ +  +  #  #  :     533382 :                 if (related_kv != stats->index.end()) {
                   #  # ]
     215   [ #  #  #  #  :     223150 :                         pe->related_index = related_kv->second;
             #  #  #  # ]
     216   [ #  #  #  #  :     223150 :                         pe->related_type = tpoint->related_objects[i].object_type;
          #  #  #  #  #  
                #  #  # ]
     217   [ #  #  #  #  :     223150 :                         pe->args[tpoint->related_objects[i].arg_index].is_related = true;
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     218                 :     223150 :                         break;
     219                 :            :                 }
     220                 :          0 :         }
     221                 :            : 
     222         [ #  # ]:    1064891 :         _iter++;
     223                 :    1064891 :         return true;
     224                 :          0 : }
     225                 :            : 
     226                 :            : void
     227         [ #  # ]:          8 : spdk_trace_parser::populate_events(spdk_trace_history *history, int num_entries, bool overflowed)
     228                 :            : {
     229                 :            :         int i, num_entries_filled;
     230                 :            :         spdk_trace_entry *e;
     231                 :            :         int first, last, lcore;
     232                 :            : 
     233   [ #  #  #  # ]:          8 :         lcore = history->lcore;
     234         [ #  # ]:          8 :         e = history->entries;
     235                 :            : 
     236                 :          8 :         num_entries_filled = num_entries;
     237   [ -  +  #  #  :          8 :         while (e[num_entries_filled - 1].tsc == 0) {
          #  #  #  #  #  
                      # ]
     238         [ #  # ]:          0 :                 num_entries_filled--;
     239                 :            :         }
     240                 :            : 
     241         [ +  - ]:          8 :         if (num_entries == num_entries_filled) {
     242                 :          8 :                 first = last = 0;
     243   [ +  +  #  # ]:    1213997 :                 for (i = 1; i < num_entries; i++) {
     244   [ -  +  #  #  :    1213989 :                         if (e[i].tsc < e[first].tsc) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     245                 :          0 :                                 first = i;
     246                 :          0 :                         }
     247   [ +  +  #  #  :    1213989 :                         if (e[i].tsc > e[last].tsc) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     248                 :    1064883 :                                 last = i;
     249                 :          0 :                         }
     250                 :          0 :                 }
     251                 :          0 :         } else {
     252                 :          0 :                 first = 0;
     253         [ #  # ]:          0 :                 last = num_entries_filled - 1;
     254                 :            :         }
     255                 :            : 
     256                 :            :         /*
     257                 :            :          * We keep track of the highest first TSC out of all reactors iff. any
     258                 :            :          * have overflowed their circular buffer.
     259                 :            :          *  We will ignore any events that occurred before this TSC on any
     260                 :            :          *  other reactors.  This will ensure we only print data for the
     261                 :            :          *  subset of time where we have data across all reactors.
     262                 :            :          */
     263   [ +  -  +  -  :          8 :         if (e[first].tsc > _tsc_offset && overflowed) {
          #  #  #  #  #  
                #  #  # ]
     264   [ #  #  #  #  :          8 :                 _tsc_offset = e[first].tsc;
                   #  # ]
     265                 :          0 :         }
     266                 :            : 
     267                 :          8 :         i = first;
     268                 :          0 :         while (1) {
     269   [ +  +  #  #  :    1213997 :                 if (e[i].tpoint_id != SPDK_TRACE_MAX_TPOINT_ID) {
             #  #  #  # ]
     270   [ +  -  #  #  :    1064891 :                         _entries[entry_key(lcore, e[i].tsc)] = &e[i];
          #  #  #  #  #  
                #  #  # ]
     271                 :          0 :                 }
     272         [ +  + ]:    1213997 :                 if (i == last) {
     273                 :          8 :                         break;
     274                 :            :                 }
     275         [ #  # ]:    1213989 :                 i++;
     276         [ -  + ]:    1213989 :                 if (i == num_entries_filled) {
     277                 :          0 :                         i = 0;
     278                 :          0 :                 }
     279                 :            :         }
     280                 :          8 : }
     281                 :            : 
     282                 :            : bool
     283         [ #  # ]:          2 : spdk_trace_parser::init(const spdk_trace_parser_opts *opts)
     284                 :            : {
     285                 :            :         spdk_trace_history *history;
     286                 :          0 :         struct stat st;
     287                 :            :         int rc, i, entry_num;
     288                 :            :         bool overflowed;
     289                 :            : 
     290   [ +  -  -  #  :          2 :         switch (opts->mode) {
                #  #  # ]
     291                 :          2 :         case SPDK_TRACE_PARSER_MODE_FILE:
     292   [ -  +  +  -  :          2 :                 _fd = open(opts->filename, O_RDONLY);
                   #  # ]
     293                 :          2 :                 break;
     294                 :          0 :         case SPDK_TRACE_PARSER_MODE_SHM:
     295   [ #  #  #  # ]:          0 :                 _fd = shm_open(opts->filename, O_RDONLY, 0600);
     296                 :          0 :                 break;
     297                 :          0 :         default:
     298   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Invalid mode: %d\n", opts->mode);
     299                 :          0 :                 return false;
     300                 :            :         }
     301                 :            : 
     302         [ -  + ]:          2 :         if (_fd < 0) {
     303   [ #  #  #  #  :          0 :                 SPDK_ERRLOG("Could not open trace file: %s (%d)\n", opts->filename, errno);
                   #  # ]
     304                 :          0 :                 return false;
     305                 :            :         }
     306                 :            : 
     307         [ #  # ]:          2 :         rc = fstat(_fd, &st);
     308         [ -  + ]:          2 :         if (rc < 0) {
     309   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Could not get size of trace file: %s\n", opts->filename);
     310                 :          0 :                 return false;
     311                 :            :         }
     312                 :            : 
     313   [ -  +  #  # ]:          2 :         if ((size_t)st.st_size < sizeof(*_trace_file)) {
     314   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Invalid trace file: %s\n", opts->filename);
     315                 :          0 :                 return false;
     316                 :            :         }
     317                 :            : 
     318                 :            :         /* Map the header of trace file */
     319                 :          2 :         _map_size = sizeof(*_trace_file);
     320                 :          2 :         _trace_file = static_cast<spdk_trace_file *>(mmap(NULL, _map_size, PROT_READ,
     321                 :          0 :                         MAP_SHARED, _fd, 0));
     322         [ -  + ]:          2 :         if (_trace_file == MAP_FAILED) {
     323   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Could not mmap trace file: %s\n", opts->filename);
     324                 :          0 :                 _trace_file = NULL;
     325                 :          0 :                 return false;
     326                 :            :         }
     327                 :            : 
     328                 :            :         /* Remap the entire trace file */
     329                 :          2 :         _map_size = spdk_get_trace_file_size(_trace_file);
     330                 :          2 :         munmap(_trace_file, sizeof(*_trace_file));
     331   [ -  +  #  # ]:          2 :         if ((size_t)st.st_size < _map_size) {
     332   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Trace file %s is not valid\n", opts->filename);
     333                 :          0 :                 _trace_file = NULL;
     334                 :          0 :                 return false;
     335                 :            :         }
     336                 :          2 :         _trace_file = static_cast<spdk_trace_file *>(mmap(NULL, _map_size, PROT_READ,
     337                 :          0 :                         MAP_SHARED, _fd, 0));
     338         [ -  + ]:          2 :         if (_trace_file == MAP_FAILED) {
     339   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Could not mmap trace file: %s\n", opts->filename);
     340                 :          0 :                 _trace_file = NULL;
     341                 :          0 :                 return false;
     342                 :            :         }
     343                 :            : 
     344   [ +  -  #  #  :          2 :         if (opts->lcore == SPDK_TRACE_MAX_LCORE) {
                   #  # ]
     345                 :            :                 /* Check if any reactors have overwritten their circular buffer. */
     346   [ +  -  #  # ]:          2 :                 for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
     347                 :          2 :                         history = spdk_get_per_lcore_history(_trace_file, i);
     348   [ +  -  +  -  :          2 :                         if (history == NULL || history->num_entries == 0 || history->entries[0].tsc == 0) {
          -  +  #  #  #  
          #  #  #  #  #  
                   #  # ]
     349                 :          0 :                                 continue;
     350                 :            :                         }
     351   [ #  #  #  # ]:          2 :                         entry_num = history->num_entries - 1;
     352                 :          2 :                         overflowed = true;
     353         [ +  + ]:     299746 :                         while (entry_num >= 0) {
     354   [ -  +  #  #  :     299744 :                                 if (history->entries[entry_num].tsc == 0) {
          #  #  #  #  #  
                      # ]
     355                 :          0 :                                         overflowed = false;
     356                 :          0 :                                         break;
     357                 :            :                                 }
     358         [ #  # ]:     299744 :                                 entry_num--;
     359                 :            :                         }
     360   [ +  -  #  # ]:          2 :                         if (overflowed) {
     361                 :          2 :                                 break;
     362                 :            :                         }
     363                 :            : 
     364                 :          0 :                 }
     365   [ +  +  #  # ]:       2050 :                 for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
     366                 :       2048 :                         history = spdk_get_per_lcore_history(_trace_file, i);
     367   [ +  +  +  -  :       2048 :                         if (history == NULL || history->num_entries == 0 || history->entries[0].tsc == 0) {
          -  +  #  #  #  
          #  #  #  #  #  
                   #  # ]
     368                 :       2040 :                                 continue;
     369                 :            :                         }
     370   [ +  -  #  #  :          8 :                         populate_events(history, history->num_entries, overflowed);
                   #  # ]
     371                 :          0 :                 }
     372                 :          0 :         } else {
     373   [ #  #  #  # ]:          0 :                 history = spdk_get_per_lcore_history(_trace_file, opts->lcore);
     374         [ #  # ]:          0 :                 if (history == NULL) {
     375   [ #  #  #  #  :          0 :                         SPDK_ERRLOG("Trace file %s has no trace history for lcore %d\n",
             #  #  #  # ]
     376                 :            :                                     opts->filename, opts->lcore);
     377                 :          0 :                         return false;
     378                 :            :                 }
     379   [ #  #  #  #  :          0 :                 if (history->num_entries > 0 && history->entries[0].tsc != 0) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     380   [ #  #  #  # ]:          0 :                         populate_events(history, history->num_entries, false);
     381                 :          0 :                 }
     382                 :            :         }
     383                 :            : 
     384         [ #  # ]:          2 :         _iter = _entries.begin();
     385                 :          2 :         return true;
     386                 :          0 : }
     387                 :            : 
     388                 :            : void
     389         [ #  # ]:          2 : spdk_trace_parser::cleanup()
     390                 :            : {
     391         [ +  - ]:          2 :         if (_trace_file != NULL) {
     392                 :          2 :                 munmap(_trace_file, _map_size);
     393                 :          0 :         }
     394                 :            : 
     395         [ +  - ]:          2 :         if (_fd > 0) {
     396                 :          2 :                 close(_fd);
     397                 :          0 :         }
     398                 :          2 : }
     399                 :            : 
     400   [ #  #  #  #  :          2 : spdk_trace_parser::spdk_trace_parser(const spdk_trace_parser_opts *opts) :
                   #  # ]
     401                 :          2 :         _trace_file(NULL),
     402                 :          2 :         _map_size(0),
     403                 :          2 :         _fd(-1),
     404   [ +  +  -  - ]:        514 :         _tsc_offset(0)
     405                 :            : {
     406   [ +  -  -  + ]:          2 :         if (!init(opts)) {
     407         [ #  # ]:          0 :                 cleanup();
     408   [ #  #  #  # ]:          0 :                 throw std::exception();
     409                 :            :         }
     410   [ -  -  #  # ]:          2 : }
     411                 :            : 
     412         [ +  - ]:       1028 : spdk_trace_parser::~spdk_trace_parser()
     413                 :            : {
     414         [ #  # ]:          2 :         cleanup();
     415   [ +  +  #  # ]:        516 : }
     416                 :            : 
     417                 :            : struct spdk_trace_parser *
     418                 :          2 : spdk_trace_parser_init(const struct spdk_trace_parser_opts *opts)
     419                 :            : {
     420                 :            :         try {
     421   [ +  -  +  -  :          2 :                 return new spdk_trace_parser(opts);
                   -  - ]
     422                 :          0 :         } catch (...) {
     423                 :          0 :                 return NULL;
     424         [ #  # ]:          0 :         }
     425                 :          0 : }
     426                 :            : 
     427                 :            : void
     428                 :          2 : spdk_trace_parser_cleanup(struct spdk_trace_parser *parser)
     429                 :            : {
     430   [ +  -  #  # ]:          2 :         delete parser;
     431                 :          2 : }
     432                 :            : 
     433                 :            : const struct spdk_trace_file *
     434                 :          2 : spdk_trace_parser_get_file(const struct spdk_trace_parser *parser)
     435                 :            : {
     436         [ #  # ]:          2 :         return parser->file();
     437                 :            : }
     438                 :            : 
     439                 :            : uint64_t
     440                 :          2 : spdk_trace_parser_get_tsc_offset(const struct spdk_trace_parser *parser)
     441                 :            : {
     442         [ #  # ]:          2 :         return parser->tsc_offset();
     443                 :            : }
     444                 :            : 
     445                 :            : bool
     446                 :    1064893 : spdk_trace_parser_next_entry(struct spdk_trace_parser *parser,
     447                 :            :                              struct spdk_trace_parser_entry *entry)
     448                 :            : {
     449         [ #  # ]:    1064893 :         return parser->next_entry(entry);
     450                 :            : }
     451                 :            : 
     452                 :            : uint64_t
     453                 :       2048 : spdk_trace_parser_get_entry_count(const struct spdk_trace_parser *parser, uint16_t lcore)
     454                 :            : {
     455         [ #  # ]:       2048 :         return parser->entry_count(lcore);
     456                 :            : }

Generated by: LCOV version 1.15