rates-printer.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved.
3 
4 #include <iostream>
5 #include "rates-printer.h"
6 
7 namespace librealsense
8 {
10  {
11  return frame && !frame.is<rs2::frameset>();
12  }
13 
15  {
16  if (_profiles.empty())
17  {
18  std::cout << std::endl << "#### RS Frame Rate Printer ####" << std::endl;
20  }
21  _profiles[f.get_profile().get()].on_frame_arrival(f);
22  print();
23  return f;
24  }
25 
27  {
28  auto period = std::chrono::milliseconds(1000 / _render_rate).count();
29  auto curr_time = std::chrono::steady_clock::now();
30  auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - _last_print_time).count();
31 
32  if (diff < period)
33  return;
34 
35  _last_print_time = curr_time;
36 
37  std::cout << std::fixed;
38  std::cout << std::setprecision(1);
39  std::cout << "\r";
40  for (auto p : _profiles)
41  {
42  auto sp = p.second.get_stream_profile();
43  std::cout << sp.stream_name() << "[" << sp.stream_index() << "]: " <<
44  p.second.get_fps() << "/" << sp.fps() << " [FPS] || ";
45  }
46  }
47 
48  rates_printer::profile::profile() : _counter(0), _last_frame_number(0), _actual_fps(0)
49  {
50  }
51 
53  {
54  return _last_frame_number;
55  }
56 
58  {
59  return _stream_profile;
60  }
61 
63  {
64  return _actual_fps;
65  }
66 
68  {
69  if (!_stream_profile)
70  {
73  }
75  return;
77  auto curr_time = std::chrono::steady_clock::now();
78  _time_points.push_back(curr_time);
79  auto oldest = _time_points[0];
80  if (_time_points.size() > size_t(_stream_profile.fps()))
81  _time_points.erase(_time_points.begin());
82  auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - oldest).count() / 1000.f;
83  if (diff > 0)
84  _actual_fps = _time_points.size() / diff;
85  }
86 }
unsigned long long last_frame_number()
GLfloat GLfloat p
Definition: glext.h:12687
stream_profile get_profile() const
Definition: rs_frame.hpp:557
std::map< const rs2_stream_profile *, profile > _profiles
Definition: rates-printer.h:41
rs2::stream_profile get_stream_profile()
std::chrono::steady_clock::time_point _last_print_time
Definition: rates-printer.h:42
bool should_process(const rs2::frame &frame) override
GLdouble f
bool is() const
Definition: rs_frame.hpp:570
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
std::ostream & cout()
void on_frame_arrival(const rs2::frame &f)
const rs2_stream_profile * get() const
Definition: rs_frame.hpp:137
GLint GLsizei count
GLsizei GLsizei GLchar * source
std::vector< std::chrono::steady_clock::time_point > _time_points
Definition: rates-printer.h:26
unsigned long long get_frame_number() const
Definition: rs_frame.hpp:521
std::chrono::steady_clock::time_point _last_time
Definition: rates-printer.h:29
int fps() const
Definition: rs_frame.hpp:49


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39