Skip to content

Commit ad7fb0a

Browse files
committed
[breadcrumb] add thread ID to breadcrumb bar
1 parent 4857e95 commit ad7fb0a

34 files changed

+420
-248
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ Interface changes:
193193
of time in the gap.
194194
* The SPECTRO view now shows the year in timestamps
195195
and uses additional colors to show the value range.
196+
* The breadcrumb bar in the LOG view now includes the
197+
current thread, if defined.
196198
* If there are background tasks, like the processing done
197199
by `:add-source-path`, a panel with progress bars for
198200
each operation will be shown just above the bottom

src/all_logs_vtab.cc

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,12 @@ all_logs_vtab::all_logs_vtab()
5757
alv_src_meta(intern_string::lookup("log_msg_src"),
5858
value_kind_t::VALUE_JSON,
5959
logline_value_meta::table_column{3}),
60-
alv_thread_meta(intern_string::lookup("log_thread_id"),
61-
value_kind_t::VALUE_TEXT,
62-
logline_value_meta::table_column{4}),
6360
alv_stacktrace_meta(intern_string::lookup("log_stack_trace"),
6461
value_kind_t::VALUE_TEXT,
65-
logline_value_meta::table_column{5})
62+
logline_value_meta::table_column{4})
6663
{
6764
this->alv_msg_meta.lvm_identifier = true;
6865
this->alv_schema_meta.lvm_identifier = true;
69-
this->alv_thread_meta.lvm_identifier = true;
70-
this->alv_thread_meta.lvm_foreign_key = true;
7166
}
7267

7368
void
@@ -92,11 +87,6 @@ all_logs_vtab::get_columns(std::vector<vtab_column>& cols) const
9287
"",
9388
false,
9489
"The source code that generated this message");
95-
cols.emplace_back(this->alv_thread_meta.lvm_name.get(),
96-
SQLITE3_TEXT,
97-
"",
98-
false,
99-
"The ID of the thread that generated this message");
10090
cols.emplace_back(this->alv_stacktrace_meta.lvm_name.get(),
10191
SQLITE3_TEXT,
10292
"",
@@ -157,9 +147,8 @@ all_logs_vtab::extract(logfile* lf,
157147
h.update(find_res->pattern.c_str());
158148
}
159149
auto line_iter = lf->begin() + line_number;
160-
if (!line_iter->has_schema()) {
161-
line_iter->set_schema(h.to_array());
162-
}
150+
line_iter->merge_bloom_bits(h.to_bloom_bits());
151+
line_iter->set_schema_computed(true);
163152
values.lvv_values.emplace_back(this->alv_msg_meta,
164153
(std::string) find_res->pattern);
165154
values.lvv_values.emplace_back(this->alv_schema_meta, h.to_string());
@@ -195,12 +184,7 @@ all_logs_vtab::extract(logfile* lf,
195184
this->alv_values_meta,
196185
json_string(gen).to_string_fragment().to_string());
197186
}
198-
if (sub_values.lvv_thread_id_value) {
199-
values.lvv_values.emplace_back(this->alv_thread_meta,
200-
sub_values.lvv_thread_id_value.value());
201-
} else {
202-
values.lvv_values.emplace_back(this->alv_thread_meta);
203-
}
187+
values.lvv_thread_id_value = std::move(sub_values.lvv_thread_id_value);
204188
values.lvv_opid_value = std::move(sub_values.lvv_opid_value);
205189
values.lvv_opid_provenance = sub_values.lvv_opid_provenance;
206190
}

src/all_logs_vtab.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ private:
6060
logline_value_meta alv_schema_meta;
6161
logline_value_meta alv_values_meta;
6262
logline_value_meta alv_src_meta;
63-
logline_value_meta alv_thread_meta;
6463
logline_value_meta alv_stacktrace_meta;
6564
};
6665

src/base/intern_string.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,27 @@ string_fragment::to_string_with_case_style(case_style style) const
349349
return retval;
350350
}
351351

352+
uint64_t
353+
string_fragment::bloom_bits() const
354+
{
355+
auto a = XXH3_64bits(this->data(), this->length());
356+
auto b = a >> 8;
357+
if ((b & 0x3f) == (a & 0x3f)) {
358+
b = b >> 8;
359+
}
360+
auto c = b >> 8;
361+
if ((c & 0x3f) == (a & 0x3f) || (c & 0x3f) == (b & 0x3f)) {
362+
c = c >> 8;
363+
}
364+
365+
uint64_t retval = 0;
366+
retval |= 1ULL << (a % 56);
367+
retval |= 1ULL << (b % 56);
368+
retval |= 1ULL << (c % 56);
369+
370+
return retval;
371+
}
372+
352373
std::string
353374
string_fragment::to_unquoted_string() const
354375
{
@@ -540,7 +561,7 @@ string_fragment::byte_to_column_index(const size_t byte_index) const
540561
do {
541562
curr_col += 1;
542563
} while (curr_col % 8);
543-
break;
564+
break;
544565
default: {
545566
auto wcw_res = uc_width(read_res.unwrap(), "UTF-8");
546567
if (wcw_res < 0) {

src/base/intern_string.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,8 @@ struct string_fragment {
745745
return hash_str(this->data(), this->length());
746746
}
747747

748+
uint64_t bloom_bits() const;
749+
748750
const char* sf_string;
749751
int32_t sf_begin;
750752
int32_t sf_end;

src/base/log_level_enum.hh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ enum log_level_t : int {
5151
LEVEL_INVALID,
5252

5353
LEVEL__MAX,
54-
55-
LEVEL_IGNORE = 0x10, /*< Ignore */
56-
LEVEL_TIME_SKEW = 0x20, /*< Received after timestamp. */
57-
LEVEL_MARK = 0x40, /*< Bookmarked line. */
58-
LEVEL_CONTINUED = 0x80, /*< Continuation of multiline entry. */
59-
60-
/** Mask of flags for the level field. */
61-
LEVEL__FLAGS
62-
= (LEVEL_IGNORE | LEVEL_TIME_SKEW | LEVEL_MARK | LEVEL_CONTINUED)
6354
};
6455

6556
#endif

src/breadcrumb_curses.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,8 @@ breadcrumb_curses::reload_data()
176176
}
177177
}
178178

179-
auto matches = attr_line_t()
180-
.join(this->bc_similar_values
181-
| lnav::itertools::map(
182-
&breadcrumb::possibility::p_display_value),
183-
"\n")
184-
.move();
179+
auto matches = this->bc_similar_values
180+
| lnav::itertools::map(&breadcrumb::possibility::p_display_value);
185181
this->bc_match_source.replace_with(matches);
186182
auto width = this->bc_possible_values
187183
| lnav::itertools::fold(

src/hasher.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ public:
8787
return retval;
8888
}
8989

90+
uint64_t to_bloom_bits() const
91+
{
92+
uint64_t h1;
93+
uint64_t h2;
94+
uint64_t retval = 0;
95+
96+
this->h_context.Final(&h1, &h2);
97+
retval |= 1UL << (h1 % 56);
98+
retval |= 1UL << (h2 % 56);
99+
return retval;
100+
}
101+
90102
void to_string(auto_buffer& buf) const
91103
{
92104
auto bits = this->to_array();

src/hotkeys.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ DELETE FROM lnav_user_notifications WHERE id = 'org.lnav.mouse-support'
657657
.to_attr_line());
658658
} else {
659659
const auto& start_line = start_win_iter->get_logline();
660-
unsigned int opid_hash = start_line.get_opid();
660+
auto lvv = start_win_iter->get_values();
661+
auto opid_bloom
662+
= string_fragment::from_str(opid_opt.value())
663+
.bloom_bits();
661664
auto next_win
662665
= lss->window_to_end(start_win_iter->get_vis_line());
663666
auto next_win_iter = next_win->begin();
@@ -676,7 +679,7 @@ DELETE FROM lnav_user_notifications WHERE id = 'org.lnav.mouse-support'
676679
--next_win_iter;
677680
}
678681
const auto& next_line = next_win_iter->get_logline();
679-
if (!next_line.match_opid_hash(opid_hash)) {
682+
if (!next_line.match_bloom_bits(opid_bloom)) {
680683
continue;
681684
}
682685
const auto& next_opid_opt

src/itertools.similar.hh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <queue>
3434
#include <string>
35+
#include <vector>
3536

3637
#include "base/fts_fuzzy_match.hh"
3738
#include "base/itertools.hh"
@@ -79,6 +80,7 @@ std::vector<typename T::value_type>
7980
operator|(const T& in, const lnav::itertools::details::similar_to<F>& st)
8081
{
8182
using score_pair = std::pair<int, typename T::value_type>;
83+
constexpr size_t MAX_ELEMENTS = 512;
8284

8385
struct score_cmp {
8486
bool operator()(const score_pair& lhs, const score_pair& rhs)
@@ -90,7 +92,13 @@ operator|(const T& in, const lnav::itertools::details::similar_to<F>& st)
9092
std::vector<std::remove_const_t<typename T::value_type>> retval;
9193

9294
if (st.st_pattern.empty()) {
93-
retval.insert(retval.begin(), in.begin(), in.end());
95+
retval.reserve(std::min(MAX_ELEMENTS, in.size()));
96+
for (const auto& elem : in) {
97+
if (retval.size() >= MAX_ELEMENTS) {
98+
break;
99+
}
100+
retval.emplace_back(elem);
101+
}
94102
return retval;
95103
}
96104

0 commit comments

Comments
 (0)