Commit 0e465cdb authored by Thiago Santini's avatar Thiago Santini

Starts Performance Monitor Widget

parent 6ad85d0d
...@@ -34,7 +34,9 @@ SOURCES +=\ ...@@ -34,7 +34,9 @@ SOURCES +=\
$${TOP}/src/DataRecorder.cpp \ $${TOP}/src/DataRecorder.cpp \
$${TOP}/src/NetworkStream.cpp \ $${TOP}/src/NetworkStream.cpp \
$${TOP}/src/Reference.cpp \ $${TOP}/src/Reference.cpp \
$${TOP}/src/LogWidget.cpp $${TOP}/src/LogWidget.cpp \
$${TOP}/src/PerformanceMonitor.cpp \
$${TOP}/src/PerformanceMonitorWidget.cpp
HEADERS += \ HEADERS += \
$${TOP}/src/MainWindow.h\ $${TOP}/src/MainWindow.h\
...@@ -58,13 +60,16 @@ HEADERS += \ ...@@ -58,13 +60,16 @@ HEADERS += \
$${TOP}/src/DataRecorder.h \ $${TOP}/src/DataRecorder.h \
$${TOP}/src/NetworkStream.h \ $${TOP}/src/NetworkStream.h \
$${TOP}/src/Reference.h \ $${TOP}/src/Reference.h \
$${TOP}/src/LogWidget.h $${TOP}/src/LogWidget.h \
$${TOP}/src/PerformanceMonitor.h \
$${TOP}/src/PerformanceMonitorWidget.h
FORMS += \ FORMS += \
$${TOP}/src/MainWindow.ui \ $${TOP}/src/MainWindow.ui \
$${TOP}/src/CameraWidget.ui \ $${TOP}/src/CameraWidget.ui \
$${TOP}/src/GazeEstimationWidget.ui \ $${TOP}/src/GazeEstimationWidget.ui \
src/LogWidget.ui $${TOP}/src/LogWidget.ui \
$${TOP}/src/PerformanceMonitorWidget.ui
RESOURCES += \ RESOURCES += \
$${TOP}/resources.qrc $${TOP}/resources.qrc
......
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
<file>icons/EyeRecToo.png</file> <file>icons/EyeRecToo.png</file>
<file>icons/gazeEstimationWidget.png</file> <file>icons/gazeEstimationWidget.png</file>
<file>icons/logWidget.png</file> <file>icons/logWidget.png</file>
<file>icons/performanceMonitorWidget.png</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -37,6 +37,11 @@ CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget *paren ...@@ -37,6 +37,11 @@ CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget *paren
break; break;
} }
// Early enrollment of stages so they are listed in order :-)
gPerformanceMonitor.enrol(id, "Frame Grabber");
gPerformanceMonitor.enrol(id, "Image Processor");
gPerformanceMonitor.enrol(id, "Data Recorder");
setWindowTitle(id + " Widget"); setWindowTitle(id + " Widget");
camera = NULL; camera = NULL;
imageProcessor = NULL; imageProcessor = NULL;
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
using namespace cv; using namespace cv;
DataRecorder::DataRecorder(QString prefix, QString header, QObject *parent) DataRecorder::DataRecorder(QString id, QString header, QObject *parent)
: prefix(prefix), : id(id),
header(header), header(header),
videoWriter(NULL), videoWriter(NULL),
dataFile(NULL), dataFile(NULL),
...@@ -11,6 +11,8 @@ DataRecorder::DataRecorder(QString prefix, QString header, QObject *parent) ...@@ -11,6 +11,8 @@ DataRecorder::DataRecorder(QString prefix, QString header, QObject *parent)
framerate(0), framerate(0),
QObject(parent) QObject(parent)
{ {
if (!id.contains("Journal"))
pmIdx = gPerformanceMonitor.enrol(id, "Data Recorder");
} }
DataRecorder::~DataRecorder() DataRecorder::~DataRecorder()
...@@ -20,7 +22,7 @@ DataRecorder::~DataRecorder() ...@@ -20,7 +22,7 @@ DataRecorder::~DataRecorder()
void DataRecorder::startRecording() void DataRecorder::startRecording()
{ {
QString fileName = prefix + "Data.csv"; QString fileName = id + "Data.csv";
dataFile = new QFile( fileName ); dataFile = new QFile( fileName );
if ( !dataFile->open(QIODevice::WriteOnly) ) { if ( !dataFile->open(QIODevice::WriteOnly) ) {
qWarning() << "Recording failure." << QString("Could not open %1").arg(fileName); qWarning() << "Recording failure." << QString("Could not open %1").arg(fileName);
...@@ -69,6 +71,9 @@ void DataRecorder::newData(FieldData fieldData) ...@@ -69,6 +71,9 @@ void DataRecorder::newData(FieldData fieldData)
void DataRecorder::newData(DataTuple dataTuple) void DataRecorder::newData(DataTuple dataTuple)
{ {
// Note that the Journal data recorder doesn't registered with the
// performance monitor since it's cheap to store its data.
if (dataStream == NULL) if (dataStream == NULL)
return; return;
...@@ -96,7 +101,7 @@ void DataRecorder::storeData(T &data) ...@@ -96,7 +101,7 @@ void DataRecorder::storeData(T &data)
if (firstFrame || splitVideoFile()) { if (firstFrame || splitVideoFile()) {
firstFrame = false; firstFrame = false;
QString fileName = prefix + "-P" + QString::number(videoIdx) + ".avi"; QString fileName = id + "-P" + QString::number(videoIdx) + ".avi";
int codec = videoWriter->fourcc('D', 'I', 'V', 'X'); int codec = videoWriter->fourcc('D', 'I', 'V', 'X');
if (gHasOpenH264) if (gHasOpenH264)
...@@ -116,6 +121,9 @@ void DataRecorder::storeData(T &data) ...@@ -116,6 +121,9 @@ void DataRecorder::storeData(T &data)
if (!gRecording) if (!gRecording)
return; return;
if ( gPerformanceMonitor.shouldDrop(pmIdx, gTimer.elapsed() - data.timestamp, 1000) )
return;
if (videoWriter->isOpened()) if (videoWriter->isOpened())
*videoWriter << data.input; *videoWriter << data.input;
if (dataStream->status() == QTextStream::Ok) if (dataStream->status() == QTextStream::Ok)
......
...@@ -16,7 +16,7 @@ class DataRecorder : public QObject ...@@ -16,7 +16,7 @@ class DataRecorder : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DataRecorder(QString prefix, QString header, QObject *parent = 0); explicit DataRecorder(QString id, QString header, QObject *parent = 0);
~DataRecorder(); ~DataRecorder();
signals: signals:
...@@ -30,7 +30,7 @@ public slots: ...@@ -30,7 +30,7 @@ public slots:
void newData(DataTuple dataTuple); void newData(DataTuple dataTuple);
private: private:
QString prefix; QString id;
QString header; QString header;
QFile *dataFile; QFile *dataFile;
QTextStream *dataStream; QTextStream *dataStream;
...@@ -44,14 +44,16 @@ private: ...@@ -44,14 +44,16 @@ private:
void storeData(T &data); void storeData(T &data);
bool splitVideoFile(); bool splitVideoFile();
double fps; double fps;
unsigned int pmIdx;
}; };
class DataRecorderThread : public QObject class DataRecorderThread : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DataRecorderThread(QString prefix, QString header, QObject *parent = 0) explicit DataRecorderThread(QString id, QString header, QObject *parent = 0)
: prefix(prefix), : id(id),
header(header), header(header),
dataRecorder(NULL), dataRecorder(NULL),
QObject(parent) QObject(parent)
...@@ -76,7 +78,7 @@ signals: ...@@ -76,7 +78,7 @@ signals:
public slots: public slots:
void create() { void create() {
dataRecorder = new DataRecorder(prefix, header, this); dataRecorder = new DataRecorder(id, header, this);
connect(this, SIGNAL(startRecording(double)), connect(this, SIGNAL(startRecording(double)),
dataRecorder, SLOT(startRecording(double)) ); dataRecorder, SLOT(startRecording(double)) );
connect(this, SIGNAL(startRecording()), connect(this, SIGNAL(startRecording()),
...@@ -92,9 +94,8 @@ public slots: ...@@ -92,9 +94,8 @@ public slots:
} }
private: private:
QString prefix; QString id;
QString header; QString header;
}; };
#endif // DATARECORDER_H #endif // DATARECORDER_H
...@@ -22,6 +22,8 @@ EyeImageProcessor::EyeImageProcessor(QString id, QObject *parent) ...@@ -22,6 +22,8 @@ EyeImageProcessor::EyeImageProcessor(QString id, QObject *parent)
#endif #endif
settings = new QSettings(gCfgDir + "/" + id + " ImageProcessor", QSettings::IniFormat); settings = new QSettings(gCfgDir + "/" + id + " ImageProcessor", QSettings::IniFormat);
updateConfig(); updateConfig();
pmIdx = gPerformanceMonitor.enrol(id, "Image Processor");
} }
void EyeImageProcessor::updateConfig() void EyeImageProcessor::updateConfig()
...@@ -50,7 +52,7 @@ void EyeImageProcessor::process(Timestamp timestamp, const Mat &frame) ...@@ -50,7 +52,7 @@ void EyeImageProcessor::process(Timestamp timestamp, const Mat &frame)
Mat prevInput = data.input; Mat prevInput = data.input;
// TODO: parametrize frame drop due to lack of processing power // TODO: parametrize frame drop due to lack of processing power
if (gTimer.elapsed() - timestamp > 50) if ( gPerformanceMonitor.shouldDrop(pmIdx, gTimer.elapsed() - timestamp, 50) )
return; return;
QMutexLocker locker(&cfgMutex); QMutexLocker locker(&cfgMutex);
......
...@@ -278,6 +278,8 @@ private: ...@@ -278,6 +278,8 @@ private:
QPointF sROI, eROI; QPointF sROI, eROI;
PupilDetectionMethod *pupilDetectionMethod; PupilDetectionMethod *pupilDetectionMethod;
unsigned int pmIdx;
}; };
#endif // EYEIMAGEPROCESSOR_H #endif // EYEIMAGEPROCESSOR_H
...@@ -22,6 +22,8 @@ FieldImageProcessor::FieldImageProcessor(QString id, QObject *parent) ...@@ -22,6 +22,8 @@ FieldImageProcessor::FieldImageProcessor(QString id, QObject *parent)
detectorParameters->markerBorderBits = 2; detectorParameters->markerBorderBits = 2;
detectorParameters->minMarkerPerimeterRate = 0.10; // TODO: determine a good value for these based on the fov and maximum detection distance detectorParameters->minMarkerPerimeterRate = 0.10; // TODO: determine a good value for these based on the fov and maximum detection distance
//printMarkers(); // TODO: parametrize me //printMarkers(); // TODO: parametrize me
pmIdx = gPerformanceMonitor.enrol(id, "Image Processor");
} }
void FieldImageProcessor::updateConfig() void FieldImageProcessor::updateConfig()
...@@ -42,7 +44,7 @@ void FieldImageProcessor::process(Timestamp timestamp, const Mat &frame) ...@@ -42,7 +44,7 @@ void FieldImageProcessor::process(Timestamp timestamp, const Mat &frame)
Mat prevInput = data.input; Mat prevInput = data.input;
// TODO: parametrize frame drop due to lack of processing power // TODO: parametrize frame drop due to lack of processing power
if (gTimer.elapsed() - timestamp > 50) if ( gPerformanceMonitor.shouldDrop(pmIdx, gTimer.elapsed() - timestamp, 100) )
return; return;
QMutexLocker locker(&cfgMutex); QMutexLocker locker(&cfgMutex);
......
...@@ -381,6 +381,8 @@ private: ...@@ -381,6 +381,8 @@ private:
cv::Size imageSize, newImageSize; cv::Size imageSize, newImageSize;
bool forceSanitize; bool forceSanitize;
void sanitizeCameraParameters(cv::Size size); void sanitizeCameraParameters(cv::Size size);
unsigned int pmIdx;
}; };
#endif // FIELDIMAGEPROCESSOR_H #endif // FIELDIMAGEPROCESSOR_H
...@@ -18,6 +18,8 @@ FrameGrabber::FrameGrabber(QString id, int code, QObject *parent) : ...@@ -18,6 +18,8 @@ FrameGrabber::FrameGrabber(QString id, int code, QObject *parent) :
watchdog = new QTimer(this); watchdog = new QTimer(this);
connect(watchdog, SIGNAL(timeout()), this, SIGNAL(timedout())); connect(watchdog, SIGNAL(timeout()), this, SIGNAL(timedout()));
watchdog->start(timeoutMs); watchdog->start(timeoutMs);
pmIdx = gPerformanceMonitor.enrol(id, "Frame Grabber");
} }
FrameGrabber::~FrameGrabber() FrameGrabber::~FrameGrabber()
...@@ -108,7 +110,8 @@ bool FrameGrabber::present(const QVideoFrame &frame) ...@@ -108,7 +110,8 @@ bool FrameGrabber::present(const QVideoFrame &frame)
if (success && !cvFrame.empty()) { if (success && !cvFrame.empty()) {
watchdog->start(timeoutMs); watchdog->start(timeoutMs);
emit newFrame(t, cvFrame); emit newFrame(t, cvFrame);
} } else
gPerformanceMonitor.account(pmIdx);
return success; return success;
} }
......
...@@ -45,6 +45,8 @@ private: ...@@ -45,6 +45,8 @@ private:
long unsigned int yuvBufferSize; long unsigned int yuvBufferSize;
bool jpeg2bmp(const QVideoFrame &in, cv::Mat &cvFrame); bool jpeg2bmp(const QVideoFrame &in, cv::Mat &cvFrame);
bool rgb32_2bmp(const QVideoFrame &in, cv::Mat &cvFrame); bool rgb32_2bmp(const QVideoFrame &in, cv::Mat &cvFrame);
unsigned int pmIdx;
}; };
#endif // FRAMEGRABBER_H #endif // FRAMEGRABBER_H
...@@ -108,6 +108,11 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -108,6 +108,11 @@ MainWindow::MainWindow(QWidget *parent) :
networkStream->start(2002); networkStream->start(2002);
connect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)), networkStream, SLOT(push(DataTuple)) ); connect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)), networkStream, SLOT(push(DataTuple)) );
performanceMonitorWidget = new PerformanceMonitorWidget();
performanceMonitorWidget->show();
performanceMonitorWidget->move(cfg.performanceMonitorWidgetPos);
performanceMonitorWidget->resize(cfg.performanceMonitorWidgetSize);
// GUI to Widgets signals // GUI to Widgets signals
connect(this, SIGNAL(startRecording()), connect(this, SIGNAL(startRecording()),
lEyeWidget, SLOT(startRecording()) ); lEyeWidget, SLOT(startRecording()) );
...@@ -159,6 +164,8 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -159,6 +164,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
cfg.fieldWidgetSize = fieldWidget->size(); cfg.fieldWidgetSize = fieldWidget->size();
cfg.gazeEstimationWidgetPos = gazeEstimationWidget->pos(); cfg.gazeEstimationWidgetPos = gazeEstimationWidget->pos();
cfg.gazeEstimationWidgetSize = gazeEstimationWidget->size(); cfg.gazeEstimationWidgetSize = gazeEstimationWidget->size();
cfg.performanceMonitorWidgetPos = performanceMonitorWidget->pos();
cfg.performanceMonitorWidgetSize = performanceMonitorWidget->size();
cfg.workingDirectory = QDir::currentPath(); cfg.workingDirectory = QDir::currentPath();
if (settings) if (settings)
cfg.save(settings); cfg.save(settings);
...@@ -192,6 +199,16 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -192,6 +199,16 @@ void MainWindow::closeEvent(QCloseEvent *event)
if (networkStream) if (networkStream)
networkStream->deleteLater(); networkStream->deleteLater();
gPerformanceMonitor.report();
qInfo() << "Closing Performance Monitor Widget...";
if (performanceMonitorWidget) {
performanceMonitorWidget->close();
performanceMonitorWidget->deleteLater();
performanceMonitorWidget = NULL;
}
qInfo() << "Closing Log Widget..."; qInfo() << "Closing Log Widget...";
if (logWidget) { if (logWidget) {
gLogWidget = NULL; gLogWidget = NULL;
...@@ -411,6 +428,11 @@ void MainWindow::on_log_clicked() ...@@ -411,6 +428,11 @@ void MainWindow::on_log_clicked()
widgetButtonReact(logWidget, ui->log->isChecked()); widgetButtonReact(logWidget, ui->log->isChecked());
} }
void MainWindow::on_performanceMonitor_clicked()
{
widgetButtonReact(performanceMonitorWidget, ui->performanceMonitor->isChecked());
}
void MainWindow::keyPressEvent(QKeyEvent *event) void MainWindow::keyPressEvent(QKeyEvent *event)
{ {
if (event->isAutoRepeat()) if (event->isAutoRepeat())
...@@ -561,3 +583,4 @@ void MainWindow::checkForOpenH264() ...@@ -561,3 +583,4 @@ void MainWindow::checkForOpenH264()
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "Reference.h" #include "Reference.h"
#include "LogWidget.h" #include "LogWidget.h"
#include "PerformanceMonitorWidget.h"
#include "utils.h" #include "utils.h"
...@@ -41,6 +42,8 @@ public: ...@@ -41,6 +42,8 @@ public:
fieldWidgetSize( QSize(320,240) ), fieldWidgetSize( QSize(320,240) ),
gazeEstimationWidgetPos( QPoint(0,0) ), gazeEstimationWidgetPos( QPoint(0,0) ),
gazeEstimationWidgetSize( QSize(100, 100) ), gazeEstimationWidgetSize( QSize(100, 100) ),
performanceMonitorWidgetPos( QPoint(0,0) ),
performanceMonitorWidgetSize( QSize(640, 240)),
workingDirectory("./"), workingDirectory("./"),
showOpenH264Info(true) showOpenH264Info(true)
{} {}
...@@ -57,6 +60,8 @@ public: ...@@ -57,6 +60,8 @@ public:
QSize fieldWidgetSize; QSize fieldWidgetSize;
QPoint gazeEstimationWidgetPos; QPoint gazeEstimationWidgetPos;
QSize gazeEstimationWidgetSize; QSize gazeEstimationWidgetSize;
QPoint performanceMonitorWidgetPos;
QSize performanceMonitorWidgetSize;
QString workingDirectory; QString workingDirectory;
bool showOpenH264Info; bool showOpenH264Info;
...@@ -75,6 +80,8 @@ public: ...@@ -75,6 +80,8 @@ public:
settings->setValue("fieldWidgetSize", fieldWidgetSize); settings->setValue("fieldWidgetSize", fieldWidgetSize);
settings->setValue("gazeEstimationWidgetPos", gazeEstimationWidgetPos); settings->setValue("gazeEstimationWidgetPos", gazeEstimationWidgetPos);
settings->setValue("gazeEstimationWidgetSize", gazeEstimationWidgetSize); settings->setValue("gazeEstimationWidgetSize", gazeEstimationWidgetSize);
settings->setValue("performanceMonitorWidgetPos", performanceMonitorWidgetPos);
settings->setValue("performanceMonitorWidgetSize", performanceMonitorWidgetSize);
settings->setValue("workingDirectory", workingDirectory); settings->setValue("workingDirectory", workingDirectory);
settings->setValue("showOpenH264Info", showOpenH264Info); settings->setValue("showOpenH264Info", showOpenH264Info);
} }
...@@ -94,6 +101,8 @@ public: ...@@ -94,6 +101,8 @@ public:
set(settings, "fieldWidgetSize", fieldWidgetSize); set(settings, "fieldWidgetSize", fieldWidgetSize);
set(settings, "gazeEstimationWidgetPos", gazeEstimationWidgetPos); set(settings, "gazeEstimationWidgetPos", gazeEstimationWidgetPos);
set(settings, "gazeEstimationWidgetSize", gazeEstimationWidgetSize); set(settings, "gazeEstimationWidgetSize", gazeEstimationWidgetSize);
set(settings, "performanceMonitorWidgetPos", performanceMonitorWidgetPos);
set(settings, "performanceMonitorWidgetSize", performanceMonitorWidgetSize);
set(settings, "workingDirectory", workingDirectory); set(settings, "workingDirectory", workingDirectory);
set(settings, "showOpenH264Info", showOpenH264Info); set(settings, "showOpenH264Info", showOpenH264Info);
} }
...@@ -130,6 +139,7 @@ private: ...@@ -130,6 +139,7 @@ private:
DataRecorderThread *journal; DataRecorderThread *journal;
NetworkStream * networkStream; NetworkStream * networkStream;
LogWidget *logWidget; LogWidget *logWidget;
PerformanceMonitorWidget *performanceMonitorWidget;
QElapsedTimer elapsedTime; QElapsedTimer elapsedTime;
int elapsedTimeUpdateTimer; int elapsedTimeUpdateTimer;
...@@ -163,6 +173,7 @@ private slots: ...@@ -163,6 +173,7 @@ private slots:
void showReferencesDialog(); void showReferencesDialog();
void showAboutDialog(); void showAboutDialog();
void on_log_clicked(); void on_log_clicked();
void on_performanceMonitor_clicked();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>319</width> <width>252</width>
<height>371</height> <height>444</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>3</number> <number>3</number>
</property> </property>
...@@ -383,10 +389,16 @@ ...@@ -383,10 +389,16 @@
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QGroupBox" name="widgetBox"> <widget class="QGroupBox" name="widgetBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>75</height> <height>130</height>
</size> </size>
</property> </property>
<property name="title"> <property name="title">
...@@ -443,8 +455,8 @@ ...@@ -443,8 +455,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="2">
<widget class="QPushButton" name="leftEyeCam"> <widget class="QPushButton" name="fieldCam">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -453,7 +465,7 @@ ...@@ -453,7 +465,7 @@