18 #ifndef DS3D_COMMON_HPP_PROFILING_HPP
19 #define DS3D_COMMON_HPP_PROFILING_HPP
22 #include <ds3d/common/common.h>
26 namespace ds3d {
namespace profiling {
33 struct timeval time_now;
34 gettimeofday(&time_now,
nullptr);
35 double now = (double)time_now.tv_sec + time_now.tv_usec / (
double)1000000;
37 auto iSrc = _timestamps.find(source_id);
38 if (iSrc != _timestamps.end()) {
39 auto& tms = iSrc->second;
40 fps = tms.size() / (now - tms.front());
41 while (tms.size() >= _max_frame_nums) {
45 iSrc = _timestamps.emplace(source_id, std::queue<double>()).first;
47 iSrc->second.push(now);
53 std::unordered_map<uint32_t, std::queue<double>> _timestamps;
54 uint32_t _max_frame_nums = 50;
59 Timing(uint32_t maxSlots = 50) : _maxTimeLotNum(maxSlots) {}
66 while (_timelots.size() > _maxTimeLotNum) {
67 _total -= _timelots.front();
73 if (_timelots.size()) {
74 return _total / _timelots.size();
80 std::queue<double> _timelots;
82 uint32_t _maxTimeLotNum = 0;
93 bool open(
const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::binary)
96 _file.open(path.c_str(), mode);
97 return _file.is_open();
99 bool isOpen()
const {
return _file.is_open(); }
103 if (_file.is_open()) {
108 bool write(
const void* buf,
size_t size)
111 return _file.write((
const char*)buf, size).good();
123 bool open(
const std::string& path, std::ios::openmode mode = std::ios::in | std::ios::binary)
126 _file.open(path.c_str(), mode);
127 return _file.is_open();
129 bool isOpen()
const {
return _file.is_open(); }
130 bool eof()
const {
return _file.eof(); }
134 if (_file.is_open()) {
139 int32_t
read(
void* buf,
size_t size)
143 return (int32_t)_file.readsome((
char*)buf, size);
151 #endif // DS3D_COMMON_HPP_PROFILING_HPP