LCOV - code coverage report
Current view: top level - src/Module/Stateful/Probe/Timestamp - Probe_timestamp.cpp (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 19 26 73.1 %
Date: 2025-01-11 12:25:42 Functions: 3 4 75.0 %

          Line data    Source code
       1             : #include <chrono>
       2             : #include <ctime>
       3             : #include <ios>
       4             : #include <sstream>
       5             : 
       6             : #include "Module/Stateful/Probe/Timestamp/Probe_timestamp.hpp"
       7             : #include "Tools/Exception/exception.hpp"
       8             : 
       9             : using namespace spu;
      10             : using namespace spu::module;
      11             : 
      12          56 : Probe_timestamp::Probe_timestamp(const uint64_t mod, const std::string& col_name, tools::Reporter_probe* reporter)
      13             :   : Probe<uint8_t>(0, col_name)
      14          56 :   , mod(mod)
      15             : {
      16          56 :     const std::string name = "Probe_timestamp<" + col_name + ">";
      17          56 :     this->set_name(name);
      18          56 :     this->set_single_wave(true);
      19             : 
      20          56 :     if (reporter != nullptr) this->register_reporter(reporter);
      21          56 : }
      22             : 
      23           0 : Probe_timestamp::Probe_timestamp(const std::string& col_name, tools::Reporter_probe* reporter)
      24           0 :   : Probe_timestamp(0, col_name, reporter)
      25             : {
      26           0 : }
      27             : 
      28             : void
      29          56 : Probe_timestamp::register_reporter(tools::Reporter_probe* reporter)
      30             : {
      31          56 :     if (this->reporter != nullptr)
      32             :     {
      33           0 :         std::stringstream message;
      34             :         message << "It is not possible to register this probe to a new 'tools::Reporter_probe' because it is already "
      35           0 :                 << "registered to an other 'tools::Reporter_probe'.";
      36           0 :         throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
      37           0 :     }
      38          56 :     this->reporter = reporter;
      39          56 :     this->proxy_register_probe(1, typeid(uint64_t), "(us)", 100, std::ios_base::scientific, 2);
      40          56 : }
      41             : 
      42             : void
      43         412 : Probe_timestamp::_probe(const uint8_t* in, const size_t frame_id)
      44             : {
      45         412 :     std::chrono::microseconds us = std::chrono::duration_cast<std::chrono::microseconds>(
      46             :       // std::chrono::system_clock::now().time_since_epoch()
      47         412 :       std::chrono::steady_clock::now().time_since_epoch());
      48             : 
      49         412 :     uint64_t unix_timestamp_count = mod ? (uint64_t)us.count() % mod : (uint64_t)us.count();
      50             : 
      51         944 :     for (size_t f = 0; f < this->get_n_frames(); f++)
      52         532 :         this->proxy_probe((void*)&unix_timestamp_count, frame_id);
      53         412 : }

Generated by: LCOV version 1.14