1 #include "basic_stats.h"
5 #include <sys/resource.h>
8 using namespace std::chrono;
10 bool uses_mlock = false;
12 BasicStats::BasicStats(bool verbose)
15 start = steady_clock::now();
17 metric_start_time_seconds = get_timestamp_for_metrics();
18 global_metrics.add("frames_output_total", &metric_frames_output_total);
19 global_metrics.add("frames_output_dropped", &metric_frames_output_dropped);
20 global_metrics.add("start_time_seconds", &metric_start_time_seconds, Metrics::TYPE_GAUGE);
21 global_metrics.add("memory_used_bytes", &metrics_memory_used_bytes);
22 global_metrics.add("memory_locked_limit_bytes", &metrics_memory_locked_limit_bytes);
25 void BasicStats::update(int frame_num, int stats_dropped_frames)
27 steady_clock::time_point now = steady_clock::now();
28 double elapsed = duration<double>(now - start).count();
30 metric_frames_output_total = frame_num;
31 metric_frames_output_dropped = stats_dropped_frames;
33 if (frame_num % 100 != 0) {
38 printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)",
39 frame_num, stats_dropped_frames, elapsed, frame_num / elapsed,
40 1e3 * elapsed / frame_num);
43 // Check our memory usage, to see if we are close to our mlockall()
44 // limit (if at all set).
46 if (getrusage(RUSAGE_SELF, &used) == -1) {
47 perror("getrusage(RUSAGE_SELF)");
50 metrics_memory_used_bytes = used.ru_maxrss * 1024;
54 if (getrlimit(RLIMIT_MEMLOCK, &limit) == -1) {
55 perror("getrlimit(RLIMIT_MEMLOCK)");
58 metrics_memory_locked_limit_bytes = limit.rlim_cur;
61 if (limit.rlim_cur == 0) {
62 printf(", using %ld MB memory (locked)",
63 long(used.ru_maxrss / 1024));
65 printf(", using %ld / %ld MB lockable memory (%.1f%%)",
66 long(used.ru_maxrss / 1024),
67 long(limit.rlim_cur / 1048576),
68 float(100.0 * (used.ru_maxrss * 1024.0) / limit.rlim_cur));
72 metrics_memory_locked_limit_bytes = 0.0 / 0.0;
74 printf(", using %ld MB memory (not locked)",
75 long(used.ru_maxrss / 1024));