Skip to content

Commit d79386d

Browse files
committed
[db] recognize log_time_msecs as a time column
1 parent 1fd8154 commit d79386d

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/db_sub_source.cc

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ db_label_source::push_header(const std::string& colstr, int type)
359359

360360
hm.hm_column_size = utf8_string_length(colstr).unwrapOr(colstr.length());
361361
hm.hm_column_type = type;
362-
if (colstr == "log_time" || colstr == "min(log_time)") {
362+
if (colstr == "log_time" || colstr == "min(log_time)"
363+
|| colstr == "log_time_msecs")
364+
{
363365
this->dls_time_column_index = this->dls_headers.size() - 1;
364366
}
365367
if (colstr == "__lnav_style__") {
@@ -371,6 +373,18 @@ db_label_source::push_header(const std::string& colstr, int type)
371373
hm.hm_chart.with_show_state(stacked_bar_chart_base::show_all{});
372374
}
373375

376+
void
377+
db_label_source::update_time_column(const timeval& tv)
378+
{
379+
if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) {
380+
this->dls_time_column_invalidated_at = this->dls_time_column.size();
381+
this->dls_time_column_index = SIZE_MAX;
382+
this->dls_time_column.clear();
383+
} else {
384+
this->dls_time_column.push_back(tv);
385+
}
386+
}
387+
374388
void
375389
db_label_source::update_time_column(const string_fragment& sf)
376390
{
@@ -381,13 +395,7 @@ db_label_source::update_time_column(const string_fragment& sf)
381395
tv.tv_sec = -1;
382396
tv.tv_usec = -1;
383397
}
384-
if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) {
385-
this->dls_time_column_invalidated_at = this->dls_time_column.size();
386-
this->dls_time_column_index = SIZE_MAX;
387-
this->dls_time_column.clear();
388-
} else {
389-
this->dls_time_column.push_back(tv);
390-
}
398+
this->update_time_column(tv);
391399
}
392400

393401
void
@@ -446,9 +454,16 @@ db_label_source::push_column(const column_value_t& sv)
446454
}
447455
cv_sf = sf;
448456
},
449-
[this, &width](int64_t i) {
457+
[this, col, &width](int64_t i) {
450458
width = count_digits(i);
451459
this->dls_cell_container.push_int_cell(i);
460+
if (col == this->dls_time_column_index) {
461+
auto ms = std::chrono::milliseconds{i};
462+
auto us
463+
= std::chrono::duration_cast<std::chrono::microseconds>(ms);
464+
465+
this->update_time_column(to_timeval(us));
466+
}
452467
},
453468
[this, &width](double d) {
454469
char buffer[1];

src/db_sub_source.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public:
117117
std::optional<int64_t> get_cell_as_int64(vis_line_t row, size_t col);
118118
std::optional<double> get_cell_as_double(vis_line_t row, size_t col);
119119

120+
void update_time_column(const timeval& tv);
120121
void update_time_column(const string_fragment& sf);
121122

122123
void reset_user_state();

0 commit comments

Comments
 (0)