13 #ifndef DS3D_COMMON_HPP_PROFILING_HPP
14 #define DS3D_COMMON_HPP_PROFILING_HPP
21 namespace ds3d {
namespace profiling {
28 struct timeval time_now;
29 gettimeofday(&time_now,
nullptr);
30 double now = (double)time_now.tv_sec + time_now.tv_usec / (
double)1000000;
32 auto iSrc = _timestamps.find(source_id);
33 if (iSrc != _timestamps.end()) {
34 auto& tms = iSrc->second;
35 fps = tms.size() / (now - tms.front());
36 while (tms.size() >= _max_frame_nums) {
40 iSrc = _timestamps.emplace(source_id, std::queue<double>()).first;
42 iSrc->second.push(now);
48 std::unordered_map<uint32_t, std::queue<double>> _timestamps;
49 uint32_t _max_frame_nums = 50;
54 Timing(uint32_t maxSlots = 50) : _maxTimeLotNum(maxSlots) {}
61 while (_timelots.size() > _maxTimeLotNum) {
62 _total -= _timelots.front();
68 if (_timelots.size()) {
69 return _total / _timelots.size();
75 std::queue<double> _timelots;
77 uint32_t _maxTimeLotNum = 0;
88 bool open(
const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::binary)
91 _file.open(path.c_str(), mode);
92 return _file.is_open();
94 bool isOpen()
const {
return _file.is_open(); }
98 if (_file.is_open()) {
103 bool write(
const void* buf,
size_t size)
106 return _file.write((
const char*)buf, size).good();
118 bool open(
const std::string& path, std::ios::openmode mode = std::ios::in | std::ios::binary)
121 _file.open(path.c_str(), mode);
122 return _file.is_open();
124 bool isOpen()
const {
return _file.is_open(); }
125 bool eof()
const {
return _file.eof(); }
129 if (_file.is_open()) {
134 int32_t
read(
void* buf,
size_t size)
138 return (int32_t)_file.readsome((
char*)buf, size);
146 #endif // DS3D_COMMON_HPP_PROFILING_HPP