Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ set(SOURCES
)

set(HEADERS
include/framepacer.h
include/timingstats.h
include/mainwindow.h
include/glwidget.h
include/graphics.h
Expand Down Expand Up @@ -343,6 +345,13 @@ if(BUILD_TESTING)
set_property(TARGET grSim_rendering_test APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--wrap=glBegin")
endif()
add_test(NAME render_capture_measurements_regression COMMAND grSim_rendering_test --profile-captures)
set_tests_properties(render_capture_measurements_regression PROPERTIES
TIMEOUT 15 LABELS "opengl" ENVIRONMENT "GRSIM_PROFILE_RENDERING=1")
if(UNIX AND NOT APPLE)
set_tests_properties(render_capture_measurements_regression PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=xcb;LIBGL_ALWAYS_SOFTWARE=1;GRSIM_PROFILE_RENDERING=1")
endif()
add_test(NAME rendering_regression COMMAND grSim_rendering_test)
set_tests_properties(rendering_regression PROPERTIES TIMEOUT 30 LABELS "opengl")
if(UNIX AND NOT APPLE)
Expand All @@ -353,6 +362,21 @@ if(BUILD_TESTING)
ENVIRONMENT "QT_QPA_PLATFORM=xcb;LIBGL_ALWAYS_SOFTWARE=1;QT_SCALE_FACTOR=2"
TIMEOUT 30 LABELS "opengl")
endif()
add_test(NAME frame_schedule_regression COMMAND grSim_timing_test --schedule)
set_tests_properties(frame_schedule_regression PROPERTIES TIMEOUT 5)
add_test(NAME render_cadence_regression COMMAND grSim_timing_test --cadence)
set_tests_properties(render_cadence_regression PROPERTIES TIMEOUT 15 LABELS "opengl")
if(UNIX AND NOT APPLE)
set_tests_properties(render_cadence_regression PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=xcb;LIBGL_ALWAYS_SOFTWARE=1")
endif()
add_test(NAME render_measurements_regression COMMAND grSim_timing_test --cadence)
set_tests_properties(render_measurements_regression PROPERTIES
TIMEOUT 15 LABELS "opengl" ENVIRONMENT "GRSIM_PROFILE_RENDERING=1")
if(UNIX AND NOT APPLE)
set_tests_properties(render_measurements_regression PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=xcb;LIBGL_ALWAYS_SOFTWARE=1;GRSIM_PROFILE_RENDERING=1")
endif()
add_test(NAME timing_rendering_regression COMMAND grSim_timing_test --rendering)
set_tests_properties(timing_rendering_regression PROPERTIES TIMEOUT 30 LABELS "opengl")
if(UNIX AND NOT APPLE)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ Kazunori Kimura and Jeremy Feltracco and Kenta Sato and Atousa Ahsani},
```


Hover over the Render/Sim status to inspect recent frame intervals, drawing and
swap times, simulation tick times and physics backlog. FPS counts submitted
window frames, excluding screenshots; the display compositor controls presentation.
The 60 FPS cap uses fixed deadlines and keeps showing the latest completed scene
during physics lag.

For optional GPU timing, launch with `GRSIM_PROFILE_RENDERING=1`. Results are
collected asynchronously when the graphics context supports timer queries; the
default leaves GPU queries disabled. CPU timings and bounded recent histories
remain available in either mode.

The `grSim_replay` developer executable records a fresh physics world's complete
settings, initial body states, random seed and accepted protocol commands by
simulation tick. Replay runs without rendering or wall-clock command scheduling:
Expand Down
31 changes: 31 additions & 0 deletions include/framepacer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FRAMEPACER_H
#define FRAMEPACER_H

#include <QtGlobal>
#include <algorithm>
#include <cmath>

// Deadlines stay on the original time line. Late frames are skipped rather
// than queued, and integer-millisecond timer rounding never accumulates.
class FramePacer {
public:
void reset(qint64 now, double fps)
{
if (!std::isfinite(fps) || fps <= 0) fps = 60;
period = 1e9 / std::max(1.0, std::min(1000.0, fps));
next = double(now) + period;
}
bool due(qint64 now) const { return double(now) >= next; }
void advance(qint64 now)
{
if (due(now)) next += (std::floor((double(now) - next) / period) + 1) * period;
}
int delayMilliseconds(qint64 now) const
{
return std::max(1, std::min(1000, int(std::ceil((next - double(now)) / 1e6))));
}
private:
double period = 1e9 / 60.0, next = 0;
};

#endif
24 changes: 24 additions & 0 deletions include/glwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)
#define GL_SILENCE_DEPRECATION
#include <QGLWidget>
#include <QGLFramebufferObject>
#include <QOpenGLTimerQuery>
#include <QOpenGLContext>
#include <QPointer>
#include <memory>
#include "timingstats.h"
#include <QLabel>
#include <QFrame>
#include "simulation.h"
Expand Down Expand Up @@ -84,6 +89,7 @@ class GLWidget : public QGLWidget {
QMenu *cameraMenu;
int Current_robot,Current_team;
int lockedIndex;
FrameTimings frameTimings() const;
bool ctrl,alt,kickingball,altTrigger;
bool chiping;
double kickpower, chipAngle;
Expand All @@ -107,11 +113,13 @@ public slots:
void lockCameraToBall();
signals:
void frameRendered();
void frameSubmitted();
void clicked();
void selectedRobot();
void closeSignal(bool);
void robotTurnedOnOff(int,bool);
protected:
void paintEvent(QPaintEvent* event) override;
virtual bool hasFramebufferObjects() const;
virtual bool hasFramebufferBlit() const;
void resizeEvent(QResizeEvent* event) override;
Expand All @@ -134,6 +142,22 @@ public slots:
SceneRenderer renderer;
QString graphicsRenderer, graphicsVendor, graphicsVersion;
bool softwareRendering = false;
TimingWindow intervalTimings, sceneTimings, labelTimings, paintTimings, gpuTimings;
QElapsedTimer frameClock;
qint64 previousFrame = -1;
quint64 submittedFrames = 0;
bool gpuTimingRequested = false, gpuTimingSupported = false;
bool gpuTimingInitialized = false, paintingWindow = false;
QPointer<QOpenGLContext> gpuContext;
QPointer<QObject> gpuSurfaceOwner;
QSurface* gpuSurface = nullptr;
QMetaObject::Connection gpuCleanupConnection;
void initializeGpuTiming();
void cleanupGpuTiming();
std::array<std::unique_ptr<QOpenGLTimerQuery>, 4> gpuQueries;
std::array<bool, 4> gpuPending{{false, false, false, false}};
int activeGpuQuery = -1;

QWidget* lagWarning;
bool showCursor = false;
double cursorRadius = 0;
Expand Down
4 changes: 3 additions & 1 deletion include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)

#include <QMdiArea>
#include <QElapsedTimer>
#include "framepacer.h"

#include <QLabel>

Expand Down Expand Up @@ -74,10 +75,11 @@ public slots:

int robotIndex(int robot,int team);
private:
int getRenderInterval();
void updateGraphicsDeviceStatus();
SimulationController* simulation;
QTimer *renderTimer;
QElapsedTimer renderClock;
FramePacer framePacer;
QTimer *uiTimer;
GLWidget *glwidget;

Expand Down
3 changes: 3 additions & 0 deletions include/scenesnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>
#include <QtGlobal>
#include "simulationsettings.h"
#include "timingstats.h"

enum class PrimitiveKind { None, Sphere, Box, Cylinder, Ground };

Expand Down Expand Up @@ -42,6 +43,8 @@ struct SceneSnapshot {
std::vector<RobotSnapshot> robots;
std::array<double, 3> ballPosition{{0, 0, 0}};
unsigned odeHelpers = 0;
TimingSummary stepTimings;
double snapshotMs = 0;
};

using SceneSnapshotPtr = std::shared_ptr<const SceneSnapshot>;
Expand Down
2 changes: 2 additions & 0 deletions include/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private slots:
int stepsThisSecond = 0;
bool initialized = false;
LagMonitor lag;
TimingWindow stepTimings;
TimingSummary recentStepTimings;
};

// GUI-facing interface. All operations are queued; only snapshots cross back.
Expand Down
49 changes: 49 additions & 0 deletions include/timingstats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef TIMINGSTATS_H
#define TIMINGSTATS_H

#include <array>
#include <algorithm>
#include <cmath>
#include <cstdint>

struct TimingSummary {
unsigned samples = 0;
double medianMs = 0, p95Ms = 0, p99Ms = 0, maximumMs = 0;
};

// Bounded recent history; recording never allocates or sorts. Summarize only
// when a consumer needs diagnostics, outside the drawing/stepping hot paths.
class TimingWindow {
public:
void add(double milliseconds)
{
if (!std::isfinite(milliseconds) || milliseconds < 0) return;
values[next] = milliseconds;
next = (next + 1) % values.size();
count = std::min(count + 1, unsigned(values.size()));
}
TimingSummary summary() const
{
TimingSummary result;
result.samples = count;
if (!count) return result;
auto sorted = values;
std::sort(sorted.begin(), sorted.begin() + count);
result.medianMs = sorted[(count - 1) / 2];
result.p95Ms = sorted[unsigned(std::ceil(count * 0.95)) - 1];
result.p99Ms = sorted[unsigned(std::ceil(count * 0.99)) - 1];
result.maximumMs = sorted[count - 1];
return result;
}
private:
std::array<double, 240> values{};
unsigned count = 0, next = 0;
};

struct FrameTimings {
TimingSummary interval, scene, labels, paintAndSwap, gpu;
bool gpuRequested = false, gpuSupported = false;
std::uint64_t frames = 0;
};

#endif
Loading
Loading