From a4deaa1e8bd811902ae93dac396fda35664b0506 Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Mon, 2 May 2016 22:59:04 -0700 Subject: [PATCH] [spectro] log_time must be in ascending order --- src/db_sub_source.hh | 8 +++++++- src/lnav_commands.cc | 2 +- src/lnav_util.hh | 6 ++++++ test/test_sql.sh | 11 ++++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/db_sub_source.hh b/src/db_sub_source.hh index cd425b27..f7df7b6b 100644 --- a/src/db_sub_source.hh +++ b/src/db_sub_source.hh @@ -201,7 +201,13 @@ public: tv.tv_sec = -1; tv.tv_usec = -1; } - this->dls_time_column.push_back(tv); + if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) { + this->dls_time_column_index = -1; + this->dls_time_column.clear(); + } + else { + this->dls_time_column.push_back(tv); + } } this->dls_rows.back().push_back(colstr); diff --git a/src/lnav_commands.cc b/src/lnav_commands.cc index e1147fba..30a0434f 100644 --- a/src/lnav_commands.cc +++ b/src/lnav_commands.cc @@ -2606,7 +2606,7 @@ public: this->dsvs_column_index = dls.column_name_to_index(this->dsvs_colname); if (!dls.has_log_time_column()) { - this->dsvs_error_msg = "no 'log_time' column found, unable to create spectrogram"; + this->dsvs_error_msg = "no 'log_time' column found or not in ascending order, unable to create spectrogram"; return; } diff --git a/src/lnav_util.hh b/src/lnav_util.hh index df646733..fdf3b6b6 100644 --- a/src/lnav_util.hh +++ b/src/lnav_util.hh @@ -258,6 +258,12 @@ bool operator<(time_t left, const struct timeval &right) { return left < right.tv_sec; }; +inline +bool operator<(const struct timeval &left, const struct timeval &right) { + return left.tv_sec < right.tv_sec || + ((left.tv_sec == right.tv_usec) && (left.tv_usec < right.tv_usec)); +}; + struct date_time_scanner { date_time_scanner() : dts_keep_base_tz(false), dts_local_time(false), diff --git a/test/test_sql.sh b/test/test_sql.sh index db1ae70e..4f99431c 100644 --- a/test/test_sql.sh +++ b/test/test_sql.sh @@ -77,7 +77,7 @@ run_test ${lnav_test} -n \ ${test_dir}/logfile_access_log.0 check_error_output "spectrogram worked without log_time?" <