Skip to content

Commit 0951f3d

Browse files
committed
[all_opids] add description to opids vtable
Related to #1552
1 parent 4bd314c commit 0951f3d

20 files changed

Lines changed: 263 additions & 70 deletions

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Features:
3636
matches a breakpoint.
3737
* The `all_opids` and `all_thread_ids` virtual tables
3838
have been added to make it simple to discover all of
39-
the operations and threads across all log files.
39+
the operations and threads across all log files. The
40+
`all_opids` table also supports setting a description
41+
for an operation using through an `UPDATE`.
4042
* The `:xopen` command will now open text files in an
4143
external editor. To open the file at a particular
4244
line/column, add a URL fragment of the form

docs/source/sqltab.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ The :code:`all_logs` table lets you query the format derived from the **lnav**
281281
log message parser that is used to automatically extract data, see
282282
:ref:`data-ext` for more details.
283283

284+
all_opids
285+
---------
286+
287+
The :code:`all_opids` table contains information about all opids that were
288+
found in the log files or set via the :code:`log_opid` column on the log
289+
vtables. The information in this table is the same as available through the
290+
:ref:`TIMELINE<timeline>` view. The :code:`description` column can be
291+
:code:`SET` in an :code:`UPDATE` statement to customize the description
292+
shown in the timeline.
293+
284294
lnav_focused_msg
285295
----------------
286296

src/all_ids_vtabs.cc

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "base/itertools.hh"
3939
#include "base/time_util.hh"
4040
#include "file_collection.hh"
41+
#include "log_format.hh"
4142
#include "logfile.hh"
4243
#include "robin_hood/robin_hood.h"
4344
#include "vtab_module.hh"
@@ -52,14 +53,16 @@ CREATE TABLE all_opids (
5253
latest DATETIME, -- The latest time this ID was seen
5354
errors INTEGER, -- The number of error messages associated with this ID
5455
warnings INTEGER, -- The number of warning messages associated with this ID
55-
total INTEGER -- The total number of messages associated with this ID
56+
total INTEGER, -- The total number of messages associated with this ID
57+
description TEXT -- A description of the operation
5658
);
5759
)";
5860

5961
struct cursor {
6062
struct opid_time_pair {
6163
std::string otp_opid;
6264
opid_time_range otp_range;
65+
std::string otp_description;
6366

6467
bool operator<(const opid_time_pair& rhs) const
6568
{
@@ -84,11 +87,31 @@ CREATE TABLE all_opids (
8487
auto key_str = key.to_string();
8588
auto gather_iter = gather_map.find(key_str);
8689
if (gather_iter == gather_map.end()) {
87-
gather_map[key_str].otp_opid = key_str;
88-
gather_map[key_str].otp_range = om;
90+
auto emplace_res = gather_map.emplace(
91+
key_str, opid_time_pair{key_str, om});
92+
gather_iter = emplace_res.first;
8993
} else {
9094
gather_iter->second.otp_range |= om;
9195
}
96+
if (gather_iter->second.otp_description.empty()) {
97+
auto format = lf->get_format();
98+
if (om.otr_description.lod_id.has_value()) {
99+
auto desc_iter
100+
= format->lf_opid_description_def->find(
101+
om.otr_description.lod_id.value());
102+
if (desc_iter
103+
!= format->lf_opid_description_def->end())
104+
{
105+
gather_iter->second.otp_description
106+
= desc_iter->second.to_string(
107+
om.otr_description.lod_elements);
108+
}
109+
} else if (!om.otr_description.lod_elements.empty()) {
110+
gather_iter->second.otp_description
111+
= om.otr_description.lod_elements.front()
112+
.second;
113+
}
114+
}
92115
}
93116
}
94117
for (const auto& [key, value] : gather_map) {
@@ -156,10 +179,52 @@ CREATE TABLE all_opids (
156179
vc.c_iter->otp_range.otr_level_stats.lls_total_count);
157180
break;
158181
}
182+
case 6: {
183+
if (vc.c_iter->otp_description.empty()) {
184+
sqlite3_result_null(ctx);
185+
} else {
186+
to_sqlite(ctx, vc.c_iter->otp_description);
187+
}
188+
break;
189+
}
159190
}
160191

161192
return SQLITE_OK;
162193
}
194+
195+
int delete_row(sqlite3_vtab* tab, sqlite3_int64 rowid)
196+
{
197+
tab->zErrMsg = sqlite3_mprintf(
198+
"Rows cannot be deleted from the all_opids table");
199+
return SQLITE_ERROR;
200+
}
201+
202+
int insert_row(sqlite3_vtab* tab, sqlite3_int64& rowid_out)
203+
{
204+
tab->zErrMsg = sqlite3_mprintf(
205+
"Rows cannot be inserted into the all_opids table");
206+
return SQLITE_ERROR;
207+
}
208+
209+
int update_row(sqlite3_vtab* tab,
210+
sqlite3_int64& index,
211+
string_fragment opid,
212+
string_fragment earliest,
213+
string_fragment latest,
214+
int64_t errors,
215+
int64_t warnings,
216+
int64_t total,
217+
std::optional<string_fragment> description)
218+
{
219+
if (description) {
220+
const auto& active_files = injector::get<file_collection&>();
221+
222+
for (const auto& lf : active_files.fc_files) {
223+
lf->set_opid_description(opid, description.value());
224+
}
225+
}
226+
return SQLITE_OK;
227+
}
163228
};
164229

165230
struct all_thread_ids {
@@ -286,7 +351,7 @@ CREATE TABLE all_thread_ids (
286351
};
287352

288353
auto all_vtabs_binder = injector::bind_multiple<vtab_module_base>()
289-
.add<vtab_module<tvt_no_update<all_opids>>>()
354+
.add<vtab_module<all_opids>>()
290355
.add<vtab_module<tvt_no_update<all_thread_ids>>>();
291356

292357
} // namespace

src/hotkeys.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ handle_paging_key(notcurses* nc, const ncinput& ch, const char* keyseq)
233233
if (src_view != nullptr && dst_view != nullptr && sel) {
234234
src_view->time_for_row(sel.value()) |
235235
[dst_view, tc](auto top_ri) {
236-
dst_view->row_for_time(top_ri.ri_time) |
236+
dst_view->row_for(top_ri) |
237237
[tc](auto row) { tc->set_selection(row); };
238238
};
239239
}

src/listview_curses.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ listview_curses::reload_data()
185185
}
186186

187187
this->update_top_from_selection();
188+
this->lv_source->listview_selection_changed(*this);
188189
}
189190
}
190191
this->vc_needs_update = true;

src/log_format_fwd.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <chrono>
3636
#include <cstdint>
3737
#include <optional>
38+
#include <string>
3839
#include <utility>
3940
#include <vector>
4041

src/logfile.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,12 +1369,11 @@ logfile::rebuild_index(std::optional<ui_clock::time_point> deadline)
13691369
tid_iter->second |= tid_pair.second;
13701370
}
13711371
}
1372-
log_debug(
1373-
"%s: tid_map size: count=%zu; sizeof(otr)=%zu; alloc=%zu",
1374-
this->lf_filename_as_string.c_str(),
1375-
tids->ltis_tid_ranges.size(),
1376-
sizeof(opid_time_range),
1377-
this->lf_allocator.getNumBytesAllocated());
1372+
log_debug("%s: tid_map size: count=%zu; sizeof(otr)=%zu; alloc=%zu",
1373+
this->lf_filename_as_string.c_str(),
1374+
tids->ltis_tid_ranges.size(),
1375+
sizeof(opid_time_range),
1376+
this->lf_allocator.getNumBytesAllocated());
13781377
}
13791378

13801379
if (begin_size > this->lf_index.size()) {
@@ -1866,6 +1865,20 @@ logfile::set_logline_opid(uint32_t line_number, string_fragment opid)
18661865
this->lf_bookmark_metadata[line_number].bm_opid = opid.to_string();
18671866
}
18681867

1868+
void
1869+
logfile::set_opid_description(string_fragment opid, string_fragment desc)
1870+
{
1871+
auto opid_guard = this->lf_opids.writeAccess();
1872+
1873+
auto opid_iter = opid_guard->los_opid_ranges.find(opid);
1874+
if (opid_iter == opid_guard->los_opid_ranges.end()) {
1875+
return;
1876+
}
1877+
opid_iter->second.otr_description.lod_id = std::nullopt;
1878+
opid_iter->second.otr_description.lod_elements.clear();
1879+
opid_iter->second.otr_description.lod_elements[0] = desc.to_string();
1880+
}
1881+
18691882
void
18701883
logfile::clear_logline_opid(uint32_t line_number)
18711884
{

src/logfile.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ public:
429429

430430
void set_logline_opid(uint32_t line_number, string_fragment opid);
431431

432+
void set_opid_description(string_fragment opid, string_fragment desc);
433+
432434
void clear_logline_opid(uint32_t line_number);
433435

434436
void quiesce() { this->lf_line_buffer.quiesce(); }

0 commit comments

Comments
 (0)