#include <math.h>
#include <algorithm>
+#include <chrono>
#include <locale>
#include <sstream>
using namespace std;
+using namespace std::chrono;
Metrics global_metrics;
+double get_timestamp_for_metrics()
+{
+ return duration<double>(system_clock::now().time_since_epoch()).count();
+}
+
namespace {
string serialize_name(const string &name, const vector<pair<string, string>> &labels)
class Histogram;
+// Prometheus recommends the use of timestamps instead of “time since event”,
+// so you can use this to get the number of seconds since the epoch.
+// Note that this will be wrong if your clock changes, so for non-metric use,
+// you should use std::chrono::steady_clock instead.
+double get_timestamp_for_metrics();
+
class Metrics {
public:
enum Type {
set_output_card_internal(global_flags.output_card);
}
+ metric_start_time_seconds = get_timestamp_for_metrics();
+
global_metrics.add("frames_output_total", &metric_frames_output_total);
global_metrics.add("frames_output_dropped", &metric_frames_output_dropped);
- global_metrics.add("uptime_seconds", &metric_uptime_seconds);
+ global_metrics.add("start_time_seconds", &metric_start_time_seconds);
global_metrics.add("memory_used_bytes", &metrics_memory_used_bytes);
global_metrics.add("metrics_memory_locked_limit_bytes", &metrics_memory_locked_limit_bytes);
}
metric_frames_output_total = frame_num;
metric_frames_output_dropped = stats_dropped_frames;
- metric_uptime_seconds = elapsed;
if (frame_num % 100 == 0) {
printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)",
// Metrics.
std::atomic<int64_t> metric_frames_output_total{0};
std::atomic<int64_t> metric_frames_output_dropped{0};
- std::atomic<double> metric_uptime_seconds{0.0};
+ std::atomic<double> metric_start_time_seconds{0.0 / 0.0};
std::atomic<int64_t> metrics_memory_used_bytes{0};
std::atomic<double> metrics_memory_locked_limit_bytes{0.0 / 0.0};
};