fix(cpn): log viewer performance (#7205)
This commit is contained in:
@@ -590,40 +590,56 @@ void LogsDialog::fileOpen()
|
|||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
g.logDir(fileName);
|
g.logDir(fileName);
|
||||||
ui->FileName_LE->setText(fileName);
|
ui->FileName_LE->setText(fileName);
|
||||||
|
//Stopwatch s1("LogViewer");
|
||||||
|
//s1.report("Start");
|
||||||
|
|
||||||
if (cvsFileParse()) {
|
if (cvsFileParse()) {
|
||||||
ui->FieldsTW->clear();
|
ui->FieldsTW->clear();
|
||||||
ui->logTable->clear();
|
ui->logTable->clear();
|
||||||
ui->FieldsTW->setShowGrid(false);
|
ui->FieldsTW->setShowGrid(false);
|
||||||
ui->FieldsTW->setContentsMargins(0,0,0,0);
|
ui->FieldsTW->setContentsMargins(0, 0, 0, 0);
|
||||||
ui->FieldsTW->setRowCount(csvlog.at(0).count()-2);
|
ui->FieldsTW->setRowCount(csvlog.at(0).count() - 2);
|
||||||
ui->FieldsTW->setColumnCount(1);
|
ui->FieldsTW->setColumnCount(1);
|
||||||
ui->FieldsTW->setHorizontalHeaderLabels(QStringList(tr("Available fields")));
|
ui->FieldsTW->setHorizontalHeaderLabels(QStringList(tr("Available fields")));
|
||||||
ui->logTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
ui->logTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
for (int i=2; i<csvlog.at(0).count(); i++) {
|
|
||||||
|
for (int i = 3; i < csvlog.at(0).count(); i++) {
|
||||||
QTableWidgetItem* item= new QTableWidgetItem(csvlog.at(0).at(i));
|
QTableWidgetItem* item= new QTableWidgetItem(csvlog.at(0).at(i));
|
||||||
ui->FieldsTW->setItem(i-2, 0, item);
|
ui->FieldsTW->setItem(i - 3, 0, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->FieldsTW->resizeRowsToContents();
|
ui->FieldsTW->resizeRowsToContents();
|
||||||
ui->logTable->setColumnCount(csvlog.at(0).count());
|
ui->logTable->setColumnCount(csvlog.at(0).count());
|
||||||
ui->logTable->setRowCount(csvlog.count()-1);
|
ui->logTable->setRowCount(csvlog.count() - 1);
|
||||||
ui->logTable->setHorizontalHeaderLabels(csvlog.at(0));
|
ui->logTable->setHorizontalHeaderLabels(csvlog.at(0));
|
||||||
|
//s1.report("Load fields");
|
||||||
|
|
||||||
QAbstractItemModel *model = ui->logTable->model();
|
QAbstractItemModel *model = ui->logTable->model();
|
||||||
for (int i=1; i<csvlog.count(); i++) {
|
for (int i = 1; i < csvlog.count(); i++) {
|
||||||
for (int j=0; j<csvlog.at(0).count(); j++) {
|
for (int j = 0; j < csvlog.at(0).count(); j++) {
|
||||||
model->setData(model->index(i - 1, j, QModelIndex()), csvlog.at(i).at(j));
|
model->setData(model->index(i - 1, j, QModelIndex()), csvlog.at(i).at(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s1.report("Load data model");
|
||||||
|
|
||||||
ui->logTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
ui->logTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
QVarLengthArray<int> sizes;
|
QVarLengthArray<int> sizes;
|
||||||
|
|
||||||
for (int i = 0; i < ui->logTable->columnCount(); i++) {
|
for (int i = 0; i < ui->logTable->columnCount(); i++) {
|
||||||
sizes.append(ui->logTable->columnWidth(i));
|
sizes.append(ui->logTable->columnWidth(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->logTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
|
ui->logTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
|
||||||
|
|
||||||
for (int i = 0; i < ui->logTable->columnCount(); i++) {
|
for (int i = 0; i < ui->logTable->columnCount(); i++) {
|
||||||
ui->logTable->setColumnWidth(i, sizes.at(i));
|
if (i == 0)
|
||||||
|
ui->logTable->setColumnHidden(i, true); // hide MSecsSinceEpoch column
|
||||||
|
else
|
||||||
|
ui->logTable->setColumnWidth(i, sizes.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s1.report("Adjust headers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -672,6 +688,8 @@ void LogsDialog::saveSession()
|
|||||||
|
|
||||||
bool LogsDialog::cvsFileParse()
|
bool LogsDialog::cvsFileParse()
|
||||||
{
|
{
|
||||||
|
//Stopwatch s("Parse");
|
||||||
|
|
||||||
QFile file(ui->FileName_LE->text());
|
QFile file(ui->FileName_LE->text());
|
||||||
int errors=0;
|
int errors=0;
|
||||||
int lines=-1;
|
int lines=-1;
|
||||||
@@ -696,13 +714,39 @@ bool LogsDialog::cvsFileParse()
|
|||||||
while (!file.atEnd()) {
|
while (!file.atEnd()) {
|
||||||
QString line = file.readLine().trimmed();
|
QString line = file.readLine().trimmed();
|
||||||
QStringList columns = line.split(',');
|
QStringList columns = line.split(',');
|
||||||
if (numfields==-1) {
|
|
||||||
|
if (numfields == -1) {
|
||||||
numfields=columns.count();
|
numfields=columns.count();
|
||||||
}
|
}
|
||||||
if (columns.count()==numfields) {
|
|
||||||
csvlog.append(columns);
|
if (columns.count() == numfields) {
|
||||||
}
|
if (lines == -1) {
|
||||||
else {
|
csvlog.append(QStringList("MSecsSinceEpoch") << columns);
|
||||||
|
} else {
|
||||||
|
// Qt v6.2 onwards QDateTime::fromString() is very slow
|
||||||
|
QStringList sDate = columns.at(0).split("-");
|
||||||
|
QStringList sTime = columns.at(1).split(":");
|
||||||
|
QStringList sSecs;
|
||||||
|
|
||||||
|
if (sTime.count() == 3) {
|
||||||
|
sSecs = sTime.at(2).split(".");
|
||||||
|
|
||||||
|
if (sSecs.count() == 1)
|
||||||
|
sSecs.append("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sDate.count() == 3 && sTime.count() == 3 && sSecs.count() == 2) {
|
||||||
|
QDate d(sDate.at(0).toInt(), sDate.at(1).toInt(), sDate.at(2).toInt());
|
||||||
|
QTime t(sTime.at(0).toInt(), sTime.at(1).toInt(), sSecs.at(0).toInt(), sSecs.at(1).toInt());
|
||||||
|
QDateTime dt(d, t);
|
||||||
|
//qDebug() << dt << dt.toString() << dt.toMSecsSinceEpoch() << QDateTime::fromMSecsSinceEpoch(dt.toMSecsSinceEpoch());
|
||||||
|
csvlog.append(QStringList(QString::number(dt.toMSecsSinceEpoch())) << columns);
|
||||||
|
//qDebug() << csvlog.at(csvlog.count() - 1);
|
||||||
|
} else {
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
lines++;
|
lines++;
|
||||||
@@ -722,10 +766,14 @@ bool LogsDialog::cvsFileParse()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Data loaded");
|
||||||
|
|
||||||
plotLock = true;
|
plotLock = true;
|
||||||
setFlightSessions();
|
setFlightSessions();
|
||||||
plotLock = false;
|
plotLock = false;
|
||||||
|
|
||||||
|
//s.report("Sessions loaded");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -736,10 +784,8 @@ struct FlightSession {
|
|||||||
|
|
||||||
QDateTime LogsDialog::getRecordTimeStamp(int index)
|
QDateTime LogsDialog::getRecordTimeStamp(int index)
|
||||||
{
|
{
|
||||||
QString tstamp = csvlog.at(index).at(0) + " " + csvlog.at(index).at(1);
|
//qDebug() << csvlog.at(index).at(0).toLongLong() << QDateTime::fromMSecsSinceEpoch(csvlog.at(index).at(0).toLongLong());
|
||||||
if (csvlog.at(index).at(1).contains("."))
|
return QDateTime::fromMSecsSinceEpoch(csvlog.at(index).at(0).toLongLong());
|
||||||
return QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss.zzz");
|
|
||||||
return QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LogsDialog::generateDuration(const QDateTime & start, const QDateTime & end)
|
QString LogsDialog::generateDuration(const QDateTime & start, const QDateTime & end)
|
||||||
@@ -756,6 +802,8 @@ QString LogsDialog::generateDuration(const QDateTime & start, const QDateTime &
|
|||||||
|
|
||||||
void LogsDialog::setFlightSessions()
|
void LogsDialog::setFlightSessions()
|
||||||
{
|
{
|
||||||
|
//Stopwatch s("Sessions");
|
||||||
|
|
||||||
ui->sessions_CB->clear();
|
ui->sessions_CB->clear();
|
||||||
ui->SaveSession_PB->setEnabled(false);
|
ui->SaveSession_PB->setEnabled(false);
|
||||||
|
|
||||||
@@ -775,24 +823,28 @@ void LogsDialog::setFlightSessions()
|
|||||||
}
|
}
|
||||||
sessions.push_back(n-1);
|
sessions.push_back(n-1);
|
||||||
|
|
||||||
|
//s.report("Breaks found");
|
||||||
|
|
||||||
//now construct a list of sessions with their times
|
//now construct a list of sessions with their times
|
||||||
//total time
|
//total time
|
||||||
int noSesions = sessions.size()-1;
|
int noSesions = sessions.size() - 1;
|
||||||
QString label = QString("%1 ").arg(noSesions);
|
QString label = QString("%1 ").arg(noSesions);
|
||||||
label += tr(noSesions > 1 ? "sessions" : "session");
|
label += tr(noSesions > 1 ? "sessions" : "session");
|
||||||
label += " <" + tr("time span") + generateDuration(getRecordTimeStamp(1), getRecordTimeStamp(n-1)) + ">";
|
label += " <" + tr("time span ") + generateDuration(getRecordTimeStamp(1), getRecordTimeStamp(n - 1)) + ">";
|
||||||
ui->sessions_CB->addItem(label);
|
ui->sessions_CB->addItem(label);
|
||||||
|
|
||||||
// add individual sessions
|
// add individual sessions
|
||||||
if (sessions.size() > 2) {
|
if (sessions.size() > 2) {
|
||||||
for (int i = 1; i < sessions.size(); i++) {
|
for (int i = 1; i < sessions.size(); i++) {
|
||||||
QDateTime sessionStart = getRecordTimeStamp(sessions.at(i-1)+1);
|
QDateTime sessionStart = getRecordTimeStamp(sessions.at(i - 1) + 1);
|
||||||
QDateTime sessionEnd = getRecordTimeStamp(sessions.at(i));
|
QDateTime sessionEnd = getRecordTimeStamp(sessions.at(i));
|
||||||
QString label = sessionStart.toString("HH:mm:ss") + " <" + tr("duration ") + generateDuration(sessionStart, sessionEnd) + ">";
|
QString label = sessionStart.toString("HH:mm:ss") + " <" + tr("duration ") + generateDuration(sessionStart, sessionEnd) + ">";
|
||||||
ui->sessions_CB->addItem(label, sessions.at(i-1));
|
ui->sessions_CB->addItem(label, sessions.at(i - 1));
|
||||||
// qDebug() << "added label" << label << sessions.at(i-1);
|
// qDebug() << "added label" << label << sessions.at(i-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("List created");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsDialog::sessionsCurrentIndexChanged(int index)
|
void LogsDialog::sessionsCurrentIndexChanged(int index)
|
||||||
@@ -881,6 +933,7 @@ void LogsDialog::plotLogs()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Stopwatch s("Plot");
|
||||||
plotsCollection plots;
|
plotsCollection plots;
|
||||||
|
|
||||||
QModelIndexList selection = ui->logTable->selectionModel()->selectedRows();
|
QModelIndexList selection = ui->logTable->selectionModel()->selectedRows();
|
||||||
@@ -900,12 +953,14 @@ void LogsDialog::plotLogs()
|
|||||||
rowCount = ui->logTable->rowCount();
|
rowCount = ui->logTable->rowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Row count");
|
||||||
|
|
||||||
plots.min_x = INVALID_MIN;
|
plots.min_x = INVALID_MIN;
|
||||||
plots.max_x = 0;
|
plots.max_x = 0;
|
||||||
|
|
||||||
foreach (QTableWidgetItem *plot, ui->FieldsTW->selectedItems()) {
|
foreach (QTableWidgetItem *plot, ui->FieldsTW->selectedItems()) {
|
||||||
coords_t plotCoords;
|
coords_t plotCoords;
|
||||||
int plotColumn = plot->row() + 2; // Date and Time first
|
int plotColumn = plot->row() + 3; // Epoch, Date and Time first
|
||||||
|
|
||||||
plotCoords.min_y = INVALID_MIN;
|
plotCoords.min_y = INVALID_MIN;
|
||||||
plotCoords.max_y = INVALID_MAX;
|
plotCoords.max_y = INVALID_MAX;
|
||||||
@@ -916,16 +971,14 @@ void LogsDialog::plotLogs()
|
|||||||
QTableWidgetItem *logValue;
|
QTableWidgetItem *logValue;
|
||||||
double y;
|
double y;
|
||||||
double time;
|
double time;
|
||||||
QString time_str;
|
QDateTime datetime;
|
||||||
|
|
||||||
if (hasLogSelection) {
|
if (hasLogSelection) {
|
||||||
logValue = ui->logTable->item(selectedRows.at(row), plotColumn);
|
logValue = ui->logTable->item(selectedRows.at(row), plotColumn);
|
||||||
time_str = ui->logTable->item(selectedRows.at(row), 0)->text() +
|
datetime = QDateTime::fromMSecsSinceEpoch(ui->logTable->item(selectedRows.at(row), 0)->text().toLongLong());
|
||||||
QString(" ") + ui->logTable->item(selectedRows.at(row), 1)->text();
|
|
||||||
} else {
|
} else {
|
||||||
logValue = ui->logTable->item(row, plotColumn);
|
logValue = ui->logTable->item(row, plotColumn);
|
||||||
time_str = ui->logTable->item(row, 0)->text() + QString(" ") +
|
datetime = QDateTime::fromMSecsSinceEpoch(ui->logTable->item(row, 0)->text().toLongLong());
|
||||||
ui->logTable->item(row, 1)->text();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
y = logValue->text().toDouble();
|
y = logValue->text().toDouble();
|
||||||
@@ -934,8 +987,7 @@ void LogsDialog::plotLogs()
|
|||||||
if (plotCoords.min_y > y) plotCoords.min_y = y;
|
if (plotCoords.min_y > y) plotCoords.min_y = y;
|
||||||
if (plotCoords.max_y < y) plotCoords.max_y = y;
|
if (plotCoords.max_y < y) plotCoords.max_y = y;
|
||||||
|
|
||||||
QString fmt(time_str.contains('.') ? "yyyy-MM-dd HH:mm:ss.zzz" :"yyyy-MM-dd HH:mm:ss");
|
time = QCPAxisTickerDateTime::dateTimeToKey(datetime);
|
||||||
time = QCPAxisTickerDateTime::dateTimeToKey(QDateTime::fromString(time_str, fmt));
|
|
||||||
|
|
||||||
plotCoords.x.push_back(time);
|
plotCoords.x.push_back(time);
|
||||||
|
|
||||||
@@ -955,6 +1007,8 @@ void LogsDialog::plotLogs()
|
|||||||
plots.coords.append(plotCoords);
|
plots.coords.append(plotCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Cords");
|
||||||
|
|
||||||
yAxesRanges[firstLeft].min = plots.coords.at(0).min_y;
|
yAxesRanges[firstLeft].min = plots.coords.at(0).min_y;
|
||||||
yAxesRanges[firstLeft].max = plots.coords.at(0).max_y;
|
yAxesRanges[firstLeft].max = plots.coords.at(0).max_y;
|
||||||
for (int i = firstRight; i < AXES_LIMIT; i++) {
|
for (int i = firstRight; i < AXES_LIMIT; i++) {
|
||||||
@@ -1009,6 +1063,8 @@ void LogsDialog::plotLogs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Check too many ranges");
|
||||||
|
|
||||||
if (plots.tooManyRanges) {
|
if (plots.tooManyRanges) {
|
||||||
yAxesRanges[firstLeft].max = 101;
|
yAxesRanges[firstLeft].max = 101;
|
||||||
yAxesRanges[firstLeft].min = -1;
|
yAxesRanges[firstLeft].min = -1;
|
||||||
@@ -1038,6 +1094,8 @@ void LogsDialog::plotLogs()
|
|||||||
|
|
||||||
removeAllGraphs();
|
removeAllGraphs();
|
||||||
|
|
||||||
|
//s.report("Remove existing graphs");
|
||||||
|
|
||||||
axisRect->axis(QCPAxis::atBottom)->setRange(plots.min_x, plots.max_x);
|
axisRect->axis(QCPAxis::atBottom)->setRange(plots.min_x, plots.max_x);
|
||||||
if (useCommonAxes) {
|
if (useCommonAxes) {
|
||||||
auto [min, max] = this->GetMinMaxY();
|
auto [min, max] = this->GetMinMaxY();
|
||||||
@@ -1072,6 +1130,8 @@ void LogsDialog::plotLogs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Set axis");
|
||||||
|
|
||||||
for (int i = 0; i < plots.coords.size(); i++) {
|
for (int i = 0; i < plots.coords.size(); i++) {
|
||||||
switch (plots.coords[i].yaxis) {
|
switch (plots.coords[i].yaxis) {
|
||||||
case firstLeft:
|
case firstLeft:
|
||||||
@@ -1113,6 +1173,8 @@ void LogsDialog::plotLogs()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Legend");
|
||||||
|
|
||||||
ui->customPlot->graph(i)->setData(plots.coords.at(i).x,
|
ui->customPlot->graph(i)->setData(plots.coords.at(i).x,
|
||||||
plots.coords.at(i).y);
|
plots.coords.at(i).y);
|
||||||
pen.setColor(colors.at(i % colors.size()));
|
pen.setColor(colors.at(i % colors.size()));
|
||||||
@@ -1130,8 +1192,12 @@ void LogsDialog::plotLogs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//s.report("Set graph");
|
||||||
|
|
||||||
ui->customPlot->legend->setVisible(true);
|
ui->customPlot->legend->setVisible(true);
|
||||||
ui->customPlot->replot();
|
ui->customPlot->replot();
|
||||||
|
|
||||||
|
//s.report("Refresh graph");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsDialog::yAxisChangeRanges(QCPRange range)
|
void LogsDialog::yAxisChangeRanges(QCPRange range)
|
||||||
|
|||||||
Reference in New Issue
Block a user