Skip to content
Snippets Groups Projects
Commit acd3f857 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add some GPU stats

parent 35554cc8
No related branches found
No related tags found
No related merge requests found
Pipeline #29090 failed
...@@ -72,6 +72,6 @@ target_include_directories(ftl-gui2 PUBLIC ...@@ -72,6 +72,6 @@ target_include_directories(ftl-gui2 PUBLIC
#endif() #endif()
#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include) #target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(ftl-gui2 ftlcommon ftldata ftlctrl ftlrgbd ftlstreams ftlrender Threads::Threads ${OpenCV_LIBS} openvr ftlnet nanogui ${NANOGUI_EXTRA_LIBS} ceres) target_link_libraries(ftl-gui2 ftlcommon ftldata ftlctrl ftlrgbd ftlstreams ftlrender Threads::Threads ${OpenCV_LIBS} openvr ftlnet nanogui ${NANOGUI_EXTRA_LIBS} ceres nvidia-ml)
target_precompile_headers(ftl-gui2 REUSE_FROM ftldata) target_precompile_headers(ftl-gui2 REUSE_FROM ftldata)
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
#include <loguru.hpp> #include <loguru.hpp>
#include <nvml.h>
#ifdef WIN32
#pragma comment(lib, "nvml")
#endif
using ftl::gui2::Statistics; using ftl::gui2::Statistics;
using ftl::gui2::StatisticsPanel; using ftl::gui2::StatisticsPanel;
...@@ -21,6 +27,10 @@ std::string to_string_with_precision(const T a_value, const int n = 6) { ...@@ -21,6 +27,10 @@ std::string to_string_with_precision(const T a_value, const int n = 6) {
return out.str(); return out.str();
} }
Statistics::~Statistics() {
nvmlShutdown();
}
void Statistics::update(double delta) { void Statistics::update(double delta) {
time_count_ += delta; time_count_ += delta;
if (time_count_ > 1.0) { if (time_count_ > 1.0) {
...@@ -29,10 +39,41 @@ void Statistics::update(double delta) { ...@@ -29,10 +39,41 @@ void Statistics::update(double delta) {
getJSON(StatisticsPanel::PERFORMANCE_INFO)["Bitrate"] = to_string_with_precision(bitrate, 1) + std::string("Mbit/s"); getJSON(StatisticsPanel::PERFORMANCE_INFO)["Bitrate"] = to_string_with_precision(bitrate, 1) + std::string("Mbit/s");
} }
time_count_ = 0.0; time_count_ = 0.0;
size_t gpu_free_mem;
size_t gpu_total_mem;
cudaSafeCall(cudaMemGetInfo(&gpu_free_mem, &gpu_total_mem));
float gpu_mem = 1.0f - (float(gpu_free_mem) / float(gpu_total_mem));
getJSON(StatisticsPanel::PERFORMANCE_INFO)["GPU Memory"] = to_string_with_precision(gpu_mem*100.0f, 1) + std::string("%");
nvmlDevice_t device;
auto result = nvmlDeviceGetHandleByIndex(0, &device);
nvmlUtilization_st device_utilization;
result = nvmlDeviceGetUtilizationRates(device, &device_utilization);
getJSON(StatisticsPanel::PERFORMANCE_INFO)["GPU Usage"] = std::to_string(device_utilization.gpu) + std::string("%");
unsigned int decode_util;
unsigned int decode_period;
result = nvmlDeviceGetDecoderUtilization(device, &decode_util, &decode_period);
getJSON(StatisticsPanel::PERFORMANCE_INFO)["GPU Decoder"] = std::to_string(decode_util) + std::string("%");
// Doesn't seem to work
unsigned int encoder_sessions=0;
unsigned int encoder_fps;
unsigned int encoder_latency;
result = nvmlDeviceGetEncoderStats(device, &encoder_sessions, &encoder_fps, &encoder_latency);
unsigned int encoder_util;
unsigned int encoder_period;
result = nvmlDeviceGetEncoderUtilization(device, &encoder_util, &encoder_period);
getJSON(StatisticsPanel::PERFORMANCE_INFO)["GPU Encoder"] = std::to_string(encoder_util) + std::string("% (") + std::to_string(encoder_sessions) + std::string(")");
} }
} }
void Statistics::init() { void Statistics::init() {
auto result = nvmlInit();
if (result != NVML_SUCCESS) throw FTL_Error("No NVML");
/** /**
* TODO: store all values in hash table and allow other modules to * TODO: store all values in hash table and allow other modules to
* add/remove items/groups. * add/remove items/groups.
......
...@@ -21,6 +21,10 @@ enum class StatisticsPanel { ...@@ -21,6 +21,10 @@ enum class StatisticsPanel {
class Statistics : public Module { class Statistics : public Module {
public: public:
using Module::Module; using Module::Module;
//Statistics();
~Statistics();
virtual void init() override; virtual void init() override;
virtual void update(double delta) override; virtual void update(double delta) override;
......
...@@ -1153,6 +1153,7 @@ bool Feed::_isRecording() { ...@@ -1153,6 +1153,7 @@ bool Feed::_isRecording() {
} }
ftl::data::FrameSetPtr Feed::getFrameSet(uint32_t fsid) { ftl::data::FrameSetPtr Feed::getFrameSet(uint32_t fsid) {
SHARED_LOCK(mtx_, lk);
if (latest_.count(fsid) == 0) { if (latest_.count(fsid) == 0) {
throw ftl::exception("No FrameSet with given ID"); throw ftl::exception("No FrameSet with given ID");
} }
......
...@@ -64,6 +64,8 @@ ScreenRender::ScreenRender(ftl::render::Source *host, ftl::stream::Feed *feed) ...@@ -64,6 +64,8 @@ ScreenRender::ScreenRender(ftl::render::Source *host, ftl::stream::Feed *feed)
filter_ = feed_->filter({Channel::Colour, Channel::Depth}); filter_ = feed_->filter({Channel::Colour, Channel::Depth});
} }
}); });
calibration_uptodate_.clear();
} }
ScreenRender::~ScreenRender() { ScreenRender::~ScreenRender() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment