LCOV - code coverage report
Current view: top level - src/Communicate - LogEntry.cpp (source / functions) Coverage Total Hit
Test: report.info Lines: 93.5 % 46 43
Test Date: 2025-05-21 10:57:37 Functions: 100.0 % 4 4
Branches: 54.8 % 42 23

             Branch data     Line data    Source code
       1                 :             : #include "Communicate/LogEntry.h"
       2                 :             : 
       3                 :             : namespace ippl {
       4                 :             : 
       5                 :          12 :     void serializeString(std::vector<char>& buffer, const std::string& str) {
       6                 :          12 :         size_t length = str.size();
       7         [ +  - ]:          12 :         serializeBasicType(buffer, length);  // First, serialize the length of the string
       8         [ +  - ]:          12 :         buffer.insert(buffer.end(), str.begin(), str.end());  // Then, serialize the string itself
       9                 :          12 :     }
      10                 :             : 
      11                 :           6 :     std::string deserializeString(const std::vector<char>& buffer, size_t& offset) {
      12                 :             :         size_t length =
      13                 :           6 :             deserializeBasicType<size_t>(buffer, offset);  // Get the length of the string
      14                 :           0 :         std::string str(buffer.begin() + offset,
      15         [ +  - ]:           6 :                         buffer.begin() + offset + length);  // Extract the string
      16                 :           6 :         offset += length;
      17                 :           6 :         return str;
      18                 :             :     }
      19                 :             : 
      20                 :           2 :     std::vector<char> LogEntry::serialize() const {
      21                 :           2 :         std::vector<char> buffer;
      22                 :             : 
      23         [ +  - ]:           2 :         serializeString(buffer, methodName);
      24         [ +  - ]:           2 :         serializeBasicType(buffer, usedSize);
      25         [ +  - ]:           2 :         serializeBasicType(buffer, freeSize);
      26         [ +  - ]:           2 :         serializeString(buffer, memorySpace);
      27         [ +  - ]:           2 :         serializeBasicType(buffer, rank);
      28                 :             : 
      29                 :             :         // Serialize the timestamp (as duration since epoch)
      30                 :           2 :         auto duration = timestamp.time_since_epoch().count();
      31         [ +  - ]:           2 :         serializeBasicType(buffer, duration);
      32                 :             : 
      33                 :           2 :         size_t mapSize = parameters.size();
      34         [ +  - ]:           2 :         serializeBasicType(buffer, mapSize);
      35         [ +  + ]:           6 :         for (const auto& pair : parameters) {
      36         [ +  - ]:           4 :             serializeString(buffer, pair.first);
      37         [ +  - ]:           4 :             serializeString(buffer, pair.second);
      38                 :             :         }
      39                 :             : 
      40                 :           2 :         return buffer;
      41                 :           0 :     }
      42                 :             : 
      43                 :           1 :     LogEntry LogEntry::deserialize(const std::vector<char>& buffer, size_t offset) {
      44         [ +  - ]:           1 :         LogEntry entry;
      45                 :           1 :         size_t current_pos = offset;
      46                 :             : 
      47         [ +  - ]:           1 :         entry.methodName  = deserializeString(buffer, current_pos);
      48                 :           1 :         entry.usedSize    = deserializeBasicType<size_t>(buffer, current_pos);
      49                 :           1 :         entry.freeSize    = deserializeBasicType<size_t>(buffer, current_pos);
      50         [ +  - ]:           1 :         entry.memorySpace = deserializeString(buffer, current_pos);
      51                 :           1 :         entry.rank        = deserializeBasicType<int>(buffer, current_pos);
      52                 :             : 
      53                 :           1 :         auto duration   = deserializeBasicType<long long>(buffer, current_pos);
      54                 :           1 :         entry.timestamp = std::chrono::time_point<std::chrono::high_resolution_clock>(
      55                 :           1 :             std::chrono::high_resolution_clock::duration(duration));
      56                 :             : 
      57                 :           1 :         size_t mapSize = deserializeBasicType<size_t>(buffer, current_pos);
      58         [ +  + ]:           3 :         for (size_t i = 0; i < mapSize; ++i) {
      59         [ +  - ]:           2 :             std::string key       = deserializeString(buffer, current_pos);
      60         [ +  - ]:           2 :             std::string value     = deserializeString(buffer, current_pos);
      61   [ +  -  +  - ]:           2 :             entry.parameters[key] = value;
      62                 :           2 :         }
      63                 :             : 
      64                 :           1 :         return entry;
      65                 :           0 :     }
      66                 :             : 
      67                 :             : }  // namespace ippl
        

Generated by: LCOV version 2.0-1