FPS counter

Added toggle to enable an fps counter for the onroad UI and the current displayed camera.
This commit is contained in:
FrogAi
2024-02-27 16:34:47 -07:00
parent 4045564927
commit 9f12f67d06
8 changed files with 84 additions and 2 deletions

View File

@@ -935,6 +935,9 @@ void process_road_camera(MultiCameraState *s, CameraState *c, int cnt) {
void cameras_run(MultiCameraState *s) {
// FrogPilot variables
Params paramsMemory{"/dev/shm/params"};
const std::chrono::seconds fpsUpdateInterval(1);
std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();
int frameCount = 0;
LOG("-- Starting threads");
std::vector<std::thread> threads;
@@ -978,6 +981,20 @@ void cameras_run(MultiCameraState *s) {
// for debugging
//do_exit = do_exit || event_data->u.frame_msg.frame_id > (30*20);
// Increment frame count
frameCount++;
// Calculate and display FPS every second
std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now();
if (currentTime - startTime >= fpsUpdateInterval) {
double fps = static_cast<double>(frameCount) / std::chrono::duration<double>(currentTime - startTime).count();
paramsMemory.putIntNonBlocking("CameraFPS", fps / 3);
// Reset counter and timer
frameCount = 0;
startTime = currentTime;
}
if (event_data->session_hdl == s->road_cam.session_handle) {
s->road_cam.handle_camera_event(event_data);
} else if (event_data->session_hdl == s->wide_road_cam.session_handle) {