XLinkGlobalProfilingLogger.cpp
Go to the documentation of this file.
2 
3 #include <XLink/XLink.h>
4 
5 #include "Logging.hpp"
7 
8 using namespace std;
9 using namespace std::chrono;
10 
11 namespace dai {
12 
13 XLinkGlobalProfilingLogger::XLinkGlobalProfilingLogger() {}
14 
15 void XLinkGlobalProfilingLogger::enable(bool en) {
16  running = false;
17  if(thr.joinable()) thr.join();
18 
19  if(en) {
20  running = true;
21  XLinkProfStart();
22  thr = std::thread([this]() {
23  XLinkProf_t lastProf = {};
24  while(running) {
25  XLinkProf_t prof;
26  XLinkGetGlobalProfilingData(&prof);
27 
28  long long w = prof.totalWriteBytes - lastProf.totalWriteBytes;
29  long long r = prof.totalReadBytes - lastProf.totalReadBytes;
30  w /= rate.load();
31  r /= rate.load();
32 
33  logger::debug("Profiling global write speed: {:.2f} MiB/s, read speed: {:.2f} MiB/s, total written: {:.2f} MiB, read: {:.2f} MiB",
34  w / 1024.0f / 1024.0f,
35  r / 1024.0f / 1024.0f,
36  prof.totalWriteBytes / 1024.0f / 1024.0f,
37  prof.totalReadBytes / 1024.0f / 1024.0f);
38 
39  lastProf = prof;
40  this_thread::sleep_for(duration<float>(1) / rate.load());
41  }
42  });
43  }
44 }
45 void XLinkGlobalProfilingLogger::setRate(float rate) {
46  this->rate = rate;
47 }
48 
49 float XLinkGlobalProfilingLogger::getRate() {
50  return rate;
51 }
52 XLinkGlobalProfilingLogger::~XLinkGlobalProfilingLogger() {
53  enable(false);
54 }
55 
56 XLinkGlobalProfilingLogger& XLinkGlobalProfilingLogger::getInstance() {
57  static XLinkGlobalProfilingLogger instance; // Guaranteed to be destroyed, instantiated on first use.
58  return instance;
59 }
60 
61 } // namespace dai
dai::logger::debug
void debug(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:72
dai::XLinkGlobalProfilingLogger
Definition: XLinkGlobalProfilingLogger.hpp:19
Initialization.hpp
XLinkGlobalProfilingLogger.hpp
std
Definition: Node.hpp:366
Logging.hpp
dai
Definition: CameraExposureOffset.hpp:6


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19