Agora  1.2.0
Agora project
time_frame_counters.h
Go to the documentation of this file.
1 
5 #ifndef TIME_FRAME_COUNTERS_H_
6 #define TIME_FRAME_COUNTERS_H_
7 
8 #include <array>
9 #include <cstddef>
10 
11 #include "gettime.h"
12 #include "message.h"
13 #include "symbols.h"
14 
16  public:
17  TimeFrameCounters() = default;
18 
19  inline void Init(size_t max_symbol_count, size_t max_task_count = 0) {
20  counter_.Init(max_symbol_count, max_task_count);
21  }
22  inline void Reset(size_t frame_id) { counter_.Reset(frame_id); }
23  inline bool CompleteSymbol(size_t frame_id) {
24  if (counter_.GetSymbolCount(frame_id) == 0) {
25  const size_t frame_idx = frame_id % kFrameWnd;
26  symbol_times_.at(frame_idx).first = GetTime::GetTimeUs();
27  }
28  const bool complete = counter_.CompleteSymbol(frame_id);
29  if (complete) {
30  const size_t frame_idx = frame_id % kFrameWnd;
31  symbol_times_.at(frame_idx).second = GetTime::GetTimeUs();
32  }
33  return complete;
34  }
35  inline bool CompleteTask(size_t frame_id, size_t symbol_id) {
36  if (counter_.GetTaskCount(frame_id, symbol_id) == 0) {
37  const size_t frame_idx = frame_id % kFrameWnd;
38  task_times_.at(frame_idx).at(symbol_id).first = GetTime::GetTimeUs();
39  }
40  const bool complete = counter_.CompleteTask(frame_id, symbol_id);
41  if (complete) {
42  const size_t frame_idx = frame_id % kFrameWnd;
43  task_times_.at(frame_idx).at(symbol_id).second = GetTime::GetTimeUs();
44  }
45  return complete;
46  }
47  inline bool CompleteTask(size_t frame_id) {
48  if (counter_.GetTaskCount(frame_id) == 0) {
49  const size_t frame_idx = frame_id % kFrameWnd;
50  symbol_times_.at(frame_idx).first = GetTime::GetTimeUs();
51  }
52  const bool complete = counter_.CompleteTask(frame_id);
53  if (complete) {
54  const size_t frame_idx = frame_id % kFrameWnd;
55  symbol_times_.at(frame_idx).second = GetTime::GetTimeUs();
56  }
57  return complete;
58  }
59  inline double GetTaskTotalTimeMs(size_t frame_id, size_t symbol_id) const {
60  const size_t frame_idx = frame_id % kFrameWnd;
61  return (task_times_.at(frame_idx).at(symbol_id).second -
62  task_times_.at(frame_idx).at(symbol_id).first) /
63  1000.0f;
64  }
65  inline double GetTaskTotalTimeMs(size_t frame_id) const {
66  const size_t frame_idx = frame_id % kFrameWnd;
67  return (symbol_times_.at(frame_idx).second -
68  symbol_times_.at(frame_idx).first) /
69  1000.0f;
70  };
71 
72  inline double GetTaskStartTimeUs(size_t frame_id, size_t symbol_id) const {
73  const size_t frame_idx = frame_id % kFrameWnd;
74  return task_times_.at(frame_idx).at(symbol_id).first;
75  }
76  inline double GetTaskStartTimeUs(size_t frame_id) const {
77  const size_t frame_idx = frame_id % kFrameWnd;
78  return symbol_times_.at(frame_idx).first;
79  };
80 
81  inline double GetTaskEndTimeUs(size_t frame_id, size_t symbol_id) const {
82  const size_t frame_idx = frame_id % kFrameWnd;
83  return task_times_.at(frame_idx).at(symbol_id).second;
84  }
85  inline double GetTaskEndTimeUs(size_t frame_id) const {
86  const size_t frame_idx = frame_id % kFrameWnd;
87  return symbol_times_.at(frame_idx).second;
88  };
89 
90  private:
92  //First = Start, Second = End
93  std::array<std::array<std::pair<double, double>, kMaxSymbols>, kFrameWnd>
95  std::array<std::pair<double, double>, kMaxSymbols> symbol_times_;
96 };
97 
98 #endif // TIME_FRAME_COUNTERS_H_
kFrameWnd
static constexpr size_t kFrameWnd
Definition: symbols.h:18
GetTime::GetTimeUs
static double GetTimeUs()
Definition: gettime.h:14
TimeFrameCounters::GetTaskStartTimeUs
double GetTaskStartTimeUs(size_t frame_id) const
Definition: time_frame_counters.h:76
FrameCounters::CompleteTask
bool CompleteTask(size_t frame_id, size_t symbol_id)
Increments the task count for input frame and symbol.
Definition: message.h:383
TimeFrameCounters::CompleteTask
bool CompleteTask(size_t frame_id)
Definition: time_frame_counters.h:47
TimeFrameCounters::task_times_
std::array< std::array< std::pair< double, double >, kMaxSymbols >, kFrameWnd > task_times_
Definition: time_frame_counters.h:94
TimeFrameCounters::CompleteSymbol
bool CompleteSymbol(size_t frame_id)
Definition: time_frame_counters.h:23
TimeFrameCounters::GetTaskEndTimeUs
double GetTaskEndTimeUs(size_t frame_id) const
Definition: time_frame_counters.h:85
FrameCounters
This class stores the counters corresponding to a frame. Specifically, it contains a) the number of s...
Definition: message.h:349
FrameCounters::GetTaskCount
size_t GetTaskCount(size_t frame_id) const
Definition: message.h:458
TimeFrameCounters::TimeFrameCounters
TimeFrameCounters()=default
TimeFrameCounters::counter_
FrameCounters counter_
Definition: time_frame_counters.h:88
TimeFrameCounters::GetTaskTotalTimeMs
double GetTaskTotalTimeMs(size_t frame_id, size_t symbol_id) const
Definition: time_frame_counters.h:59
message.h
Self defined functions for message storage and passing.
TimeFrameCounters
Definition: time_frame_counters.h:15
TimeFrameCounters::Reset
void Reset(size_t frame_id)
Definition: time_frame_counters.h:22
FrameCounters::Init
void Init(size_t max_symbol_count, size_t max_task_count=0)
Definition: message.h:353
TimeFrameCounters::GetTaskTotalTimeMs
double GetTaskTotalTimeMs(size_t frame_id) const
Definition: time_frame_counters.h:65
TimeFrameCounters::GetTaskEndTimeUs
double GetTaskEndTimeUs(size_t frame_id, size_t symbol_id) const
Definition: time_frame_counters.h:81
TimeFrameCounters::CompleteTask
bool CompleteTask(size_t frame_id, size_t symbol_id)
Definition: time_frame_counters.h:35
symbols.h
FrameCounters::Reset
void Reset(size_t frame_id)
Definition: message.h:362
TimeFrameCounters::GetTaskStartTimeUs
double GetTaskStartTimeUs(size_t frame_id, size_t symbol_id) const
Definition: time_frame_counters.h:72
TimeFrameCounters::Init
void Init(size_t max_symbol_count, size_t max_task_count=0)
Definition: time_frame_counters.h:19
FrameCounters::GetSymbolCount
size_t GetSymbolCount(size_t frame_id) const
Definition: message.h:454
gettime.h
kMaxSymbols
static constexpr size_t kMaxSymbols
Definition: symbols.h:280
FrameCounters::CompleteSymbol
bool CompleteSymbol(size_t frame_id)
Increments and checks the symbol count for input frame.
Definition: message.h:372
TimeFrameCounters::symbol_times_
std::array< std::pair< double, double >, kMaxSymbols > symbol_times_
Definition: time_frame_counters.h:95