LCOV - code coverage report
Current view: top level - package/statistics/statistics_log - statlog_domain.cpp (source / functions) Hit Total Coverage
Test: wfc_core-coverage.info Lines: 1 84 1.2 %
Date: 2019-09-05 Functions: 2 7 28.6 %

          Line data    Source code
       1             : 
       2             : #include <wfc/iinterface.hpp>
       3             : #include <wfc/statistics/meters.hpp>
       4             : #include "statlog_domain.hpp"
       5             : 
       6             : namespace wfc{ namespace core{
       7             :  
       8             : 
       9             : namespace 
      10             : {
      11           0 :   void wlog_metric( std::stringstream& os, long int val, int metric)
      12             :   {
      13             :     // statistics_duration::period::den - microseconds
      14           0 :     val*= std::chrono::nanoseconds::period::den/statistics_duration::period::den;
      15           0 :     val/=metric;
      16           0 :     os << val;
      17           0 :     switch (metric)
      18             :     {
      19           0 :       case 1 : os << "ns"; break;
      20           0 :       case 1000 : os << "μs"; break;
      21           0 :       case 1000000 : os << "ms"; break;
      22           0 :       case 1000000000 : os << "s"; break;
      23           0 :       default: os << "?s";
      24             :     }
      25           0 :   }
      26             :   
      27           0 :   void wlog( std::stringstream& os, const std::string& name, long int val, int metric)
      28             :   {
      29           0 :     if ( metric < 0 )
      30           0 :       return;
      31             : 
      32           0 :     os << name << ":";
      33             : 
      34           0 :     if ( metric==0 ) 
      35             :     {
      36           0 :       if (val!=0) val = 1000000000/val;
      37           0 :       else val = -1;
      38           0 :       os << val << "ps";
      39             :     }
      40             :     else
      41           0 :       wlog_metric( os, val, metric);
      42           0 :     os << " ";
      43             :   }
      44             : }
      45             : 
      46           0 : void statlog_domain::initialize()
      47             : {
      48           0 :   _target = this->get_target<istatistics>( this->options().target );
      49           0 : }
      50             : 
      51           0 : void statlog_domain::push( request::push::ptr req, response::push::handler cb )
      52             : {
      53           0 :   if ( this->suspended() )
      54             :   {
      55           0 :     if ( auto t = _target.lock() )
      56             :     {
      57           0 :       t->push( std::move(req), cb);
      58           0 :     }
      59           0 :     return;
      60             :   }
      61             :   
      62           0 :   if ( this->bad_request(req, cb) )
      63           0 :     return;
      64             :   
      65           0 :   auto opt = this->options();
      66           0 :   int metric = opt.log_metric;
      67           0 :   auto log = opt.common_log;
      68           0 :   if ( !log.empty() )
      69             :   {
      70           0 :     std::stringstream ss;
      71           0 :     ss << req->name << " ";
      72           0 :     ss << "count:"    << req->count << " ";
      73           0 :     wlog( ss, "min", req->min, metric );
      74           0 :     wlog( ss, "perc80", req->perc80, metric );
      75           0 :     wlog( ss, "perc99", req->perc99, metric );
      76           0 :     wlog( ss, "perc100", req->perc100, metric );
      77           0 :     wlog( ss, "max", req->max, metric );
      78           0 :     ss << "lossy:"    << req->lossy << " ";
      79           0 :     WFC_LOG_MESSAGE(log, ss.str() )
      80             :   }
      81             :   
      82           0 :   int id = 0;
      83           0 :   log = opt.legend_log;
      84           0 :   if ( !log.empty() )
      85             :   {
      86           0 :     std::lock_guard<mutex_type> lk(_mutex);
      87           0 :     auto itr = _legend.find(req->name);
      88           0 :     if ( itr == _legend.end() )
      89             :     {
      90           0 :       id = ++_id_counter;
      91           0 :       _legend[req->name] = id;
      92           0 :       WFC_LOG_MESSAGE(log, id << ":" << req->name );
      93             :     }
      94             :     else
      95           0 :       id = itr->second;
      96             :   }
      97             : 
      98           0 :   log = opt.table_log;
      99           0 :   if ( !log.empty() )
     100             :   {
     101           0 :     std::stringstream ss;
     102           0 :     ss << "|" << id 
     103           0 :        << "|" << req->count
     104           0 :        << "|" << req->lossy
     105           0 :        << "|" << req->min
     106           0 :        << "|" << req->perc50
     107           0 :        << "|" << req->perc80
     108           0 :        << "|" << req->perc95
     109           0 :        << "|" << req->perc99
     110           0 :        << "|" << req->perc100
     111           0 :        << "|" << req->max
     112           0 :        << "|" << req->avg
     113           0 :        << "|" << req->ts
     114           0 :        << "|";
     115           0 :     WFC_LOG_MESSAGE(log, ss.str() )
     116             :   }
     117             : 
     118           0 :   if ( auto t = _target.lock() )
     119             :   {
     120           0 :     t->push( std::move(req), cb);
     121             :   }
     122           0 :   else if ( auto res = this->create_response(cb) )
     123             :   {
     124           0 :     res->status = true;
     125           0 :     this->send_response( std::move(res), cb);
     126           0 :   }
     127             : }
     128             : 
     129           0 : void statlog_domain::del( request::del::ptr, response::del::handler cb ) 
     130             : {
     131           0 :   if ( cb!=nullptr )
     132           0 :     cb(nullptr);
     133           0 : }
     134             : 
     135             : 
     136           3 : }}

Generated by: LCOV version 1.10