Agora  1.2.0
Agora project
stats.h
Go to the documentation of this file.
1 
6 #ifndef STATS_H_
7 #define STATS_H_
8 
9 #include <array>
10 #include <cstddef>
11 #include <string>
12 
13 #include "config.h"
14 #include "gettime.h"
15 #include "memory_manage.h"
16 #include "message.h"
17 #include "symbols.h"
18 
19 static constexpr size_t kMaxStatBreakdown = 4;
20 
21 // Accumulated task duration for all tracked frames in each worker thread
22 struct DurationStat {
23  std::array<size_t, kMaxStatBreakdown> task_duration_; // Unit = TSC cycles
24  size_t task_count_;
26  void Reset() { std::memset(this, 0, sizeof(DurationStat)); }
27 };
28 
29 // Temporary summary statistics assembled from per-thread runtime stats
30 struct FrameSummary {
31  std::array<double, kMaxStatBreakdown> us_this_thread_;
32  size_t count_this_thread_ = 0;
33  std::array<double, kMaxStatBreakdown> us_avg_threads_;
34  size_t count_all_threads_ = 0;
35  FrameSummary() { std::memset(this, 0, sizeof(FrameSummary)); }
36 };
37 
38 // Type of timestamps recorded at the master for a framePhyStats
39 // TODO: Add definitions of what each event means
40 enum class TsType : size_t {
41  kFirstSymbolRX, // First symbol in packet received
42  kProcessingStarted, // Signal processing started on a pilot symbol
43  kPilotAllRX, // All pilot packets received
44  kRCAllRX, // All Reciprocity Calibration Symbols received
45  kFFTPilotsDone, // Completed FFT for all pilots in this frame
46  kBeamDone, // Completed zeroforcing for this frame
47  kDemulDone, // Completed demodulation for this frame
48  kRXDone, // All packets of a frame received
49  kRCDone, // Recirocity Calibration Computation done
51  kDecodeDone, // Completed all LDPC decoding for this frame
53  kIFFTDone,
55  kTXDone,
56  kModulDone,
57  kFFTDone,
59 };
60 static constexpr size_t kNumTimestampTypes =
61  static_cast<size_t>(TsType::kTsTypeEnd);
62 
63 class Stats {
64  public:
65  explicit Stats(const Config* const cfg);
66  ~Stats();
67 
70  void UpdateStats(size_t frame_id);
71 
74  void SaveToFile();
75 
77  void PrintSummary();
78 
81  void MasterSetTsc(TsType timestamp_type, size_t frame_id) {
82  this->master_timestamps_.at(static_cast<size_t>(timestamp_type))
83  .at(frame_id % kNumStatsFrames) = GetTime::Rdtsc();
84  }
85 
88  size_t MasterGetTsc(TsType timestamp_type, size_t frame_id) const {
89  return this->master_timestamps_.at(static_cast<size_t>(timestamp_type))
90  .at((frame_id % kNumStatsFrames));
91  }
92 
95  double MasterGetMsSince(TsType timestamp_type, size_t frame_id) const {
96  return GetTime::CyclesToMs(
97  GetTime::Rdtsc() - MasterGetTsc(timestamp_type, frame_id),
98  this->freq_ghz_);
99  }
100 
103  double MasterGetUsSince(TsType timestamp_type, size_t frame_id) const {
104  return GetTime::CyclesToUs(
105  GetTime::Rdtsc() - MasterGetTsc(timestamp_type, frame_id),
106  this->freq_ghz_);
107  }
108 
111  double MasterGetUsFromRef(TsType timestamp_type, size_t frame_id,
112  size_t reference_tsc) const {
113  return GetTime::CyclesToUs(
114  MasterGetTsc(timestamp_type, frame_id) - reference_tsc,
115  this->freq_ghz_);
116  }
117 
120  double MasterGetDeltaMs(TsType timestamp_type_1, TsType timestamp_type_2,
121  size_t frame_id) const {
122  return GetTime::CyclesToMs(MasterGetTsc(timestamp_type_1, frame_id) -
123  MasterGetTsc(timestamp_type_2, frame_id),
124  this->freq_ghz_);
125  }
126 
129  double MasterGetDeltaUs(TsType timestamp_type_1, TsType timestamp_type_2,
130  size_t frame_id) const {
131  return GetTime::CyclesToUs(MasterGetTsc(timestamp_type_1, frame_id) -
132  MasterGetTsc(timestamp_type_2, frame_id),
133  this->freq_ghz_);
134  }
135 
138  double MasterGetDeltaMs(TsType timestamp_type, size_t frame_id_1,
139  size_t frame_id_2) const {
140  return GetTime::CyclesToMs(MasterGetTsc(timestamp_type, frame_id_1) -
141  MasterGetTsc(timestamp_type, frame_id_2),
142  this->freq_ghz_);
143  }
144 
147  double MasterGetDeltaUs(TsType timestamp_type, size_t frame_id_1,
148  size_t frame_id_2) const {
149  return GetTime::CyclesToUs(MasterGetTsc(timestamp_type, frame_id_1) -
150  MasterGetTsc(timestamp_type, frame_id_2),
151  this->freq_ghz_);
152  }
153 
154  void PrintPerFrameDone(PrintType print_type, size_t frame_id) const;
155  void PrintPerSymbolDone(PrintType print_type, size_t frame_id,
156  size_t symbol_id, size_t sub_count) const;
157  void PrintPerTaskDone(PrintType print_type, size_t frame_id, size_t symbol_id,
158  size_t ant_or_sc_id, size_t task_count) const;
159 
163  return &this->worker_durations_[thread_id]
164  .duration_stat_[static_cast<size_t>(doer_type)];
165  }
166 
171  return &this->worker_durations_old_[thread_id]
172  .duration_stat_[static_cast<size_t>(doer_type)];
173  }
174 
175  inline size_t LastFrameId() const { return this->last_frame_id_; }
179  inline Table<size_t>& FrameStart() { return this->frame_start_; };
180 
181  private:
182  // Fill in running time summary stats for the current frame for this
183  // thread and Doer type
184  void PopulateSummary(FrameSummary* frame_summary, size_t thread_id,
185  DoerType doer_type);
186 
187  static void ComputeAvgOverThreads(FrameSummary* frame_summary,
188  size_t thread_num, size_t break_down_num);
189  static void PrintPerThreadPerTask(std::string const& doer_string,
190  FrameSummary const& s);
191  static std::string PrintPerFrame(std::string const& doer_string,
192  FrameSummary const& frame_summary);
193 
194  size_t GetTotalTaskCount(DoerType doer_type, size_t thread_num);
195 
196  const Config* const config_;
197 
198  const size_t task_thread_num_;
199  const size_t fft_thread_num_;
200  const size_t beam_thread_num_;
201  const size_t demul_thread_num_;
202  const size_t decode_thread_num_;
204  const double freq_ghz_;
205  const size_t creation_tsc_; // TSC at which this object was created
206 
209  std::array<std::array<double, kNumStatsFrames>, kNumTimestampTypes>
211 
216  std::array<DurationStat, kNumDoerTypes> duration_stat_;
217  std::array<uint8_t, 64> false_sharing_padding_;
218  };
219 
220  std::array<TimeDurationsStats, kMaxThreads> worker_durations_;
221  std::array<TimeDurationsStats, kMaxThreads> worker_durations_old_;
222 
223  std::array<std::array<double, kNumStatsFrames>, kNumDoerTypes> doer_us_;
224  std::array<std::array<std::array<double, kNumStatsFrames>, kMaxStatBreakdown>,
227 
229 
234 };
235 
236 #endif // STATS_H_
Stats::MasterGetDeltaUs
double MasterGetDeltaUs(TsType timestamp_type_1, TsType timestamp_type_2, size_t frame_id) const
Definition: stats.h:129
FrameStats::NumPilotSyms
size_t NumPilotSyms() const
Definition: framestats.cc:91
TsType::kTXProcessedFirst
@ kTXProcessedFirst
FrameSummary::count_all_threads_
size_t count_all_threads_
Definition: stats.h:34
TsType::kFFTDone
@ kFFTDone
kStatsPrintFrameSummary
static constexpr bool kStatsPrintFrameSummary
Definition: symbols.h:195
Config::SocketThreadNum
size_t SocketThreadNum() const
Definition: config.h:182
DoerType::kBeam
@ kBeam
kProjectDir
static const std::string kProjectDir
Definition: stats.cc:12
Stats::MasterSetTsc
void MasterSetTsc(TsType timestamp_type, size_t frame_id)
Definition: stats.h:81
PrintType::kRC
@ kRC
Stats::FrameStart
Table< size_t > & FrameStart()
Definition: stats.h:179
moodycamel::details::thread_id
thread_id_t thread_id()
Definition: concurrentqueue.h:157
DoerType::kEncode
@ kEncode
Config::UeAntNum
size_t UeAntNum() const
Definition: config.h:41
Table::Calloc
void Calloc(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:45
DurationStat::Reset
void Reset()
Definition: stats.h:26
PrintType
PrintType
Definition: symbols.h:96
fmt::v8::printf
auto printf(const S &fmt, const T &... args) -> int
Definition: printf.h:631
Stats::beam_thread_num_
const size_t beam_thread_num_
Definition: stats.h:200
Stats::doer_breakdown_us_
std::array< std::array< std::array< double, kNumStatsFrames >, kMaxStatBreakdown >, kNumDoerTypes > doer_breakdown_us_
Definition: stats.h:226
Stats::freq_ghz_
const double freq_ghz_
Definition: stats.h:204
PrintType::kPacketFromMac
@ kPacketFromMac
TsType::kTsTypeEnd
@ kTsTypeEnd
kDebugPrintStatsPerThread
static constexpr bool kDebugPrintStatsPerThread
Definition: symbols.h:200
Stats::task_thread_num_
const size_t task_thread_num_
Definition: stats.h:198
Stats::SaveToFile
void SaveToFile()
Definition: stats.cc:151
Stats
Definition: stats.h:63
Stats::doer_us_
std::array< std::array< double, kNumStatsFrames >, kNumDoerTypes > doer_us_
Definition: stats.h:223
PrintType::kPacketTX
@ kPacketTX
Stats::TimeDurationsStats::duration_stat_
std::array< DurationStat, kNumDoerTypes > duration_stat_
Definition: stats.h:216
TsType::kRXDone
@ kRXDone
DurationStat::task_duration_
std::array< size_t, kMaxStatBreakdown > task_duration_
Definition: stats.h:23
Stats::frame_start_
Table< size_t > frame_start_
Definition: stats.h:233
Stats::master_timestamps_
std::array< std::array< double, kNumStatsFrames >, kNumTimestampTypes > master_timestamps_
Definition: stats.h:210
Stats::TimeDurationsStats
Definition: stats.h:215
memory_manage.h
PrintType::kEncode
@ kEncode
Stats::worker_durations_old_
std::array< TimeDurationsStats, kMaxThreads > worker_durations_old_
Definition: stats.h:221
DoerType::kPrecode
@ kPrecode
Config::BsAntNum
size_t BsAntNum() const
Definition: config.h:35
Stats::config_
const Config *const config_
Definition: stats.h:196
PrintType::kPacketRXPilots
@ kPacketRXPilots
fclose
fclose(fileID)
AGORA_LOG_ERROR
#define AGORA_LOG_ERROR(...)
Definition: logger.h:39
TOSTRING
#define TOSTRING(x)
Definition: symbols.h:14
Direction::kUplink
@ kUplink
Config::Frame
const FrameStats & Frame() const
Definition: config.h:340
Stats::creation_tsc_
const size_t creation_tsc_
Definition: stats.h:205
PrintType::kFFTPilots
@ kFFTPilots
DoerType::kCSI
@ kCSI
TsType::kFFTPilotsDone
@ kFFTPilotsDone
GetTime::CyclesToUs
static double CyclesToUs(size_t cycles, double freq_ghz)
Definition: gettime.h:97
Stats::last_frame_id_
size_t last_frame_id_
Definition: stats.h:228
TsType::kModulDone
@ kModulDone
Table< size_t >
Receiver
Definition: receiver.h:27
Stats::break_down_num_
const size_t break_down_num_
Definition: stats.h:203
Stats::worker_durations_
std::array< TimeDurationsStats, kMaxThreads > worker_durations_
Definition: stats.h:220
Stats::PrintPerFrameDone
void PrintPerFrameDone(PrintType print_type, size_t frame_id) const
Definition: stats.cc:453
Stats::PrintPerFrame
static std::string PrintPerFrame(std::string const &doer_string, FrameSummary const &frame_summary)
Definition: stats.cc:77
kMaxStatBreakdown
static constexpr size_t kMaxStatBreakdown
Definition: stats.h:19
FrameSummary::us_avg_threads_
std::array< double, kMaxStatBreakdown > us_avg_threads_
Definition: stats.h:33
Config::OfdmDataNum
size_t OfdmDataNum() const
Definition: config.h:47
Stats::MasterGetTsc
size_t MasterGetTsc(TsType timestamp_type, size_t frame_id) const
Definition: stats.h:88
Stats::MasterGetDeltaUs
double MasterGetDeltaUs(TsType timestamp_type, size_t frame_id_1, size_t frame_id_2) const
Definition: stats.h:147
stats.h
Declaration file for the Stats class. Includes definations for DurationStat and FrameSummery types.
Stats::GetTotalTaskCount
size_t GetTotalTaskCount(DoerType doer_type, size_t thread_num)
Definition: stats.cc:340
kStatsDataFilename
static const std::string kStatsDataFilename
Definition: stats.cc:15
Stats::MasterGetDeltaMs
double MasterGetDeltaMs(TsType timestamp_type, size_t frame_id_1, size_t frame_id_2) const
Definition: stats.h:138
kDoerNames
static const std::map< DoerType, std::string > kDoerNames
Definition: symbols.h:85
DurationStat::task_count_
size_t task_count_
Definition: stats.h:24
Stats::MasterGetMsSince
double MasterGetMsSince(TsType timestamp_type, size_t frame_id) const
Definition: stats.h:95
Stats::Stats
Stats(const Config *const cfg)
Definition: stats.cc:20
FrameSummary
Definition: stats.h:30
message.h
Self defined functions for message storage and passing.
Table::Free
void Free()
Definition: memory_manage.h:84
PrintType::kFFTCal
@ kFFTCal
Config::Beamforming
std::string Beamforming() const
Definition: config.h:109
PrintType::kIFFT
@ kIFFT
TsType::kPrecodeDone
@ kPrecodeDone
i
for i
Definition: generate_data.m:107
GetTime
Definition: gettime.h:11
TsType::kDecodeDone
@ kDecodeDone
u
Plot Rx waveform for u
Definition: inspect_single_frame.m:108
GetTime::Rdtsc
static size_t Rdtsc()
Return the TSC.
Definition: gettime.h:25
Stats::PrintPerThreadPerTask
static void PrintPerThreadPerTask(std::string const &doer_string, FrameSummary const &s)
Definition: stats.cc:60
fmt::v8::fprintf
auto fprintf(std::FILE *f, const S &fmt, const T &... args) -> int
Definition: printf.h:607
Agora_memory::Alignment_t::kAlign64
@ kAlign64
PrintType::kPacketTXFirst
@ kPacketTXFirst
TsType::kRCAllRX
@ kRCAllRX
kNumTimestampTypes
static constexpr size_t kNumTimestampTypes
Definition: stats.h:60
TsType::kProcessingStarted
@ kProcessingStarted
PrintType::kPacketToMac
@ kPacketToMac
TsType::kDemulDone
@ kDemulDone
Direction::kDownlink
@ kDownlink
FrameSummary::FrameSummary
FrameSummary()
Definition: stats.h:35
Stats::PrintSummary
void PrintSummary()
If worker stats collection is enabled, prsize_t a summary of stats.
Definition: stats.cc:348
Stats::ComputeAvgOverThreads
static void ComputeAvgOverThreads(FrameSummary *frame_summary, size_t thread_num, size_t break_down_num)
Definition: stats.cc:52
kNumStatsFrames
static constexpr size_t kNumStatsFrames
Definition: symbols.h:300
DoerType::kIFFT
@ kIFFT
TsType::kRCDone
@ kRCDone
Stats::TimeDurationsStats::false_sharing_padding_
std::array< uint8_t, 64 > false_sharing_padding_
Definition: stats.h:217
TsType::kPilotAllRX
@ kPilotAllRX
s
s
Definition: simulate_performance.m:3
symbols.h
Stats::LastFrameId
size_t LastFrameId() const
Definition: stats.h:175
DurationStat
Definition: stats.h:22
TsType::kFirstSymbolRX
@ kFirstSymbolRX
Stats::PrintPerSymbolDone
void PrintPerSymbolDone(PrintType print_type, size_t frame_id, size_t symbol_id, size_t sub_count) const
Definition: stats.cc:549
Config::LdpcConfig
const LDPCconfig & LdpcConfig(Direction dir) const
Definition: config.h:280
kIsWorkerTimingEnabled
static constexpr bool kIsWorkerTimingEnabled
Definition: symbols.h:303
PrintType::kPacketRX
@ kPacketRX
FrameStats::NumDLSyms
size_t NumDLSyms() const
Definition: framestats.cc:83
DoerType::kDecode
@ kDecode
Config::BeamEventsPerSymbol
size_t BeamEventsPerSymbol() const
Definition: config.h:202
TsType::kBeamDone
@ kBeamDone
FrameStats::NumULSyms
size_t NumULSyms() const
Definition: framestats.cc:85
PrintType::kBeam
@ kBeam
GetTime::CyclesToMs
static double CyclesToMs(size_t cycles, double freq_ghz)
Definition: gettime.h:91
DoerType::kDemul
@ kDemul
Config
Definition: config.h:26
AGORA_LOG_INFO
#define AGORA_LOG_INFO(...)
Definition: logger.h:62
Stats::UpdateStats
void UpdateStats(size_t frame_id)
Definition: stats.cc:96
Stats::PrintPerTaskDone
void PrintPerTaskDone(PrintType print_type, size_t frame_id, size_t symbol_id, size_t ant_or_sc_id, size_t task_count) const
Definition: stats.cc:623
RtAssert
static void RtAssert(bool condition, const char *throw_str)
Definition: utils.h:104
kDebugPrintPerSymbolDone
static constexpr bool kDebugPrintPerSymbolDone
Definition: symbols.h:198
TsType::kEncodeDone
@ kEncodeDone
receiver.h
Declaration file for the receiver class.
TsType
TsType
Definition: stats.h:40
kStatsDetailedDataFilename
static const std::string kStatsDetailedDataFilename
Definition: stats.cc:17
kNumDoerTypes
static constexpr size_t kNumDoerTypes
Definition: symbols.h:83
to_string
std::string to_string() const
Definition: eth_common.h:64
Stats::MasterGetDeltaMs
double MasterGetDeltaMs(TsType timestamp_type_1, TsType timestamp_type_2, size_t frame_id) const
Definition: stats.h:120
Stats::MasterGetUsSince
double MasterGetUsSince(TsType timestamp_type, size_t frame_id) const
Definition: stats.h:103
config.h
Declaration file for the configuration class which importants json configuration values into class va...
Stats::demul_thread_num_
const size_t demul_thread_num_
Definition: stats.h:201
gettime.h
PrintType::kFFTData
@ kFFTData
Stats::~Stats
~Stats()
Definition: stats.cc:33
kStatsOutputFilePath
static const std::string kStatsOutputFilePath
Definition: stats.cc:13
Stats::MasterGetUsFromRef
double MasterGetUsFromRef(TsType timestamp_type, size_t frame_id, size_t reference_tsc) const
Definition: stats.h:111
DurationStat::DurationStat
DurationStat()
Definition: stats.h:25
FrameSummary::us_this_thread_
std::array< double, kMaxStatBreakdown > us_this_thread_
Definition: stats.h:31
LDPCconfig::NumBlocksInSymbol
void NumBlocksInSymbol(size_t num_blocks)
Definition: ldpc_config.h:41
Stats::GetDurationStatOld
DurationStat * GetDurationStatOld(DoerType doer_type, size_t thread_id)
Definition: stats.h:170
Stats::decode_thread_num_
const size_t decode_thread_num_
Definition: stats.h:202
kDebugPrintPerFrameDone
static constexpr bool kDebugPrintPerFrameDone
Definition: symbols.h:196
Stats::fft_thread_num_
const size_t fft_thread_num_
Definition: stats.h:199
PrintType::kDecode
@ kDecode
TsType::kTXDone
@ kTXDone
main
int main(int argc, char const *argv[])
Definition: receiver_cli.cc:7
TsType::kIFFTDone
@ kIFFTDone
DoerType::kFFT
@ kFFT
DoerType
DoerType
Definition: symbols.h:67
FrameSummary::count_this_thread_
size_t count_this_thread_
Definition: stats.h:32
Stats::PopulateSummary
void PopulateSummary(FrameSummary *frame_summary, size_t thread_id, DoerType doer_type)
Definition: stats.cc:35
PrintType::kPrecode
@ kPrecode
Stats::GetDurationStat
DurationStat * GetDurationStat(DoerType doer_type, size_t thread_id)
Definition: stats.h:162
PrintType::kDemul
@ kDemul
kDebugPrintPerTaskDone
static constexpr bool kDebugPrintPerTaskDone
Definition: symbols.h:199
kAllDoerTypes
static constexpr std::array< DoerType,(static_cast< size_t >DoerType::kRC)+1)> kAllDoerTypes
Definition: symbols.h:80