Visuals - Developer UI - FPS counter
Display the 'Frames Per Second' (FPS) of your onroad UI for monitoring system performance.
This commit is contained in:
parent
f64b9217dd
commit
bc68e89f70
|
@ -615,6 +615,7 @@ void AnnotatedCameraWidget::paintGL() {
|
|||
double cur_draw_t = millis_since_boot();
|
||||
double dt = cur_draw_t - prev_draw_t;
|
||||
double fps = fps_filter.update(1. / dt * 1000);
|
||||
s->scene.fps = fps;
|
||||
if (fps < 15) {
|
||||
LOGW("slow frame rate: %.2f fps", fps);
|
||||
}
|
||||
|
|
|
@ -86,7 +86,9 @@ void OnroadWindow::updateState(const UIState &s) {
|
|||
|
||||
blindSpotLeft = scene.blind_spot_left;
|
||||
blindSpotRight = scene.blind_spot_right;
|
||||
fps = scene.fps;
|
||||
showBlindspot = scene.show_blind_spot && (blindSpotLeft || blindSpotRight);
|
||||
showFPS = scene.show_fps;
|
||||
showSignal = scene.show_signal && (turnSignalLeft || turnSignalRight);
|
||||
showSteering = scene.show_steering;
|
||||
steer = scene.steer;
|
||||
|
@ -94,7 +96,7 @@ void OnroadWindow::updateState(const UIState &s) {
|
|||
turnSignalLeft = scene.turn_signal_left;
|
||||
turnSignalRight = scene.turn_signal_right;
|
||||
|
||||
if (showBlindspot || showSignal || showSteering) {
|
||||
if (showBlindspot || showFPS || showSignal || showSteering) {
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
|
@ -323,4 +325,47 @@ void OnroadWindow::paintEvent(QPaintEvent *event) {
|
|||
p.fillRect(signalRectRight, signalBorderColorRight);
|
||||
}
|
||||
}
|
||||
|
||||
if (showFPS) {
|
||||
qint64 currentMillis = QDateTime::currentMSecsSinceEpoch();
|
||||
static std::queue<std::pair<qint64, float>> fpsQueue;
|
||||
|
||||
static float avgFPS = 0.0;
|
||||
static float maxFPS = 0.0;
|
||||
static float minFPS = 99.9;
|
||||
|
||||
minFPS = std::min(minFPS, fps);
|
||||
maxFPS = std::max(maxFPS, fps);
|
||||
|
||||
fpsQueue.push({currentMillis, fps});
|
||||
|
||||
while (!fpsQueue.empty() && currentMillis - fpsQueue.front().first > 60000) {
|
||||
fpsQueue.pop();
|
||||
}
|
||||
|
||||
if (!fpsQueue.empty()) {
|
||||
float totalFPS = 0.0;
|
||||
for (auto tempQueue = fpsQueue; !tempQueue.empty(); tempQueue.pop()) {
|
||||
totalFPS += tempQueue.front().second;
|
||||
}
|
||||
avgFPS = totalFPS / fpsQueue.size();
|
||||
}
|
||||
|
||||
QString fpsDisplayString = QString("FPS: %1 (%2) | Min: %3 | Max: %4 | Avg: %5")
|
||||
.arg(qRound(fps))
|
||||
.arg(paramsMemory.getInt("CameraFPS"))
|
||||
.arg(qRound(minFPS))
|
||||
.arg(qRound(maxFPS))
|
||||
.arg(qRound(avgFPS));
|
||||
|
||||
p.setFont(InterFont(28, QFont::DemiBold));
|
||||
p.setRenderHint(QPainter::TextAntialiasing);
|
||||
p.setPen(Qt::white);
|
||||
|
||||
int textWidth = p.fontMetrics().horizontalAdvance(fpsDisplayString);
|
||||
int xPos = (rect.width() - textWidth) / 2;
|
||||
int yPos = rect.bottom() - 5;
|
||||
|
||||
p.drawText(xPos, yPos, fpsDisplayString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,13 @@ private:
|
|||
bool blindSpotLeft;
|
||||
bool blindSpotRight;
|
||||
bool showBlindspot;
|
||||
bool showFPS;
|
||||
bool showSignal;
|
||||
bool showSteering;
|
||||
bool turnSignalLeft;
|
||||
bool turnSignalRight;
|
||||
|
||||
float fps;
|
||||
float steer;
|
||||
|
||||
int steeringAngleDeg;
|
||||
|
|
|
@ -342,6 +342,7 @@ void ui_update_frogpilot_params(UIState *s, Params ¶ms) {
|
|||
bool developer_ui = params.getBool("DeveloperUI");
|
||||
bool border_metrics = developer_ui && params.getBool("BorderMetrics");
|
||||
scene.show_blind_spot = border_metrics && params.getBool("BlindSpotMetrics");
|
||||
scene.show_fps = developer_ui && params.getBool("FPSCounter");
|
||||
scene.show_signal = border_metrics && params.getBool("SignalMetrics");
|
||||
scene.show_steering = border_metrics && params.getBool("ShowSteering");
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ typedef struct UIScene {
|
|||
bool show_aol_status_bar;
|
||||
bool show_blind_spot;
|
||||
bool show_cem_status_bar;
|
||||
bool show_fps;
|
||||
bool show_signal;
|
||||
bool show_slc_offset;
|
||||
bool show_slc_offset_ui;
|
||||
|
@ -177,6 +178,8 @@ typedef struct UIScene {
|
|||
bool use_vienna_slc_sign;
|
||||
bool vtsc_controlling_curve;
|
||||
|
||||
double fps;
|
||||
|
||||
float adjusted_cruise;
|
||||
float lane_detection_width;
|
||||
float lane_width_left;
|
||||
|
|
|
@ -960,6 +960,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;
|
||||
|
@ -1003,6 +1006,17 @@ void cameras_run(MultiCameraState *s) {
|
|||
// for debugging
|
||||
//do_exit = do_exit || event_data->u.frame_msg.frame_id > (30*20);
|
||||
|
||||
frameCount++;
|
||||
|
||||
std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now();
|
||||
if (currentTime - startTime >= fpsUpdateInterval) {
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(currentTime - startTime).count();
|
||||
double fps = frameCount / duration;
|
||||
paramsMemory.putIntNonBlocking("CameraFPS", fps / 3);
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue