• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 18954735303-2618

30 Oct 2025 08:49PM UTC coverage: 68.778% (+0.7%) from 68.076%
18954735303-2618

push

github

tstack
[filters] add min/max time filters to UI

Related to #1275
Related to #1576

175 of 525 new or added lines in 12 files covered. (33.33%)

582 existing lines in 3 files now uncovered.

50384 of 73256 relevant lines covered (68.78%)

426743.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.85
/src/logfile_sub_source.cc
1
/**
2
 * Copyright (c) 2007-2012, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include <algorithm>
31
#include <chrono>
32
#include <future>
33

34
#include "logfile_sub_source.hh"
35

36
#include <sqlite3.h>
37

38
#include "base/ansi_scrubber.hh"
39
#include "base/ansi_vars.hh"
40
#include "base/fs_util.hh"
41
#include "base/injector.hh"
42
#include "base/itertools.enumerate.hh"
43
#include "base/itertools.hh"
44
#include "base/string_util.hh"
45
#include "bookmarks.json.hh"
46
#include "command_executor.hh"
47
#include "config.h"
48
#include "field_overlay_source.hh"
49
#include "hasher.hh"
50
#include "k_merge_tree.h"
51
#include "lnav_util.hh"
52
#include "log_accel.hh"
53
#include "logfile_sub_source.cfg.hh"
54
#include "logline_window.hh"
55
#include "md2attr_line.hh"
56
#include "ptimec.hh"
57
#include "scn/scan.h"
58
#include "shlex.hh"
59
#include "sql_util.hh"
60
#include "vtab_module.hh"
61
#include "yajlpp/yajlpp.hh"
62
#include "yajlpp/yajlpp_def.hh"
63

64
using namespace std::chrono_literals;
65
using namespace lnav::roles::literals;
66

67
const DIST_SLICE(bm_types) bookmark_type_t logfile_sub_source::BM_FILES("file");
68

69
static int
70
pretty_sql_callback(exec_context& ec, sqlite3_stmt* stmt)
73✔
71
{
72
    if (!sqlite3_stmt_busy(stmt)) {
73✔
73
        return 0;
32✔
74
    }
75

76
    const auto ncols = sqlite3_column_count(stmt);
41✔
77

78
    for (int lpc = 0; lpc < ncols; lpc++) {
82✔
79
        if (!ec.ec_accumulator->empty()) {
41✔
80
            ec.ec_accumulator->append(", ");
10✔
81
        }
82

83
        const char* res = (const char*) sqlite3_column_text(stmt, lpc);
41✔
84
        if (res == nullptr) {
41✔
85
            continue;
×
86
        }
87

88
        ec.ec_accumulator->append(res);
41✔
89
    }
90

91
    for (int lpc = 0; lpc < ncols; lpc++) {
82✔
92
        const auto* colname = sqlite3_column_name(stmt, lpc);
41✔
93
        auto* raw_value = sqlite3_column_value(stmt, lpc);
41✔
94
        auto value_type = sqlite3_value_type(raw_value);
41✔
95
        scoped_value_t value;
41✔
96

97
        switch (value_type) {
41✔
98
            case SQLITE_INTEGER:
×
99
                value = (int64_t) sqlite3_value_int64(raw_value);
×
100
                break;
×
101
            case SQLITE_FLOAT:
×
102
                value = sqlite3_value_double(raw_value);
×
103
                break;
×
104
            case SQLITE_NULL:
×
105
                value = null_value_t{};
×
106
                break;
×
107
            default:
41✔
108
                value = string_fragment::from_bytes(
41✔
109
                    sqlite3_value_text(raw_value),
110
                    sqlite3_value_bytes(raw_value));
82✔
111
                break;
41✔
112
        }
113
        if (!ec.ec_local_vars.empty() && !ec.ec_dry_run) {
41✔
114
            if (sql_ident_needs_quote(colname)) {
41✔
115
                continue;
27✔
116
            }
117
            auto& vars = ec.ec_local_vars.top();
14✔
118

119
            if (vars.find(colname) != vars.end()) {
42✔
120
                continue;
10✔
121
            }
122

123
            if (value.is<string_fragment>()) {
4✔
124
                value = value.get<string_fragment>().to_string();
4✔
125
            }
126
            vars[colname] = value;
8✔
127
        }
128
    }
41✔
129
    return 0;
41✔
130
}
131

132
static std::future<std::string>
133
pretty_pipe_callback(exec_context& ec, const std::string& cmdline, auto_fd& fd)
×
134
{
135
    auto retval = std::async(std::launch::async, [&]() {
×
136
        char buffer[1024];
137
        std::ostringstream ss;
×
138
        ssize_t rc;
139

140
        while ((rc = read(fd, buffer, sizeof(buffer))) > 0) {
×
141
            ss.write(buffer, rc);
×
142
        }
143

144
        auto retval = ss.str();
×
145

146
        if (endswith(retval, "\n")) {
×
147
            retval.resize(retval.length() - 1);
×
148
        }
149

150
        return retval;
×
151
    });
×
152

153
    return retval;
×
154
}
155

156
logfile_sub_source::logfile_sub_source()
1,142✔
157
    : text_sub_source(1), lnav_config_listener(__FILE__),
158
      lss_meta_grepper(*this), lss_location_history(*this)
1,142✔
159
{
160
    this->tss_supports_filtering = true;
1,142✔
161
    this->clear_line_size_cache();
1,142✔
162
    this->clear_min_max_row_times();
1,142✔
163
}
1,142✔
164

165
std::shared_ptr<logfile>
166
logfile_sub_source::find(const char* fn, content_line_t& line_base)
23✔
167
{
168
    std::shared_ptr<logfile> retval = nullptr;
23✔
169

170
    line_base = content_line_t(0);
23✔
171
    for (auto iter = this->lss_files.begin();
23✔
172
         iter != this->lss_files.end() && retval == nullptr;
47✔
173
         ++iter)
24✔
174
    {
175
        auto& ld = *(*iter);
24✔
176
        auto* lf = ld.get_file_ptr();
24✔
177

178
        if (lf == nullptr) {
24✔
179
            continue;
×
180
        }
181
        if (strcmp(lf->get_filename_as_string().c_str(), fn) == 0) {
24✔
182
            retval = ld.get_file();
23✔
183
        } else {
184
            line_base += content_line_t(MAX_LINES_PER_FILE);
1✔
185
        }
186
    }
187

188
    return retval;
23✔
189
}
×
190

191
struct filtered_logline_cmp {
192
    filtered_logline_cmp(const logfile_sub_source& lc) : llss_controller(lc) {}
316✔
193

194
    bool operator()(const uint32_t& lhs, const uint32_t& rhs) const
195
    {
196
        auto cl_lhs = llss_controller.lss_index[lhs].value();
197
        auto cl_rhs = llss_controller.lss_index[rhs].value();
198
        auto ll_lhs = this->llss_controller.find_line(cl_lhs);
199
        auto ll_rhs = this->llss_controller.find_line(cl_rhs);
200

201
        if (ll_lhs == nullptr) {
202
            return true;
203
        }
204
        if (ll_rhs == nullptr) {
205
            return false;
206
        }
207
        return (*ll_lhs) < (*ll_rhs);
208
    }
209

210
    bool operator()(const uint32_t& lhs, const timeval& rhs) const
1,030✔
211
    {
212
        const auto cl_lhs = llss_controller.lss_index[lhs].value();
1,030✔
213
        const auto* ll_lhs = this->llss_controller.find_line(cl_lhs);
1,030✔
214

215
        if (ll_lhs == nullptr) {
1,030✔
216
            return true;
×
217
        }
218
        return (*ll_lhs) < rhs;
1,030✔
219
    }
220

221
    const logfile_sub_source& llss_controller;
222
};
223

224
std::optional<vis_line_t>
225
logfile_sub_source::find_from_time(const timeval& start) const
69✔
226
{
227
    const auto lb = std::lower_bound(this->lss_filtered_index.begin(),
69✔
228
                                     this->lss_filtered_index.end(),
229
                                     start,
230
                                     filtered_logline_cmp(*this));
231
    if (lb != this->lss_filtered_index.end()) {
69✔
232
        auto retval = std::distance(this->lss_filtered_index.begin(), lb);
59✔
233
        return vis_line_t(retval);
59✔
234
    }
235

236
    return std::nullopt;
10✔
237
}
238

239
line_info
240
logfile_sub_source::text_value_for_line(textview_curses& tc,
3,010✔
241
                                        int row,
242
                                        std::string& value_out,
243
                                        line_flags_t flags)
244
{
245
    if (this->lss_indexing_in_progress) {
3,010✔
246
        value_out = "";
×
247
        this->lss_token_attrs.clear();
×
248
        return {};
×
249
    }
250

251
    line_info retval;
3,010✔
252
    content_line_t line(0);
3,010✔
253

254
    require_ge(row, 0);
3,010✔
255
    require_lt((size_t) row, this->lss_filtered_index.size());
3,010✔
256

257
    line = this->at(vis_line_t(row));
3,010✔
258

259
    if (flags & RF_RAW) {
3,010✔
260
        auto lf = this->find(line);
32✔
261
        auto ll = lf->begin() + line;
32✔
262
        retval.li_file_range = lf->get_file_range(ll, false);
32✔
263
        retval.li_level = ll->get_msg_level();
32✔
264
        // retval.li_timestamp = ll->get_timeval();
265
        retval.li_partial = false;
32✔
266
        retval.li_utf8_scan_result.usr_has_ansi = ll->has_ansi();
32✔
267
        retval.li_utf8_scan_result.usr_message = ll->is_valid_utf() ? nullptr
32✔
268
                                                                    : "bad";
269
        // timeval start_time, end_time;
270
        // gettimeofday(&start_time, NULL);
271
        value_out = lf->read_line(lf->begin() + line)
64✔
272
                        .map([](auto sbr) { return to_string(sbr); })
64✔
273
                        .unwrapOr({});
32✔
274
        // gettimeofday(&end_time, NULL);
275
        // timeval diff = end_time - start_time;
276
        // log_debug("read time %d.%06d %s:%d", diff.tv_sec, diff.tv_usec,
277
        // lf->get_filename().c_str(), line);
278
        return retval;
32✔
279
    }
32✔
280

281
    require_false(this->lss_in_value_for_line);
2,978✔
282

283
    this->lss_in_value_for_line = true;
2,978✔
284
    this->lss_token_flags = flags;
2,978✔
285
    this->lss_token_file_data = this->find_data(line);
2,978✔
286
    this->lss_token_file = (*this->lss_token_file_data)->get_file();
2,978✔
287
    this->lss_token_line = this->lss_token_file->begin() + line;
2,978✔
288

289
    this->lss_token_attrs.clear();
2,978✔
290
    this->lss_token_values.clear();
2,978✔
291
    this->lss_share_manager.invalidate_refs();
2,978✔
292
    if (flags & text_sub_source::RF_FULL) {
2,978✔
293
        shared_buffer_ref sbr;
48✔
294

295
        this->lss_token_file->read_full_message(this->lss_token_line, sbr);
48✔
296
        this->lss_token_value = to_string(sbr);
48✔
297
        if (sbr.get_metadata().m_has_ansi) {
48✔
298
            scrub_ansi_string(this->lss_token_value, &this->lss_token_attrs);
17✔
299
            sbr.get_metadata().m_has_ansi = false;
17✔
300
        }
301
    } else {
48✔
302
        this->lss_token_value
303
            = this->lss_token_file->read_line(this->lss_token_line)
5,860✔
304
                  .map([](auto sbr) { return to_string(sbr); })
5,860✔
305
                  .unwrapOr({});
2,930✔
306
        if (this->lss_token_line->has_ansi()) {
2,930✔
307
            scrub_ansi_string(this->lss_token_value, &this->lss_token_attrs);
24✔
308
        }
309
    }
310
    this->lss_token_shift_start = 0;
2,978✔
311
    this->lss_token_shift_size = 0;
2,978✔
312

313
    auto format = this->lss_token_file->get_format();
2,978✔
314

315
    value_out = this->lss_token_value;
2,978✔
316

317
    auto& sbr = this->lss_token_values.lvv_sbr;
2,978✔
318

319
    sbr.share(this->lss_share_manager,
2,978✔
320
              (char*) this->lss_token_value.c_str(),
321
              this->lss_token_value.size());
322
    format->annotate(this->lss_token_file.get(),
5,956✔
323
                     line,
324
                     this->lss_token_attrs,
2,978✔
325
                     this->lss_token_values);
2,978✔
326
    if (flags & RF_REWRITE) {
2,978✔
327
        exec_context ec(
328
            &this->lss_token_values, pretty_sql_callback, pretty_pipe_callback);
48✔
329
        std::string rewritten_line;
48✔
330
        db_label_source rewrite_label_source;
48✔
331

332
        ec.with_perms(exec_context::perm_t::READ_ONLY);
48✔
333
        ec.ec_local_vars.push(std::map<std::string, scoped_value_t>());
48✔
334
        ec.ec_top_line = vis_line_t(row);
48✔
335
        ec.ec_label_source_stack.push_back(&rewrite_label_source);
48✔
336
        add_ansi_vars(ec.ec_global_vars);
48✔
337
        add_global_vars(ec);
48✔
338
        format->rewrite(ec, sbr, this->lss_token_attrs, rewritten_line);
48✔
339
        this->lss_token_value.assign(rewritten_line);
48✔
340
        value_out = this->lss_token_value;
48✔
341
    }
48✔
342

343
    {
344
        auto lr = line_range{0, (int) this->lss_token_value.length()};
2,978✔
345
        this->lss_token_attrs.emplace_back(lr, SA_ORIGINAL_LINE.value());
2,978✔
346
    }
347

348
    std::optional<exttm> adjusted_tm;
2,978✔
349
    auto time_attr = find_string_attr(this->lss_token_attrs, &L_TIMESTAMP);
2,978✔
350
    if (!this->lss_token_line->is_continued() && !format->lf_formatted_lines
4,122✔
351
        && (this->lss_token_file->is_time_adjusted()
908✔
352
            || ((format->lf_timestamp_flags & ETF_ZONE_SET
893✔
353
                 || format->lf_date_time.dts_default_zone != nullptr)
580✔
354
                && format->lf_date_time.dts_zoned_to_local)
397✔
355
            || format->lf_timestamp_flags & ETF_MACHINE_ORIENTED
496✔
356
            || !(format->lf_timestamp_flags & ETF_DAY_SET)
496✔
357
            || !(format->lf_timestamp_flags & ETF_MONTH_SET))
475✔
358
        && format->lf_date_time.dts_fmt_lock != -1)
4,122✔
359
    {
360
        if (time_attr != this->lss_token_attrs.end()) {
377✔
361
            const auto time_range = time_attr->sa_range;
377✔
362
            const auto time_sf = string_fragment::from_str_range(
377✔
363
                this->lss_token_value, time_range.lr_start, time_range.lr_end);
377✔
364
            adjusted_tm = format->tm_for_display(this->lss_token_line, time_sf);
377✔
365

366
            char buffer[128];
367
            const char* fmt;
368
            ssize_t len;
369

370
            if (format->lf_timestamp_flags & ETF_MACHINE_ORIENTED
377✔
371
                || !(format->lf_timestamp_flags & ETF_DAY_SET)
315✔
372
                || !(format->lf_timestamp_flags & ETF_MONTH_SET))
692✔
373
            {
374
                if (format->lf_timestamp_flags & ETF_NANOS_SET) {
68✔
375
                    fmt = "%Y-%m-%d %H:%M:%S.%N";
×
376
                } else if (format->lf_timestamp_flags & ETF_MICROS_SET) {
68✔
377
                    fmt = "%Y-%m-%d %H:%M:%S.%f";
63✔
378
                } else if (format->lf_timestamp_flags & ETF_MILLIS_SET) {
5✔
379
                    fmt = "%Y-%m-%d %H:%M:%S.%L";
2✔
380
                } else {
381
                    fmt = "%Y-%m-%d %H:%M:%S";
3✔
382
                }
383
                len = ftime_fmt(
68✔
384
                    buffer, sizeof(buffer), fmt, adjusted_tm.value());
68✔
385
            } else {
386
                len = format->lf_date_time.ftime(
618✔
387
                    buffer,
388
                    sizeof(buffer),
389
                    format->get_timestamp_formats(),
390
                    adjusted_tm.value());
309✔
391
            }
392

393
            value_out.replace(
754✔
394
                time_range.lr_start, time_range.length(), buffer, len);
377✔
395
            this->lss_token_shift_start = time_range.lr_start;
377✔
396
            this->lss_token_shift_size = len - time_range.length();
377✔
397
        }
398
    }
399

400
    // Insert space for the file/search-hit markers.
401
    value_out.insert(0, 1, ' ');
2,978✔
402
    this->lss_time_column_size = 0;
2,978✔
403
    if (this->lss_line_context == line_context_t::time_column) {
2,978✔
404
        if (time_attr != this->lss_token_attrs.end()) {
×
405
            const char* fmt;
406
            if (this->lss_all_timestamp_flags
×
407
                & (ETF_MICROS_SET | ETF_NANOS_SET))
×
408
            {
409
                fmt = "%H:%M:%S.%f";
×
410
            } else if (this->lss_all_timestamp_flags & ETF_MILLIS_SET) {
×
411
                fmt = "%H:%M:%S.%L";
×
412
            } else {
413
                fmt = "%H:%M:%S";
×
414
            }
415
            if (!adjusted_tm) {
×
416
                const auto time_range = time_attr->sa_range;
×
417
                const auto time_sf
418
                    = string_fragment::from_str_range(this->lss_token_value,
×
419
                                                      time_range.lr_start,
×
420
                                                      time_range.lr_end);
×
421
                adjusted_tm
422
                    = format->tm_for_display(this->lss_token_line, time_sf);
×
423
            }
424
            char buffer[128];
425
            this->lss_time_column_size
426
                = ftime_fmt(buffer, sizeof(buffer), fmt, adjusted_tm.value());
×
427
            if (this->tss_view->is_selectable()
×
428
                && this->tss_view->get_selection() == row)
×
429
            {
430
                buffer[this->lss_time_column_size] = ' ';
×
431
                buffer[this->lss_time_column_size + 1] = ' ';
×
432
                this->lss_time_column_size += 2;
×
433
            } else {
434
                constexpr char block[] = "\u258c ";
×
435

436
                strcpy(&buffer[this->lss_time_column_size], block);
×
437
                this->lss_time_column_size += sizeof(block) - 1;
×
438
            }
439
            if (time_attr->sa_range.lr_start != 0) {
×
440
                buffer[this->lss_time_column_size] = ' ';
×
441
                this->lss_time_column_size += 1;
×
442
                this->lss_time_column_padding = 1;
×
443
            } else {
444
                this->lss_time_column_padding = 0;
×
445
            }
446
            value_out.insert(1, buffer, this->lss_time_column_size);
×
447
            this->lss_token_attrs.emplace_back(time_attr->sa_range,
×
448
                                               SA_REPLACED.value());
×
449
        }
450
        if (format->lf_level_hideable) {
×
451
            auto level_attr = find_string_attr(this->lss_token_attrs, &L_LEVEL);
×
452
            if (level_attr != this->lss_token_attrs.end()) {
×
453
                this->lss_token_attrs.emplace_back(level_attr->sa_range,
×
454
                                                   SA_REPLACED.value());
×
455
            }
456
        }
457
    } else if (this->lss_line_context < line_context_t::none) {
2,978✔
458
        size_t file_offset_end;
459
        std::string name;
×
460
        if (this->lss_line_context == line_context_t::filename) {
×
461
            file_offset_end = this->lss_filename_width;
×
462
            name = fmt::to_string(this->lss_token_file->get_filename());
×
463
            if (file_offset_end < name.size()) {
×
464
                file_offset_end = name.size();
×
465
                this->lss_filename_width = name.size();
×
466
            }
467
        } else {
468
            file_offset_end = this->lss_basename_width;
×
469
            name = fmt::to_string(this->lss_token_file->get_unique_path());
×
470
            if (file_offset_end < name.size()) {
×
471
                file_offset_end = name.size();
×
472
                this->lss_basename_width = name.size();
×
473
            }
474
        }
475
        value_out.insert(0, file_offset_end - name.size(), ' ');
×
476
        value_out.insert(0, name);
×
477
    }
478

479
    if (this->tas_display_time_offset) {
2,978✔
480
        auto row_vl = vis_line_t(row);
210✔
481
        auto relstr = this->get_time_offset_for_line(tc, row_vl);
210✔
482
        value_out = fmt::format(FMT_STRING("{: >12}|{}"), relstr, value_out);
840✔
483
    }
210✔
484

485
    this->lss_in_value_for_line = false;
2,978✔
486

487
    return retval;
2,978✔
488
}
2,978✔
489

490
void
491
logfile_sub_source::text_attrs_for_line(textview_curses& lv,
2,978✔
492
                                        int row,
493
                                        string_attrs_t& value_out)
494
{
495
    if (this->lss_indexing_in_progress) {
2,978✔
496
        return;
×
497
    }
498

499
    auto& vc = view_colors::singleton();
2,978✔
500
    logline* next_line = nullptr;
2,978✔
501
    line_range lr;
2,978✔
502
    int time_offset_end = 0;
2,978✔
503
    text_attrs attrs;
2,978✔
504

505
    value_out = this->lss_token_attrs;
2,978✔
506

507
    if ((row + 1) < (int) this->lss_filtered_index.size()) {
2,978✔
508
        next_line = this->find_line(this->at(vis_line_t(row + 1)));
2,797✔
509
    }
510

511
    if (next_line != nullptr
2,978✔
512
        && (day_num(next_line->get_time<std::chrono::seconds>().count())
5,775✔
513
            > day_num(this->lss_token_line->get_time<std::chrono::seconds>()
5,775✔
514
                          .count())))
515
    {
516
        attrs |= text_attrs::style::underline;
15✔
517
    }
518

519
    const auto& line_values = this->lss_token_values;
2,978✔
520

521
    lr.lr_start = 0;
2,978✔
522
    lr.lr_end = -1;
2,978✔
523
    value_out.emplace_back(
2,978✔
524
        lr, SA_LEVEL.value(this->lss_token_line->get_msg_level()));
5,956✔
525

526
    lr.lr_start = time_offset_end;
2,978✔
527
    lr.lr_end = -1;
2,978✔
528

529
    if (!attrs.empty()) {
2,978✔
530
        value_out.emplace_back(lr, VC_STYLE.value(attrs));
15✔
531
    }
532

533
    if (this->lss_token_line->get_msg_level() == log_level_t::LEVEL_INVALID) {
2,978✔
534
        for (auto& token_attr : this->lss_token_attrs) {
37✔
535
            if (token_attr.sa_type != &SA_INVALID) {
20✔
536
                continue;
17✔
537
            }
538

539
            value_out.emplace_back(token_attr.sa_range,
3✔
540
                                   VC_ROLE.value(role_t::VCR_INVALID_MSG));
6✔
541
        }
542
    }
543

544
    for (const auto& line_value : line_values.lvv_values) {
13,892✔
545
        if ((!(this->lss_token_flags & RF_FULL)
23,874✔
546
             && line_value.lv_sub_offset
21,384✔
547
                 != this->lss_token_line->get_sub_offset())
10,692✔
548
            || !line_value.lv_origin.is_valid())
21,606✔
549
        {
550
            continue;
2,046✔
551
        }
552

553
        if (line_value.lv_meta.is_hidden()) {
8,868✔
554
            value_out.emplace_back(line_value.lv_origin,
151✔
555
                                   SA_HIDDEN.value(ui_icon_t::hidden));
302✔
556
        }
557

558
        if (!line_value.lv_meta.lvm_identifier
22,803✔
559
            || !line_value.lv_origin.is_valid())
8,868✔
560
        {
561
            continue;
5,067✔
562
        }
563

564
        value_out.emplace_back(line_value.lv_origin,
3,801✔
565
                               VC_ROLE.value(role_t::VCR_IDENTIFIER));
7,602✔
566
    }
567

568
    if (this->lss_token_shift_size) {
2,978✔
569
        shift_string_attrs(value_out,
96✔
570
                           this->lss_token_shift_start + 1,
96✔
571
                           this->lss_token_shift_size);
572
    }
573

574
    shift_string_attrs(value_out, 0, 1);
2,978✔
575

576
    lr.lr_start = 0;
2,978✔
577
    lr.lr_end = 1;
2,978✔
578
    {
579
        auto& bm = lv.get_bookmarks();
2,978✔
580
        const auto& bv = bm[&BM_FILES];
2,978✔
581
        bool is_first_for_file = bv.bv_tree.exists(vis_line_t(row));
2,978✔
582
        bool is_last_for_file = bv.bv_tree.exists(vis_line_t(row + 1));
2,978✔
583
        auto graph = NCACS_VLINE;
2,978✔
584
        if (is_first_for_file) {
2,978✔
585
            if (is_last_for_file) {
201✔
586
                graph = NCACS_HLINE;
8✔
587
            } else {
588
                graph = NCACS_ULCORNER;
193✔
589
            }
590
        } else if (is_last_for_file) {
2,777✔
591
            graph = NCACS_LLCORNER;
21✔
592
        }
593
        value_out.emplace_back(lr, VC_GRAPHIC.value(graph));
2,978✔
594

595
        if (!(this->lss_token_flags & RF_FULL)) {
2,978✔
596
            const auto& bv_search = bm[&textview_curses::BM_SEARCH];
2,930✔
597

598
            if (bv_search.bv_tree.exists(vis_line_t(row))) {
2,930✔
599
                lr.lr_start = 0;
9✔
600
                lr.lr_end = 1;
9✔
601
                value_out.emplace_back(
9✔
602
                    lr, VC_STYLE.value(text_attrs::with_reverse()));
18✔
603
            }
604
        }
605
    }
606

607
    value_out.emplace_back(lr,
2,978✔
608
                           VC_STYLE.value(vc.attrs_for_ident(
5,956✔
609
                               this->lss_token_file->get_filename())));
2,978✔
610

611
    if (this->lss_line_context < line_context_t::none) {
2,978✔
612
        size_t file_offset_end
×
613
            = (this->lss_line_context == line_context_t::filename)
×
614
            ? this->lss_filename_width
×
615
            : this->lss_basename_width;
616

617
        shift_string_attrs(value_out, 0, file_offset_end);
×
618

619
        lr.lr_start = 0;
×
620
        lr.lr_end = file_offset_end + 1;
×
621
        value_out.emplace_back(lr,
×
622
                               VC_STYLE.value(vc.attrs_for_ident(
×
623
                                   this->lss_token_file->get_filename())));
×
624
    } else if (this->lss_time_column_size > 0) {
2,978✔
625
        shift_string_attrs(value_out, 1, this->lss_time_column_size);
×
626

627
        ui_icon_t icon;
628
        switch (this->lss_token_line->get_msg_level()) {
×
629
            case LEVEL_TRACE:
×
630
                icon = ui_icon_t::log_level_trace;
×
631
                break;
×
632
            case LEVEL_DEBUG:
×
633
            case LEVEL_DEBUG2:
634
            case LEVEL_DEBUG3:
635
            case LEVEL_DEBUG4:
636
            case LEVEL_DEBUG5:
637
                icon = ui_icon_t::log_level_debug;
×
638
                break;
×
639
            case LEVEL_INFO:
×
640
                icon = ui_icon_t::log_level_info;
×
641
                break;
×
642
            case LEVEL_STATS:
×
643
                icon = ui_icon_t::log_level_stats;
×
644
                break;
×
645
            case LEVEL_NOTICE:
×
646
                icon = ui_icon_t::log_level_notice;
×
647
                break;
×
648
            case LEVEL_WARNING:
×
649
                icon = ui_icon_t::log_level_warning;
×
650
                break;
×
651
            case LEVEL_ERROR:
×
652
                icon = ui_icon_t::log_level_error;
×
653
                break;
×
654
            case LEVEL_CRITICAL:
×
655
                icon = ui_icon_t::log_level_critical;
×
656
                break;
×
657
            case LEVEL_FATAL:
×
658
                icon = ui_icon_t::log_level_fatal;
×
659
                break;
×
660
            default:
×
661
                icon = ui_icon_t::hidden;
×
662
                break;
×
663
        }
664
        auto extra_space_size = this->lss_time_column_padding;
×
665
        lr.lr_start = 1 + this->lss_time_column_size - 1 - extra_space_size;
×
666
        lr.lr_end = 1 + this->lss_time_column_size - extra_space_size;
×
667
        value_out.emplace_back(lr, VC_ICON.value(icon));
×
668
        if (this->tss_view->is_selectable()
×
669
            && this->tss_view->get_selection() != row)
×
670
        {
671
            lr.lr_start = 1;
×
672
            lr.lr_end = 1 + this->lss_time_column_size - 2 - extra_space_size;
×
673
            value_out.emplace_back(lr, VC_ROLE.value(role_t::VCR_TIME_COLUMN));
×
674
            if (this->lss_token_line->is_time_skewed()) {
×
675
                value_out.emplace_back(lr,
×
676
                                       VC_ROLE.value(role_t::VCR_SKEWED_TIME));
×
677
            }
678
            lr.lr_start = 1 + this->lss_time_column_size - 2 - extra_space_size;
×
679
            lr.lr_end = 1 + this->lss_time_column_size - 1 - extra_space_size;
×
680
            value_out.emplace_back(
×
681
                lr, VC_ROLE.value(role_t::VCR_TIME_COLUMN_TO_TEXT));
×
682
        }
683
    }
684

685
    if (this->tas_display_time_offset) {
2,978✔
686
        time_offset_end = 13;
210✔
687
        lr.lr_start = 0;
210✔
688
        lr.lr_end = time_offset_end;
210✔
689

690
        shift_string_attrs(value_out, 0, time_offset_end);
210✔
691

692
        value_out.emplace_back(lr, VC_ROLE.value(role_t::VCR_OFFSET_TIME));
210✔
693
        value_out.emplace_back(line_range(12, 13),
210✔
694
                               VC_GRAPHIC.value(NCACS_VLINE));
420✔
695

696
        auto bar_role = role_t::VCR_NONE;
210✔
697

698
        switch (this->get_line_accel_direction(vis_line_t(row))) {
210✔
699
            case log_accel::direction_t::A_STEADY:
126✔
700
                break;
126✔
701
            case log_accel::direction_t::A_DECEL:
42✔
702
                bar_role = role_t::VCR_DIFF_DELETE;
42✔
703
                break;
42✔
704
            case log_accel::direction_t::A_ACCEL:
42✔
705
                bar_role = role_t::VCR_DIFF_ADD;
42✔
706
                break;
42✔
707
        }
708
        if (bar_role != role_t::VCR_NONE) {
210✔
709
            value_out.emplace_back(line_range(12, 13), VC_ROLE.value(bar_role));
84✔
710
        }
711
    }
712

713
    lr.lr_start = 0;
2,978✔
714
    lr.lr_end = -1;
2,978✔
715
    value_out.emplace_back(lr, L_FILE.value(this->lss_token_file));
2,978✔
716
    value_out.emplace_back(
2,978✔
717
        lr, SA_FORMAT.value(this->lss_token_file->get_format()->get_name()));
5,956✔
718

719
    {
720
        auto line_meta_context = this->get_bookmark_metadata_context(
2,978✔
721
            vis_line_t(row + 1), bookmark_metadata::categories::partition);
722
        if (line_meta_context.bmc_current_metadata) {
2,978✔
723
            lr.lr_start = 0;
8✔
724
            lr.lr_end = -1;
8✔
725
            value_out.emplace_back(
8✔
726
                lr,
727
                L_PARTITION.value(
16✔
728
                    line_meta_context.bmc_current_metadata.value()));
729
        }
730

731
        auto line_meta_opt = this->find_bookmark_metadata(vis_line_t(row));
2,978✔
732

733
        if (line_meta_opt) {
2,978✔
734
            lr.lr_start = 0;
31✔
735
            lr.lr_end = -1;
31✔
736
            value_out.emplace_back(lr, L_META.value(line_meta_opt.value()));
31✔
737
        }
738
    }
739

740
    auto src_file_attr = get_string_attr(value_out, SA_SRC_FILE);
2,978✔
741
    if (src_file_attr) {
2,978✔
742
        auto lr = src_file_attr->saw_string_attr->sa_range;
27✔
743
        lr.lr_end = lr.lr_start + 1;
27✔
744
        value_out.emplace_back(lr,
27✔
745
                               VC_STYLE.value(text_attrs::with_underline()));
54✔
746
        value_out.emplace_back(lr,
27✔
747
                               VC_COMMAND.value(ui_command{
108✔
748
                                   source_location{},
749
                                   ":toggle-breakpoint",
750
                               }));
751
    }
752

753
    if (this->lss_time_column_size == 0) {
2,978✔
754
        if (this->lss_token_file->is_time_adjusted()) {
2,978✔
755
            auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);
17✔
756

757
            if (time_range.lr_end != -1) {
17✔
758
                value_out.emplace_back(
15✔
759
                    time_range, VC_ROLE.value(role_t::VCR_ADJUSTED_TIME));
30✔
760
            }
761
        } else if (this->lss_token_line->is_time_skewed()) {
2,961✔
762
            auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);
8✔
763

764
            if (time_range.lr_end != -1) {
8✔
765
                value_out.emplace_back(time_range,
8✔
766
                                       VC_ROLE.value(role_t::VCR_SKEWED_TIME));
16✔
767
            }
768
        }
769
    }
770

771
    if (this->ttt_preview_min_time
2,978✔
772
        && this->lss_token_line->get_timeval() < this->ttt_preview_min_time)
2,978✔
773
    {
NEW
774
        auto color = styling::color_unit::from_palette(
×
NEW
775
            lnav::enums::to_underlying(ansi_color::red));
×
NEW
776
        value_out.emplace_back(line_range{0, 1},
×
NEW
777
                               VC_BACKGROUND.value(color));
×
778
    }
779
    if (this->ttt_preview_max_time
2,978✔
780
        && this->ttt_preview_max_time < this->lss_token_line->get_timeval())
2,978✔
781
    {
NEW
782
        auto color = styling::color_unit::from_palette(
×
NEW
783
            lnav::enums::to_underlying(ansi_color::red));
×
NEW
784
        value_out.emplace_back(line_range{0, 1},
×
NEW
785
                               VC_BACKGROUND.value(color));
×
786
    }
787
    if (!this->lss_token_line->is_continued()) {
2,978✔
788
        if (this->lss_preview_filter_stmt != nullptr) {
1,144✔
789
            auto color = styling::color_unit::EMPTY;
×
790
            auto eval_res
791
                = this->eval_sql_filter(this->lss_preview_filter_stmt.in(),
792
                                        this->lss_token_file_data,
793
                                        this->lss_token_line);
×
794
            if (eval_res.isErr()) {
×
795
                color = palette_color{
×
796
                    lnav::enums::to_underlying(ansi_color::yellow)};
×
797
                value_out.emplace_back(
×
798
                    line_range{0, -1},
×
799
                    SA_ERROR.value(
×
800
                        eval_res.unwrapErr().to_attr_line().get_string()));
×
801
            } else {
802
                auto matched = eval_res.unwrap();
×
803

804
                if (matched) {
×
805
                    color = palette_color{
×
806
                        lnav::enums::to_underlying(ansi_color::green)};
×
807
                } else {
808
                    color = palette_color{
×
809
                        lnav::enums::to_underlying(ansi_color::red)};
×
810
                    value_out.emplace_back(
×
811
                        line_range{0, 1},
×
812
                        VC_STYLE.value(text_attrs::with_blink()));
×
813
                }
814
            }
815
            value_out.emplace_back(line_range{0, 1},
×
816
                                   VC_BACKGROUND.value(color));
×
817
        }
818

819
        auto sql_filter_opt = this->get_sql_filter();
1,144✔
820
        if (sql_filter_opt) {
1,144✔
821
            auto* sf = (sql_filter*) sql_filter_opt.value().get();
36✔
822
            auto eval_res = this->eval_sql_filter(sf->sf_filter_stmt.in(),
823
                                                  this->lss_token_file_data,
824
                                                  this->lss_token_line);
36✔
825
            if (eval_res.isErr()) {
36✔
826
                auto msg = fmt::format(
827
                    FMT_STRING(
×
828
                        "filter expression evaluation failed with -- {}"),
829
                    eval_res.unwrapErr().to_attr_line().get_string());
×
830
                auto cu = styling::color_unit::from_palette(palette_color{
×
831
                    lnav::enums::to_underlying(ansi_color::yellow)});
832
                value_out.emplace_back(line_range{0, -1}, SA_ERROR.value(msg));
×
833
                value_out.emplace_back(line_range{0, 1},
×
834
                                       VC_BACKGROUND.value(cu));
×
835
            }
836
        }
36✔
837
    }
1,144✔
838
}
839

840
struct logline_cmp {
841
    logline_cmp(logfile_sub_source& lc) : llss_controller(lc) {}
1,102✔
842

843
    bool operator()(const logfile_sub_source::indexed_content& lhs,
95,474✔
844
                    const logfile_sub_source::indexed_content& rhs) const
845
    {
846
        const auto* ll_lhs = this->llss_controller.find_line(lhs.value());
95,474✔
847
        const auto* ll_rhs = this->llss_controller.find_line(rhs.value());
95,474✔
848

849
        return (*ll_lhs) < (*ll_rhs);
95,474✔
850
    }
851

852
    bool operator()(const uint32_t& lhs, const uint32_t& rhs) const
853
    {
854
        auto cl_lhs = llss_controller.lss_index[lhs].value();
855
        auto cl_rhs = llss_controller.lss_index[rhs].value();
856
        const auto* ll_lhs = this->llss_controller.find_line(cl_lhs);
857
        const auto* ll_rhs = this->llss_controller.find_line(cl_rhs);
858

859
        return (*ll_lhs) < (*ll_rhs);
860
    }
861
#if 0
862
        bool operator()(const indexed_content &lhs, const indexed_content &rhs)
863
        {
864
            logline *ll_lhs = this->llss_controller.find_line(lhs.ic_value);
865
            logline *ll_rhs = this->llss_controller.find_line(rhs.ic_value);
866

867
            return (*ll_lhs) < (*ll_rhs);
868
        }
869
#endif
870

871
#if 0
872
    bool operator()(const content_line_t& lhs, const time_t& rhs) const
873
    {
874
        logline* ll_lhs = this->llss_controller.find_line(lhs);
875

876
        return *ll_lhs < rhs;
877
    }
878
#endif
879

880
    bool operator()(const logfile_sub_source::indexed_content& lhs,
×
881
                    const struct timeval& rhs) const
882
    {
883
        const auto* ll_lhs = this->llss_controller.find_line(lhs.value());
×
884

885
        return *ll_lhs < rhs;
×
886
    }
887

888
    logfile_sub_source& llss_controller;
889
};
890

891
logfile_sub_source::rebuild_result
892
logfile_sub_source::rebuild_index(std::optional<ui_clock::time_point> deadline)
4,281✔
893
{
894
    if (this->tss_view == nullptr) {
4,281✔
895
        return rebuild_result::rr_no_change;
122✔
896
    }
897

898
    this->lss_indexing_in_progress = true;
4,159✔
899
    auto fin = finally([this]() { this->lss_indexing_in_progress = false; });
4,159✔
900

901
    iterator iter;
4,159✔
902
    size_t total_lines = 0;
4,159✔
903
    size_t est_remaining_lines = 0;
4,159✔
904
    auto all_time_ordered_formats = true;
4,159✔
905
    auto full_sort = this->lss_index.empty();
4,159✔
906
    int file_count = 0;
4,159✔
907
    auto force = std::exchange(this->lss_force_rebuild, false);
4,159✔
908
    auto retval = rebuild_result::rr_no_change;
4,159✔
909
    std::optional<timeval> lowest_tv = std::nullopt;
4,159✔
910
    auto search_start = 0_vl;
4,159✔
911

912
    if (force) {
4,159✔
913
        log_debug("forced to full rebuild");
466✔
914
        retval = rebuild_result::rr_full_rebuild;
466✔
915
        full_sort = true;
466✔
916
    }
917

918
    std::vector<size_t> file_order(this->lss_files.size());
4,159✔
919

920
    for (size_t lpc = 0; lpc < file_order.size(); lpc++) {
7,064✔
921
        file_order[lpc] = lpc;
2,905✔
922
    }
923
    if (!this->lss_index.empty()) {
4,159✔
924
        std::stable_sort(file_order.begin(),
2,638✔
925
                         file_order.end(),
926
                         [this](const auto& left, const auto& right) {
241✔
927
                             const auto& left_ld = this->lss_files[left];
241✔
928
                             const auto& right_ld = this->lss_files[right];
241✔
929

930
                             if (left_ld->get_file_ptr() == nullptr) {
241✔
931
                                 return true;
×
932
                             }
933
                             if (right_ld->get_file_ptr() == nullptr) {
241✔
934
                                 return false;
4✔
935
                             }
936

937
                             return left_ld->get_file_ptr()->back()
237✔
938
                                 < right_ld->get_file_ptr()->back();
474✔
939
                         });
940
    }
941

942
    bool time_left = true;
4,159✔
943
    this->lss_all_timestamp_flags = 0;
4,159✔
944
    for (const auto file_index : file_order) {
7,064✔
945
        auto& ld = *(this->lss_files[file_index]);
2,905✔
946
        auto* lf = ld.get_file_ptr();
2,905✔
947

948
        if (lf == nullptr) {
2,905✔
949
            if (ld.ld_lines_indexed > 0) {
4✔
950
                log_debug("%d: file closed, doing full rebuild",
1✔
951
                          ld.ld_file_index);
952
                force = true;
1✔
953
                retval = rebuild_result::rr_full_rebuild;
1✔
954
                full_sort = true;
1✔
955
            }
956
        } else {
957
            if (!lf->get_format_ptr()->lf_time_ordered) {
2,901✔
958
                all_time_ordered_formats = false;
161✔
959
            }
960
            if (time_left && deadline && ui_clock::now() > deadline.value()) {
2,901✔
961
                log_debug("no time left, skipping %s",
2✔
962
                          lf->get_filename_as_string().c_str());
963
                time_left = false;
2✔
964
            }
965
            this->lss_all_timestamp_flags
2,901✔
966
                |= lf->get_format_ptr()->lf_timestamp_flags;
2,901✔
967

968
            if (!this->tss_view->is_paused() && time_left) {
2,901✔
969
                auto log_rebuild_res = lf->rebuild_index(deadline);
2,899✔
970

971
                if (ld.ld_lines_indexed < lf->size()
2,899✔
972
                    && log_rebuild_res
2,899✔
973
                        == logfile::rebuild_result_t::NO_NEW_LINES)
974
                {
975
                    // This is a bit awkward... if the logfile indexing was
976
                    // complete before being added to us, we need to adjust
977
                    // the rebuild result to make it look like new lines
978
                    // were added.
979
                    log_rebuild_res = logfile::rebuild_result_t::NEW_LINES;
50✔
980
                }
981
                switch (log_rebuild_res) {
2,899✔
982
                    case logfile::rebuild_result_t::NO_NEW_LINES:
2,373✔
983
                        break;
2,373✔
984
                    case logfile::rebuild_result_t::NEW_LINES:
474✔
985
                        if (retval == rebuild_result::rr_no_change) {
474✔
986
                            retval = rebuild_result::rr_appended_lines;
425✔
987
                        }
988
                        log_debug("new lines for %s:%d",
474✔
989
                                  lf->get_filename_as_string().c_str(),
990
                                  lf->size());
991
                        if (!this->lss_index.empty()
474✔
992
                            && lf->size() > ld.ld_lines_indexed)
474✔
993
                        {
994
                            auto& new_file_line = (*lf)[ld.ld_lines_indexed];
×
995
                            auto cl = this->lss_index.back().value();
×
996
                            auto* last_indexed_line = this->find_line(cl);
×
997

998
                            // If there are new lines that are older than what
999
                            // we have in the index, we need to resort.
1000
                            if (last_indexed_line == nullptr
×
1001
                                || new_file_line
×
1002
                                    < last_indexed_line->get_timeval())
×
1003
                            {
1004
                                log_debug(
×
1005
                                    "%s:%ld: found older lines, full "
1006
                                    "rebuild: %p  %lld < %lld",
1007
                                    lf->get_filename().c_str(),
1008
                                    ld.ld_lines_indexed,
1009
                                    last_indexed_line,
1010
                                    new_file_line
1011
                                        .get_time<std::chrono::microseconds>()
1012
                                        .count(),
1013
                                    last_indexed_line == nullptr
1014
                                        ? (uint64_t) -1
1015
                                        : last_indexed_line
1016
                                              ->get_time<
1017
                                                  std::chrono::microseconds>()
1018
                                              .count());
1019
                                if (retval <= rebuild_result::rr_partial_rebuild
×
1020
                                    && all_time_ordered_formats)
×
1021
                                {
1022
                                    retval = rebuild_result::rr_partial_rebuild;
×
1023
                                    if (!lowest_tv
×
1024
                                        || new_file_line.get_timeval()
×
1025
                                            < lowest_tv.value())
×
1026
                                    {
1027
                                        lowest_tv = new_file_line.get_timeval();
×
1028
                                    }
1029
                                } else {
1030
                                    log_debug(
×
1031
                                        "already doing full rebuild, doing "
1032
                                        "full_sort as well");
1033
                                    force = true;
×
1034
                                    full_sort = true;
×
1035
                                }
1036
                            }
1037
                        }
1038
                        break;
474✔
1039
                    case logfile::rebuild_result_t::INVALID:
52✔
1040
                    case logfile::rebuild_result_t::NEW_ORDER:
1041
                        log_debug("%s: log file has a new order, full rebuild",
52✔
1042
                                  lf->get_filename().c_str());
1043
                        retval = rebuild_result::rr_full_rebuild;
52✔
1044
                        force = true;
52✔
1045
                        full_sort = true;
52✔
1046
                        break;
52✔
1047
                }
1048
            }
1049
            file_count += 1;
2,901✔
1050
            total_lines += lf->size();
2,901✔
1051

1052
            est_remaining_lines += lf->estimated_remaining_lines();
2,901✔
1053
        }
1054
    }
1055

1056
    if (!all_time_ordered_formats
4,159✔
1057
        && retval == rebuild_result::rr_partial_rebuild)
155✔
1058
    {
1059
        force = true;
×
1060
        full_sort = true;
×
1061
        retval = rebuild_result::rr_full_rebuild;
×
1062
    }
1063

1064
    if (this->lss_index.reserve(total_lines + est_remaining_lines)) {
4,159✔
1065
        // The index array was reallocated, just do a full sort/rebuild since
1066
        // it's been cleared out.
1067
        log_debug("expanding index capacity %zu", this->lss_index.ba_capacity);
610✔
1068
        force = true;
610✔
1069
        retval = rebuild_result::rr_full_rebuild;
610✔
1070
        full_sort = true;
610✔
1071
    }
1072

1073
    auto& vis_bm = this->tss_view->get_bookmarks();
4,159✔
1074

1075
    if (force) {
4,159✔
1076
        for (iter = this->lss_files.begin(); iter != this->lss_files.end();
1,607✔
1077
             iter++)
517✔
1078
        {
1079
            (*iter)->ld_lines_indexed = 0;
517✔
1080
        }
1081

1082
        this->lss_index.clear();
1,090✔
1083
        this->lss_filtered_index.clear();
1,090✔
1084
        this->lss_longest_line = 0;
1,090✔
1085
        this->lss_basename_width = 0;
1,090✔
1086
        this->lss_filename_width = 0;
1,090✔
1087
        vis_bm[&textview_curses::BM_USER_EXPR].clear();
1,090✔
1088
        if (this->lss_index_delegate) {
1,090✔
1089
            this->lss_index_delegate->index_start(*this);
1,090✔
1090
        }
1091
    } else if (retval == rebuild_result::rr_partial_rebuild) {
3,069✔
1092
        size_t remaining = 0;
×
1093

1094
        log_debug("partial rebuild with lowest time: %ld",
×
1095
                  lowest_tv.value().tv_sec);
1096
        for (iter = this->lss_files.begin(); iter != this->lss_files.end();
×
1097
             iter++)
×
1098
        {
1099
            logfile_data& ld = *(*iter);
×
1100
            auto* lf = ld.get_file_ptr();
×
1101

1102
            if (lf == nullptr) {
×
1103
                continue;
×
1104
            }
1105

1106
            require(lf->get_format_ptr()->lf_time_ordered);
×
1107

1108
            auto line_iter = lf->find_from_time(lowest_tv.value());
×
1109

1110
            if (line_iter) {
×
1111
                log_debug("lowest line time %ld; line %ld; size %ld; path=%s",
×
1112
                          line_iter.value()->get_timeval().tv_sec,
1113
                          std::distance(lf->cbegin(), line_iter.value()),
1114
                          lf->size(),
1115
                          lf->get_filename_as_string().c_str());
1116
            }
1117
            ld.ld_lines_indexed
1118
                = std::distance(lf->cbegin(), line_iter.value_or(lf->cend()));
×
1119
            remaining += lf->size() - ld.ld_lines_indexed;
×
1120
        }
1121

1122
        auto* row_iter = std::lower_bound(this->lss_index.begin(),
×
1123
                                          this->lss_index.end(),
1124
                                          lowest_tv.value(),
×
1125
                                          logline_cmp(*this));
1126
        this->lss_index.shrink_to(
×
1127
            std::distance(this->lss_index.begin(), row_iter));
×
1128
        log_debug("new index size %ld/%ld; remain %ld",
×
1129
                  this->lss_index.ba_size,
1130
                  this->lss_index.ba_capacity,
1131
                  remaining);
1132
        auto filt_row_iter = std::lower_bound(this->lss_filtered_index.begin(),
×
1133
                                              this->lss_filtered_index.end(),
1134
                                              lowest_tv.value(),
×
1135
                                              filtered_logline_cmp(*this));
1136
        this->lss_filtered_index.resize(
×
1137
            std::distance(this->lss_filtered_index.begin(), filt_row_iter));
×
1138
        search_start = vis_line_t(this->lss_filtered_index.size());
×
1139

1140
        if (this->lss_index_delegate) {
×
1141
            this->lss_index_delegate->index_start(*this);
×
1142
            for (const auto row_in_full_index : this->lss_filtered_index) {
×
1143
                auto cl = this->lss_index[row_in_full_index].value();
×
1144
                uint64_t line_number;
1145
                auto ld_iter = this->find_data(cl, line_number);
×
1146
                auto& ld = *ld_iter;
×
1147
                auto line_iter = ld->get_file_ptr()->begin() + line_number;
×
1148

1149
                this->lss_index_delegate->index_line(
×
1150
                    *this, ld->get_file_ptr(), line_iter);
1151
            }
1152
        }
1153
    }
1154

1155
    if (this->lss_index.empty() && !time_left) {
4,159✔
1156
        log_info("ran out of time, skipping rebuild");
×
1157
        // need to make sure we rebuild in case no new data comes in
1158
        this->lss_force_rebuild = true;
×
1159
        return rebuild_result::rr_appended_lines;
×
1160
    }
1161

1162
    if (retval != rebuild_result::rr_no_change || force) {
4,159✔
1163
        size_t index_size = 0, start_size = this->lss_index.size();
1,102✔
1164
        logline_cmp line_cmper(*this);
1,102✔
1165

1166
        for (auto& ld : this->lss_files) {
1,638✔
1167
            auto* lf = ld->get_file_ptr();
536✔
1168

1169
            if (lf == nullptr) {
536✔
1170
                continue;
1✔
1171
            }
1172
            this->lss_longest_line = std::max(
1,070✔
1173
                this->lss_longest_line, lf->get_longest_line_length() + 1);
535✔
1174
            this->lss_basename_width
1175
                = std::max(this->lss_basename_width,
1,070✔
1176
                           lf->get_unique_path().native().size());
535✔
1177
            this->lss_filename_width = std::max(
1,070✔
1178
                this->lss_filename_width, lf->get_filename().native().size());
535✔
1179
        }
1180

1181
        if (full_sort) {
1,102✔
1182
            log_trace("rebuild_index full sort");
1,102✔
1183
            for (auto& ld : this->lss_files) {
1,638✔
1184
                auto* lf = ld->get_file_ptr();
536✔
1185

1186
                if (lf == nullptr) {
536✔
1187
                    continue;
1✔
1188
                }
1189

1190
                for (size_t line_index = 0; line_index < lf->size();
13,292✔
1191
                     line_index++)
1192
                {
1193
                    const auto lf_iter
1194
                        = ld->get_file_ptr()->begin() + line_index;
12,757✔
1195
                    if (lf_iter->is_ignored()) {
12,757✔
1196
                        continue;
233✔
1197
                    }
1198

1199
                    content_line_t con_line(
1200
                        ld->ld_file_index * MAX_LINES_PER_FILE + line_index);
12,524✔
1201

1202
                    if (lf_iter->is_meta_marked()) {
12,524✔
1203
                        auto start_iter = lf_iter;
12✔
1204
                        while (start_iter->is_continued()) {
12✔
1205
                            --start_iter;
×
1206
                        }
1207
                        int start_index
1208
                            = start_iter - ld->get_file_ptr()->begin();
12✔
1209
                        content_line_t start_con_line(ld->ld_file_index
12✔
1210
                                                          * MAX_LINES_PER_FILE
12✔
1211
                                                      + start_index);
12✔
1212

1213
                        auto& line_meta
1214
                            = ld->get_file_ptr()
1215
                                  ->get_bookmark_metadata()[start_index];
12✔
1216
                        if (line_meta.has(bookmark_metadata::categories::notes))
12✔
1217
                        {
1218
                            this->lss_user_marks[&textview_curses::BM_META]
4✔
1219
                                .insert_once(start_con_line);
4✔
1220
                        }
1221
                        if (line_meta.has(
12✔
1222
                                bookmark_metadata::categories::partition))
1223
                        {
1224
                            this->lss_user_marks[&textview_curses::BM_PARTITION]
8✔
1225
                                .insert_once(start_con_line);
8✔
1226
                        }
1227
                    }
1228
                    this->lss_index.push_back(
12,524✔
1229
                        indexed_content{con_line, lf_iter});
25,048✔
1230
                }
1231
            }
1232

1233
            // XXX get rid of this full sort on the initial run, it's not
1234
            // needed unless the file is not in time-order
1235
            if (this->lss_sorting_observer) {
1,102✔
1236
                this->lss_sorting_observer(*this, 0, this->lss_index.size());
3✔
1237
            }
1238
            std::sort(
1,102✔
1239
                this->lss_index.begin(), this->lss_index.end(), line_cmper);
1240
            if (this->lss_sorting_observer) {
1,102✔
1241
                this->lss_sorting_observer(
6✔
1242
                    *this, this->lss_index.size(), this->lss_index.size());
3✔
1243
            }
1244
        } else {
1245
            kmerge_tree_c<logline, logfile_data, logfile::iterator> merge(
1246
                file_count);
×
1247

1248
            for (iter = this->lss_files.begin(); iter != this->lss_files.end();
×
1249
                 iter++)
×
1250
            {
1251
                auto* ld = iter->get();
×
1252
                auto* lf = ld->get_file_ptr();
×
1253
                if (lf == nullptr) {
×
1254
                    continue;
×
1255
                }
1256

1257
                merge.add(ld, lf->begin() + ld->ld_lines_indexed, lf->end());
×
1258
                index_size += lf->size();
×
1259
            }
1260

1261
            file_off_t index_off = 0;
×
1262
            merge.execute();
×
1263
            if (this->lss_sorting_observer) {
×
1264
                this->lss_sorting_observer(*this, index_off, index_size);
×
1265
            }
1266
            log_trace("k-way merge");
×
1267
            for (;;) {
1268
                logfile::iterator lf_iter;
×
1269
                logfile_data* ld;
1270

1271
                if (!merge.get_top(ld, lf_iter)) {
×
1272
                    break;
×
1273
                }
1274

1275
                if (!lf_iter->is_ignored()) {
×
1276
                    int file_index = ld->ld_file_index;
×
1277
                    int line_index = lf_iter - ld->get_file_ptr()->begin();
×
1278

1279
                    content_line_t con_line(file_index * MAX_LINES_PER_FILE
×
1280
                                            + line_index);
×
1281

1282
                    if (lf_iter->is_meta_marked()) {
×
1283
                        auto start_iter = lf_iter;
×
1284
                        while (start_iter->is_continued()) {
×
1285
                            --start_iter;
×
1286
                        }
1287
                        int start_index
1288
                            = start_iter - ld->get_file_ptr()->begin();
×
1289
                        content_line_t start_con_line(
1290
                            file_index * MAX_LINES_PER_FILE + start_index);
×
1291

1292
                        auto& line_meta
1293
                            = ld->get_file_ptr()
1294
                                  ->get_bookmark_metadata()[start_index];
×
1295
                        if (line_meta.has(bookmark_metadata::categories::notes))
×
1296
                        {
1297
                            this->lss_user_marks[&textview_curses::BM_META]
×
1298
                                .insert_once(start_con_line);
×
1299
                        }
1300
                        if (line_meta.has(
×
1301
                                bookmark_metadata::categories::partition))
1302
                        {
1303
                            this->lss_user_marks[&textview_curses::BM_PARTITION]
×
1304
                                .insert_once(start_con_line);
×
1305
                        }
1306
                    }
1307
                    this->lss_index.push_back(
×
1308
                        indexed_content{con_line, lf_iter});
×
1309
                }
1310

1311
                merge.next();
×
1312
                index_off += 1;
×
1313
                if (index_off % 100000 == 0 && this->lss_sorting_observer) {
×
1314
                    this->lss_sorting_observer(*this, index_off, index_size);
×
1315
                }
1316
            }
1317
            if (this->lss_sorting_observer) {
×
1318
                this->lss_sorting_observer(*this, index_size, index_size);
×
1319
            }
1320
        }
1321

1322
        for (iter = this->lss_files.begin(); iter != this->lss_files.end();
1,638✔
1323
             ++iter)
536✔
1324
        {
1325
            auto* lf = (*iter)->get_file_ptr();
536✔
1326

1327
            if (lf == nullptr) {
536✔
1328
                continue;
1✔
1329
            }
1330

1331
            (*iter)->ld_lines_indexed = lf->size();
535✔
1332
        }
1333

1334
        this->lss_filtered_index.reserve(this->lss_index.size());
1,102✔
1335

1336
        uint32_t filter_in_mask, filter_out_mask;
1337
        this->get_filters().get_enabled_mask(filter_in_mask, filter_out_mask);
1,102✔
1338

1339
        if (start_size == 0 && this->lss_index_delegate != nullptr) {
1,102✔
1340
            this->lss_index_delegate->index_start(*this);
1,102✔
1341
        }
1342

1343
        log_trace("filtered index");
1,102✔
1344
        for (size_t index_index = start_size;
13,626✔
1345
             index_index < this->lss_index.size();
13,626✔
1346
             index_index++)
1347
        {
1348
            const auto cl = this->lss_index[index_index].value();
12,524✔
1349
            uint64_t line_number;
1350
            auto ld = this->find_data(cl, line_number);
12,524✔
1351

1352
            if (!(*ld)->is_visible()) {
12,524✔
1353
                continue;
×
1354
            }
1355

1356
            auto* lf = (*ld)->get_file_ptr();
12,524✔
1357
            auto line_iter = lf->begin() + line_number;
12,524✔
1358

1359
            if (line_iter->is_ignored()) {
12,524✔
1360
                continue;
×
1361
            }
1362

1363
            if (!this->tss_apply_filters
25,048✔
1364
                || (!(*ld)->ld_filter_state.excluded(
25,020✔
1365
                        filter_in_mask, filter_out_mask, line_number)
1366
                    && this->check_extra_filters(ld, line_iter)))
12,496✔
1367
            {
1368
                auto eval_res = this->eval_sql_filter(
1369
                    this->lss_marker_stmt.in(), ld, line_iter);
12,496✔
1370
                if (eval_res.isErr()) {
12,496✔
1371
                    line_iter->set_expr_mark(false);
×
1372
                } else {
1373
                    auto matched = eval_res.unwrap();
12,496✔
1374

1375
                    if (matched) {
12,496✔
1376
                        line_iter->set_expr_mark(true);
×
1377
                        vis_bm[&textview_curses::BM_USER_EXPR].insert_once(
×
1378
                            vis_line_t(this->lss_filtered_index.size()));
×
1379
                    } else {
1380
                        line_iter->set_expr_mark(false);
12,496✔
1381
                    }
1382
                }
1383
                this->lss_filtered_index.push_back(index_index);
12,496✔
1384
                if (this->lss_index_delegate != nullptr) {
12,496✔
1385
                    this->lss_index_delegate->index_line(*this, lf, line_iter);
12,496✔
1386
                }
1387
            }
12,496✔
1388
        }
1389

1390
        this->lss_indexing_in_progress = false;
1,102✔
1391

1392
        if (this->lss_index_delegate != nullptr) {
1,102✔
1393
            this->lss_index_delegate->index_complete(*this);
1,102✔
1394
        }
1395
    }
1396

1397
    switch (retval) {
4,159✔
1398
        case rebuild_result::rr_no_change:
3,057✔
1399
            break;
3,057✔
1400
        case rebuild_result::rr_full_rebuild:
1,090✔
1401
            log_debug("redoing search");
1,090✔
1402
            this->lss_index_generation += 1;
1,090✔
1403
            this->tss_view->reload_data();
1,090✔
1404
            this->tss_view->redo_search();
1,090✔
1405
            break;
1,090✔
1406
        case rebuild_result::rr_partial_rebuild:
×
1407
            log_debug("redoing search from: %d", (int) search_start);
×
1408
            this->lss_index_generation += 1;
×
1409
            this->tss_view->reload_data();
×
1410
            this->tss_view->search_new_data(search_start);
×
1411
            break;
×
1412
        case rebuild_result::rr_appended_lines:
12✔
1413
            this->tss_view->reload_data();
12✔
1414
            this->tss_view->search_new_data();
12✔
1415
            break;
12✔
1416
    }
1417

1418
    return retval;
4,159✔
1419
}
4,159✔
1420

1421
void
1422
logfile_sub_source::text_update_marks(vis_bookmarks& bm)
2,123✔
1423
{
1424
    logfile* last_file = nullptr;
2,123✔
1425
    vis_line_t vl;
2,123✔
1426

1427
    auto& bm_warnings = bm[&textview_curses::BM_WARNINGS];
2,123✔
1428
    auto& bm_errors = bm[&textview_curses::BM_ERRORS];
2,123✔
1429
    auto& bm_files = bm[&BM_FILES];
2,123✔
1430

1431
    bm_warnings.clear();
2,123✔
1432
    bm_errors.clear();
2,123✔
1433
    bm_files.clear();
2,123✔
1434

1435
    std::vector<const bookmark_type_t*> used_marks;
2,123✔
1436
    for (const auto* bmt : {
10,615✔
1437
             &textview_curses::BM_USER,
1438
             &textview_curses::BM_USER_EXPR,
1439
             &textview_curses::BM_PARTITION,
1440
             &textview_curses::BM_META,
1441
         })
12,738✔
1442
    {
1443
        bm[bmt].clear();
8,492✔
1444
        if (!this->lss_user_marks[bmt].empty()) {
8,492✔
1445
            used_marks.emplace_back(bmt);
113✔
1446
        }
1447
    }
1448

1449
    for (; vl < (int) this->lss_filtered_index.size(); ++vl) {
16,541✔
1450
        const auto& orig_ic = this->lss_index[this->lss_filtered_index[vl]];
14,418✔
1451
        auto cl = orig_ic.value();
14,418✔
1452
        auto* lf = this->find_file_ptr(cl);
14,418✔
1453

1454
        for (const auto& bmt : used_marks) {
15,916✔
1455
            auto& user_mark = this->lss_user_marks[bmt];
1,498✔
1456
            if (user_mark.bv_tree.exists(orig_ic.value())) {
1,498✔
1457
                bm[bmt].insert_once(vl);
126✔
1458

1459
                if (bmt == &textview_curses::BM_USER) {
126✔
1460
                    auto ll = lf->begin() + cl;
40✔
1461

1462
                    ll->set_mark(true);
40✔
1463
                }
1464
            }
1465
        }
1466

1467
        if (lf != last_file) {
14,418✔
1468
            bm_files.insert_once(vl);
930✔
1469
        }
1470

1471
        switch (orig_ic.level()) {
14,418✔
1472
            case indexed_content::level_t::warning:
94✔
1473
                bm_warnings.insert_once(vl);
94✔
1474
                break;
94✔
1475

1476
            case indexed_content::level_t::error:
1,034✔
1477
                bm_errors.insert_once(vl);
1,034✔
1478
                break;
1,034✔
1479

1480
            default:
13,290✔
1481
                break;
13,290✔
1482
        }
1483

1484
        last_file = lf;
14,418✔
1485
    }
1486
}
2,123✔
1487

1488
void
1489
logfile_sub_source::text_filters_changed()
160✔
1490
{
1491
    this->lss_index_generation += 1;
160✔
1492

1493
    if (this->lss_line_meta_changed) {
160✔
1494
        this->invalidate_sql_filter();
24✔
1495
        this->lss_line_meta_changed = false;
24✔
1496
    }
1497

1498
    for (auto& ld : *this) {
272✔
1499
        auto* lf = ld->get_file_ptr();
112✔
1500

1501
        if (lf != nullptr) {
112✔
1502
            ld->ld_filter_state.clear_deleted_filter_state();
112✔
1503
            lf->reobserve_from(lf->begin()
112✔
1504
                               + ld->ld_filter_state.get_min_count(lf->size()));
112✔
1505
        }
1506
    }
1507

1508
    if (this->lss_force_rebuild) {
160✔
1509
        return;
×
1510
    }
1511

1512
    auto& vis_bm = this->tss_view->get_bookmarks();
160✔
1513
    uint32_t filtered_in_mask, filtered_out_mask;
1514

1515
    this->get_filters().get_enabled_mask(filtered_in_mask, filtered_out_mask);
160✔
1516

1517
    if (this->lss_index_delegate != nullptr) {
160✔
1518
        this->lss_index_delegate->index_start(*this);
160✔
1519
    }
1520
    vis_bm[&textview_curses::BM_USER_EXPR].clear();
160✔
1521

1522
    this->lss_filtered_index.clear();
160✔
1523
    for (size_t index_index = 0; index_index < this->lss_index.size();
1,056✔
1524
         index_index++)
1525
    {
1526
        auto cl = this->lss_index[index_index].value();
896✔
1527
        uint64_t line_number;
1528
        auto ld = this->find_data(cl, line_number);
896✔
1529

1530
        if (!(*ld)->is_visible()) {
896✔
1531
            continue;
210✔
1532
        }
1533

1534
        auto lf = (*ld)->get_file_ptr();
686✔
1535
        auto line_iter = lf->begin() + line_number;
686✔
1536

1537
        if (!this->tss_apply_filters
1,372✔
1538
            || (!(*ld)->ld_filter_state.excluded(
1,234✔
1539
                    filtered_in_mask, filtered_out_mask, line_number)
1540
                && this->check_extra_filters(ld, line_iter)))
548✔
1541
        {
1542
            auto eval_res = this->eval_sql_filter(
1543
                this->lss_marker_stmt.in(), ld, line_iter);
539✔
1544
            if (eval_res.isErr()) {
539✔
1545
                line_iter->set_expr_mark(false);
×
1546
            } else {
1547
                auto matched = eval_res.unwrap();
539✔
1548

1549
                if (matched) {
539✔
1550
                    line_iter->set_expr_mark(true);
×
1551
                    vis_bm[&textview_curses::BM_USER_EXPR].insert_once(
×
1552
                        vis_line_t(this->lss_filtered_index.size()));
×
1553
                } else {
1554
                    line_iter->set_expr_mark(false);
539✔
1555
                }
1556
            }
1557
            this->lss_filtered_index.push_back(index_index);
539✔
1558
            if (this->lss_index_delegate != nullptr) {
539✔
1559
                this->lss_index_delegate->index_line(*this, lf, line_iter);
539✔
1560
            }
1561
        }
539✔
1562
    }
1563

1564
    if (this->lss_index_delegate != nullptr) {
160✔
1565
        this->lss_index_delegate->index_complete(*this);
160✔
1566
    }
1567

1568
    if (this->tss_view != nullptr) {
160✔
1569
        this->tss_view->reload_data();
160✔
1570
        this->tss_view->redo_search();
160✔
1571
    }
1572
}
1573

1574
std::optional<json_string>
1575
logfile_sub_source::text_row_details(const textview_curses& tc)
28✔
1576
{
1577
    if (this->lss_index.empty()) {
28✔
1578
        log_trace("logfile_sub_source::text_row_details empty");
1✔
1579
        return std::nullopt;
1✔
1580
    }
1581

1582
    auto ov_sel = tc.get_overlay_selection();
27✔
1583
    if (ov_sel.has_value()) {
27✔
1584
        auto* fos
1585
            = dynamic_cast<field_overlay_source*>(tc.get_overlay_source());
×
1586
        auto iter = fos->fos_row_to_field_meta.find(ov_sel.value());
×
1587
        if (iter != fos->fos_row_to_field_meta.end()) {
×
1588
            auto find_res = this->find_line_with_file(tc.get_top());
×
1589
            if (find_res) {
×
1590
                yajlpp_gen gen;
×
1591

1592
                {
1593
                    yajlpp_map root(gen);
×
1594

1595
                    root.gen("value");
×
1596
                    root.gen(iter->second.ri_value);
×
1597
                }
1598

1599
                return json_string(gen);
×
1600
            }
1601
        }
1602
    }
1603

1604
    return std::nullopt;
27✔
1605
}
1606

1607
bool
1608
logfile_sub_source::list_input_handle_key(listview_curses& lv,
3✔
1609
                                          const ncinput& ch)
1610
{
1611
    switch (ch.eff_text[0]) {
3✔
1612
        case ' ': {
×
1613
            auto ov_vl = lv.get_overlay_selection();
×
1614
            if (ov_vl) {
×
1615
                auto* fos = dynamic_cast<field_overlay_source*>(
×
1616
                    lv.get_overlay_source());
×
1617
                auto iter = fos->fos_row_to_field_meta.find(ov_vl.value());
×
1618
                if (iter != fos->fos_row_to_field_meta.end()
×
1619
                    && iter->second.ri_meta)
×
1620
                {
1621
                    auto find_res = this->find_line_with_file(lv.get_top());
×
1622
                    if (find_res) {
×
1623
                        auto file_and_line = find_res.value();
×
1624
                        auto* format = file_and_line.first->get_format_ptr();
×
1625
                        auto fstates = format->get_field_states();
×
1626
                        auto state_iter
1627
                            = fstates.find(iter->second.ri_meta->lvm_name);
×
1628
                        if (state_iter != fstates.end()) {
×
1629
                            format->hide_field(iter->second.ri_meta->lvm_name,
×
1630
                                               !state_iter->second.is_hidden());
×
1631
                            lv.set_needs_update();
×
1632
                        }
1633
                    }
1634
                }
1635
                return true;
×
1636
            }
1637
            return false;
×
1638
        }
1639
        case '#': {
×
1640
            auto ov_vl = lv.get_overlay_selection();
×
1641
            if (ov_vl) {
×
1642
                auto* fos = dynamic_cast<field_overlay_source*>(
×
1643
                    lv.get_overlay_source());
×
1644
                auto iter = fos->fos_row_to_field_meta.find(ov_vl.value());
×
1645
                if (iter != fos->fos_row_to_field_meta.end()
×
1646
                    && iter->second.ri_meta)
×
1647
                {
1648
                    const auto& meta = iter->second.ri_meta.value();
×
1649
                    std::string cmd;
×
1650

1651
                    switch (meta.to_chart_type()) {
×
1652
                        case chart_type_t::none:
×
1653
                            break;
×
1654
                        case chart_type_t::hist: {
×
1655
                            auto prql = fmt::format(
1656
                                FMT_STRING(
×
1657
                                    "from {} | stats.hist {} slice:'1h'"),
1658
                                meta.lvm_format.value()->get_name(),
×
1659
                                meta.lvm_name);
×
1660
                            cmd = fmt::format(FMT_STRING(":prompt sql ; '{}'"),
×
1661
                                              shlex::escape(prql));
×
1662
                            break;
×
1663
                        }
1664
                        case chart_type_t::spectro:
×
1665
                            cmd = fmt::format(FMT_STRING(":spectrogram {}"),
×
1666
                                              meta.lvm_name);
×
1667
                            break;
×
1668
                    }
1669
                    if (!cmd.empty()) {
×
1670
                        this->lss_exec_context
×
1671
                            ->with_provenance(exec_context::mouse_input{})
×
1672
                            ->execute(INTERNAL_SRC_LOC, cmd);
×
1673
                    }
1674
                }
1675
                return true;
×
1676
            }
1677
            return false;
×
1678
        }
1679
        case 'h':
×
1680
        case 'H':
1681
        case NCKEY_LEFT:
1682
            if (lv.get_left() == 0) {
×
1683
                this->increase_line_context();
×
1684
                lv.set_needs_update();
×
1685
                return true;
×
1686
            }
1687
            break;
×
1688
        case 'l':
×
1689
        case 'L':
1690
        case NCKEY_RIGHT:
1691
            if (this->decrease_line_context()) {
×
1692
                lv.set_needs_update();
×
1693
                return true;
×
1694
            }
1695
            break;
×
1696
    }
1697
    return false;
3✔
1698
}
1699

1700
std::optional<
1701
    std::pair<grep_proc_source<vis_line_t>*, grep_proc_sink<vis_line_t>*>>
1702
logfile_sub_source::get_grepper()
9✔
1703
{
1704
    return std::make_pair(
18✔
1705
        (grep_proc_source<vis_line_t>*) &this->lss_meta_grepper,
×
1706
        (grep_proc_sink<vis_line_t>*) &this->lss_meta_grepper);
9✔
1707
}
1708

1709
/**
1710
 * Functor for comparing the ld_file field of the logfile_data struct.
1711
 */
1712
struct logfile_data_eq {
1713
    explicit logfile_data_eq(std::shared_ptr<logfile> lf)
1,008✔
1714
        : lde_file(std::move(lf))
1,008✔
1715
    {
1716
    }
1,008✔
1717

1718
    bool operator()(
618✔
1719
        const std::unique_ptr<logfile_sub_source::logfile_data>& ld) const
1720
    {
1721
        return this->lde_file == ld->get_file();
618✔
1722
    }
1723

1724
    std::shared_ptr<logfile> lde_file;
1725
};
1726

1727
bool
1728
logfile_sub_source::insert_file(const std::shared_ptr<logfile>& lf)
504✔
1729
{
1730
    iterator existing;
504✔
1731

1732
    require_lt(lf->size(), MAX_LINES_PER_FILE);
504✔
1733

1734
    existing = std::find_if(this->lss_files.begin(),
504✔
1735
                            this->lss_files.end(),
1736
                            logfile_data_eq(nullptr));
1,008✔
1737
    if (existing == this->lss_files.end()) {
504✔
1738
        if (this->lss_files.size() >= MAX_FILES) {
504✔
1739
            return false;
×
1740
        }
1741

1742
        auto ld = std::make_unique<logfile_data>(
1743
            this->lss_files.size(), this->get_filters(), lf);
504✔
1744
        ld->set_visibility(lf->get_open_options().loo_is_visible);
504✔
1745
        this->lss_files.push_back(std::move(ld));
504✔
1746
    } else {
504✔
1747
        (*existing)->set_file(lf);
×
1748
    }
1749

1750
    return true;
504✔
1751
}
1752

1753
Result<void, lnav::console::user_message>
1754
logfile_sub_source::set_sql_filter(std::string stmt_str, sqlite3_stmt* stmt)
745✔
1755
{
1756
    if (stmt != nullptr && !this->lss_filtered_index.empty()) {
745✔
1757
        auto top_cl = this->at(0_vl);
7✔
1758
        auto ld = this->find_data(top_cl);
7✔
1759
        auto eval_res
1760
            = this->eval_sql_filter(stmt, ld, (*ld)->get_file_ptr()->begin());
7✔
1761

1762
        if (eval_res.isErr()) {
7✔
1763
            sqlite3_finalize(stmt);
1✔
1764
            return Err(eval_res.unwrapErr());
1✔
1765
        }
1766
    }
7✔
1767

1768
    for (auto& ld : *this) {
759✔
1769
        ld->ld_filter_state.lfo_filter_state.clear_filter_state(0);
15✔
1770
    }
1771

1772
    auto old_filter = this->get_sql_filter();
744✔
1773
    if (stmt != nullptr) {
744✔
1774
        auto new_filter
1775
            = std::make_shared<sql_filter>(*this, std::move(stmt_str), stmt);
6✔
1776

1777
        if (old_filter) {
6✔
1778
            auto existing_iter = std::find(this->tss_filters.begin(),
×
1779
                                           this->tss_filters.end(),
1780
                                           old_filter.value());
×
1781
            *existing_iter = new_filter;
×
1782
        } else {
1783
            this->tss_filters.add_filter(new_filter);
6✔
1784
        }
1785
    } else if (old_filter) {
744✔
1786
        this->tss_filters.delete_filter(old_filter.value()->get_id());
6✔
1787
    }
1788

1789
    return Ok();
744✔
1790
}
744✔
1791

1792
Result<void, lnav::console::user_message>
1793
logfile_sub_source::set_sql_marker(std::string stmt_str, sqlite3_stmt* stmt)
740✔
1794
{
1795
    if (stmt != nullptr && !this->lss_filtered_index.empty()) {
740✔
1796
        auto top_cl = this->at(0_vl);
2✔
1797
        auto ld = this->find_data(top_cl);
2✔
1798
        auto eval_res
1799
            = this->eval_sql_filter(stmt, ld, (*ld)->get_file_ptr()->begin());
2✔
1800

1801
        if (eval_res.isErr()) {
2✔
1802
            sqlite3_finalize(stmt);
×
1803
            return Err(eval_res.unwrapErr());
×
1804
        }
1805
    }
2✔
1806

1807
    this->lss_marker_stmt_text = std::move(stmt_str);
740✔
1808
    this->lss_marker_stmt = stmt;
740✔
1809

1810
    if (this->tss_view == nullptr || this->lss_force_rebuild) {
740✔
1811
        return Ok();
128✔
1812
    }
1813

1814
    auto& vis_bm = this->tss_view->get_bookmarks();
612✔
1815
    auto& expr_marks_bv = vis_bm[&textview_curses::BM_USER_EXPR];
612✔
1816

1817
    expr_marks_bv.clear();
612✔
1818
    if (this->lss_index_delegate) {
612✔
1819
        this->lss_index_delegate->index_start(*this);
612✔
1820
    }
1821
    for (auto row = 0_vl; row < vis_line_t(this->lss_filtered_index.size());
619✔
1822
         row += 1_vl)
7✔
1823
    {
1824
        auto cl = this->at(row);
7✔
1825
        auto ld = this->find_data(cl);
7✔
1826

1827
        if (!(*ld)->is_visible()) {
7✔
1828
            continue;
1✔
1829
        }
1830
        auto ll = (*ld)->get_file()->begin() + cl;
7✔
1831
        if (ll->is_continued() || ll->is_ignored()) {
7✔
1832
            continue;
1✔
1833
        }
1834
        auto eval_res
1835
            = this->eval_sql_filter(this->lss_marker_stmt.in(), ld, ll);
6✔
1836

1837
        if (eval_res.isErr()) {
6✔
1838
            ll->set_expr_mark(false);
×
1839
        } else {
1840
            auto matched = eval_res.unwrap();
6✔
1841

1842
            if (matched) {
6✔
1843
                ll->set_expr_mark(true);
4✔
1844
                expr_marks_bv.insert_once(row);
4✔
1845
            } else {
1846
                ll->set_expr_mark(false);
2✔
1847
            }
1848
        }
1849
        if (this->lss_index_delegate) {
6✔
1850
            this->lss_index_delegate->index_line(
6✔
1851
                *this, (*ld)->get_file_ptr(), ll);
6✔
1852
        }
1853
    }
6✔
1854
    if (this->lss_index_delegate) {
612✔
1855
        this->lss_index_delegate->index_complete(*this);
612✔
1856
    }
1857

1858
    return Ok();
612✔
1859
}
1860

1861
Result<void, lnav::console::user_message>
1862
logfile_sub_source::set_preview_sql_filter(sqlite3_stmt* stmt)
738✔
1863
{
1864
    if (stmt != nullptr && !this->lss_filtered_index.empty()) {
738✔
1865
        auto top_cl = this->at(0_vl);
×
1866
        auto ld = this->find_data(top_cl);
×
1867
        auto eval_res
1868
            = this->eval_sql_filter(stmt, ld, (*ld)->get_file_ptr()->begin());
×
1869

1870
        if (eval_res.isErr()) {
×
1871
            sqlite3_finalize(stmt);
×
1872
            return Err(eval_res.unwrapErr());
×
1873
        }
1874
    }
1875

1876
    this->lss_preview_filter_stmt = stmt;
738✔
1877

1878
    return Ok();
738✔
1879
}
1880

1881
Result<bool, lnav::console::user_message>
1882
logfile_sub_source::eval_sql_filter(sqlite3_stmt* stmt,
13,220✔
1883
                                    iterator ld,
1884
                                    logfile::const_iterator ll)
1885
{
1886
    if (stmt == nullptr) {
13,220✔
1887
        return Ok(false);
26,070✔
1888
    }
1889

1890
    auto* lf = (*ld)->get_file_ptr();
185✔
1891
    char timestamp_buffer[64];
1892
    shared_buffer_ref raw_sbr;
185✔
1893
    logline_value_vector values;
185✔
1894
    auto& sbr = values.lvv_sbr;
185✔
1895
    lf->read_full_message(ll, sbr);
185✔
1896
    sbr.erase_ansi();
185✔
1897
    auto format = lf->get_format();
185✔
1898
    string_attrs_t sa;
185✔
1899
    auto line_number = std::distance(lf->cbegin(), ll);
185✔
1900
    format->annotate(lf, line_number, sa, values);
185✔
1901

1902
    sqlite3_reset(stmt);
185✔
1903
    sqlite3_clear_bindings(stmt);
185✔
1904

1905
    auto count = sqlite3_bind_parameter_count(stmt);
185✔
1906
    for (int lpc = 0; lpc < count; lpc++) {
382✔
1907
        const auto* name = sqlite3_bind_parameter_name(stmt, lpc + 1);
197✔
1908

1909
        if (name[0] == '$') {
197✔
1910
            const char* env_value;
1911

1912
            if ((env_value = getenv(&name[1])) != nullptr) {
4✔
1913
                sqlite3_bind_text(stmt, lpc + 1, env_value, -1, SQLITE_STATIC);
1✔
1914
            }
1915
            continue;
4✔
1916
        }
4✔
1917
        if (strcmp(name, ":log_level") == 0) {
193✔
1918
            auto lvl = ll->get_level_name();
6✔
1919
            sqlite3_bind_text(
6✔
1920
                stmt, lpc + 1, lvl.data(), lvl.length(), SQLITE_STATIC);
1921
            continue;
6✔
1922
        }
6✔
1923
        if (strcmp(name, ":log_time") == 0) {
187✔
1924
            auto len = sql_strftime(timestamp_buffer,
×
1925
                                    sizeof(timestamp_buffer),
1926
                                    ll->get_timeval(),
×
1927
                                    'T');
1928
            sqlite3_bind_text(
×
1929
                stmt, lpc + 1, timestamp_buffer, len, SQLITE_STATIC);
1930
            continue;
×
1931
        }
1932
        if (strcmp(name, ":log_time_msecs") == 0) {
187✔
1933
            sqlite3_bind_int64(
1✔
1934
                stmt,
1935
                lpc + 1,
1936
                ll->get_time<std::chrono::milliseconds>().count());
1✔
1937
            continue;
1✔
1938
        }
1939
        if (strcmp(name, ":log_mark") == 0) {
186✔
1940
            sqlite3_bind_int(stmt, lpc + 1, ll->is_marked());
×
1941
            continue;
×
1942
        }
1943
        if (strcmp(name, ":log_comment") == 0) {
186✔
1944
            const auto& bm = lf->get_bookmark_metadata();
×
1945
            auto line_number
1946
                = static_cast<uint32_t>(std::distance(lf->cbegin(), ll));
×
1947
            auto bm_iter = bm.find(line_number);
×
1948
            if (bm_iter != bm.end() && !bm_iter->second.bm_comment.empty()) {
×
1949
                const auto& meta = bm_iter->second;
×
1950
                sqlite3_bind_text(stmt,
×
1951
                                  lpc + 1,
1952
                                  meta.bm_comment.c_str(),
1953
                                  meta.bm_comment.length(),
×
1954
                                  SQLITE_STATIC);
1955
            }
1956
            continue;
×
1957
        }
1958
        if (strcmp(name, ":log_annotations") == 0) {
186✔
1959
            const auto& bm = lf->get_bookmark_metadata();
×
1960
            auto line_number
1961
                = static_cast<uint32_t>(std::distance(lf->cbegin(), ll));
×
1962
            auto bm_iter = bm.find(line_number);
×
1963
            if (bm_iter != bm.end()
×
1964
                && !bm_iter->second.bm_annotations.la_pairs.empty())
×
1965
            {
1966
                const auto& meta = bm_iter->second;
×
1967
                auto anno_str = logmsg_annotations_handlers.to_string(
1968
                    meta.bm_annotations);
×
1969

1970
                sqlite3_bind_text(stmt,
×
1971
                                  lpc + 1,
1972
                                  anno_str.c_str(),
1973
                                  anno_str.length(),
×
1974
                                  SQLITE_TRANSIENT);
1975
            }
1976
            continue;
×
1977
        }
1978
        if (strcmp(name, ":log_tags") == 0) {
186✔
1979
            const auto& bm = lf->get_bookmark_metadata();
9✔
1980
            auto line_number
1981
                = static_cast<uint32_t>(std::distance(lf->cbegin(), ll));
9✔
1982
            auto bm_iter = bm.find(line_number);
9✔
1983
            if (bm_iter != bm.end() && !bm_iter->second.bm_tags.empty()) {
9✔
1984
                const auto& meta = bm_iter->second;
1✔
1985
                yajlpp_gen gen;
1✔
1986

1987
                yajl_gen_config(gen, yajl_gen_beautify, false);
1✔
1988

1989
                {
1990
                    yajlpp_array arr(gen);
1✔
1991

1992
                    for (const auto& str : meta.bm_tags) {
2✔
1993
                        arr.gen(str);
1✔
1994
                    }
1995
                }
1✔
1996

1997
                string_fragment sf = gen.to_string_fragment();
1✔
1998

1999
                sqlite3_bind_text(
1✔
2000
                    stmt, lpc + 1, sf.data(), sf.length(), SQLITE_TRANSIENT);
2001
            }
1✔
2002
            continue;
9✔
2003
        }
9✔
2004
        if (strcmp(name, ":log_format") == 0) {
177✔
2005
            const auto format_name = format->get_name();
6✔
2006
            sqlite3_bind_text(stmt,
6✔
2007
                              lpc + 1,
2008
                              format_name.get(),
2009
                              format_name.size(),
6✔
2010
                              SQLITE_STATIC);
2011
            continue;
6✔
2012
        }
6✔
2013
        if (strcmp(name, ":log_format_regex") == 0) {
171✔
2014
            const auto pat_name = format->get_pattern_name(line_number);
×
2015
            sqlite3_bind_text(
×
2016
                stmt, lpc + 1, pat_name.get(), pat_name.size(), SQLITE_STATIC);
×
2017
            continue;
×
2018
        }
2019
        if (strcmp(name, ":log_path") == 0) {
171✔
2020
            const auto& filename = lf->get_filename();
×
2021
            sqlite3_bind_text(stmt,
×
2022
                              lpc + 1,
2023
                              filename.c_str(),
2024
                              filename.native().length(),
×
2025
                              SQLITE_STATIC);
2026
            continue;
×
2027
        }
2028
        if (strcmp(name, ":log_unique_path") == 0) {
171✔
2029
            const auto& filename = lf->get_unique_path();
×
2030
            sqlite3_bind_text(stmt,
×
2031
                              lpc + 1,
2032
                              filename.c_str(),
2033
                              filename.native().length(),
×
2034
                              SQLITE_STATIC);
2035
            continue;
×
2036
        }
2037
        if (strcmp(name, ":log_text") == 0) {
171✔
2038
            sqlite3_bind_text(
4✔
2039
                stmt, lpc + 1, sbr.get_data(), sbr.length(), SQLITE_STATIC);
4✔
2040
            continue;
4✔
2041
        }
2042
        if (strcmp(name, ":log_body") == 0) {
167✔
2043
            auto body_attr_opt = get_string_attr(sa, SA_BODY);
16✔
2044
            if (body_attr_opt) {
16✔
2045
                const auto& sar
2046
                    = body_attr_opt.value().saw_string_attr->sa_range;
16✔
2047

2048
                sqlite3_bind_text(stmt,
32✔
2049
                                  lpc + 1,
2050
                                  sbr.get_data_at(sar.lr_start),
16✔
2051
                                  sar.length(),
2052
                                  SQLITE_STATIC);
2053
            } else {
2054
                sqlite3_bind_null(stmt, lpc + 1);
×
2055
            }
2056
            continue;
16✔
2057
        }
16✔
2058
        if (strcmp(name, ":log_opid") == 0) {
151✔
2059
            if (values.lvv_opid_value) {
×
2060
                sqlite3_bind_text(stmt,
×
2061
                                  lpc + 1,
2062
                                  values.lvv_opid_value->c_str(),
2063
                                  values.lvv_opid_value->length(),
×
2064
                                  SQLITE_STATIC);
2065
            } else {
2066
                sqlite3_bind_null(stmt, lpc + 1);
×
2067
            }
2068
            continue;
×
2069
        }
2070
        if (strcmp(name, ":log_raw_text") == 0) {
151✔
2071
            auto res = lf->read_raw_message(ll);
×
2072

2073
            if (res.isOk()) {
×
2074
                raw_sbr = res.unwrap();
×
2075
                sqlite3_bind_text(stmt,
×
2076
                                  lpc + 1,
2077
                                  raw_sbr.get_data(),
2078
                                  raw_sbr.length(),
×
2079
                                  SQLITE_STATIC);
2080
            }
2081
            continue;
×
2082
        }
2083
        for (const auto& lv : values.lvv_values) {
412✔
2084
            if (lv.lv_meta.lvm_name != &name[1]) {
409✔
2085
                continue;
261✔
2086
            }
2087

2088
            switch (lv.lv_meta.lvm_kind) {
148✔
2089
                case value_kind_t::VALUE_BOOLEAN:
×
2090
                    sqlite3_bind_int64(stmt, lpc + 1, lv.lv_value.i);
×
2091
                    break;
×
2092
                case value_kind_t::VALUE_FLOAT:
×
2093
                    sqlite3_bind_double(stmt, lpc + 1, lv.lv_value.d);
×
2094
                    break;
×
2095
                case value_kind_t::VALUE_INTEGER:
12✔
2096
                    sqlite3_bind_int64(stmt, lpc + 1, lv.lv_value.i);
12✔
2097
                    break;
12✔
2098
                case value_kind_t::VALUE_NULL:
×
2099
                    sqlite3_bind_null(stmt, lpc + 1);
×
2100
                    break;
×
2101
                default:
136✔
2102
                    sqlite3_bind_text(stmt,
136✔
2103
                                      lpc + 1,
2104
                                      lv.text_value(),
2105
                                      lv.text_length(),
136✔
2106
                                      SQLITE_TRANSIENT);
2107
                    break;
136✔
2108
            }
2109
            break;
148✔
2110
        }
2111
    }
2112

2113
    auto step_res = sqlite3_step(stmt);
185✔
2114

2115
    sqlite3_reset(stmt);
185✔
2116
    sqlite3_clear_bindings(stmt);
185✔
2117
    switch (step_res) {
185✔
2118
        case SQLITE_OK:
64✔
2119
        case SQLITE_DONE:
2120
            return Ok(false);
128✔
2121
        case SQLITE_ROW:
120✔
2122
            return Ok(true);
240✔
2123
        default:
1✔
2124
            return Err(sqlite3_error_to_user_message(sqlite3_db_handle(stmt)));
1✔
2125
    }
2126
}
185✔
2127

2128
bool
2129
logfile_sub_source::check_extra_filters(iterator ld, logfile::iterator ll)
13,044✔
2130
{
2131
    if (this->lss_marked_only) {
13,044✔
2132
        auto found_mark = ll->is_marked() || ll->is_expr_marked();
6✔
2133
        auto to_start_ll = ll;
6✔
2134
        while (!found_mark && to_start_ll->is_continued()) {
6✔
2135
            if (to_start_ll->is_marked() || to_start_ll->is_expr_marked()) {
×
2136
                found_mark = true;
×
2137
            }
2138
            --to_start_ll;
×
2139
        }
2140
        auto to_end_ll = std::next(ll);
6✔
2141
        while (!found_mark && to_end_ll != (*ld)->get_file_ptr()->end()
10✔
2142
               && to_end_ll->is_continued())
11✔
2143
        {
2144
            if (to_end_ll->is_marked() || to_end_ll->is_expr_marked()) {
1✔
2145
                found_mark = true;
1✔
2146
            }
2147
            ++to_end_ll;
1✔
2148
        }
2149
        if (!found_mark) {
6✔
2150
            return false;
3✔
2151
        }
2152
    }
2153

2154
    if (ll->get_msg_level() < this->lss_min_log_level) {
13,041✔
2155
        return false;
2✔
2156
    }
2157

2158
    if (*ll < this->ttt_min_row_time) {
13,039✔
2159
        return false;
3✔
2160
    }
2161

2162
    if (!(*ll <= this->ttt_max_row_time)) {
13,036✔
2163
        return false;
4✔
2164
    }
2165

2166
    return true;
13,032✔
2167
}
2168

2169
void
2170
logfile_sub_source::invalidate_sql_filter()
24✔
2171
{
2172
    for (auto& ld : *this) {
48✔
2173
        ld->ld_filter_state.lfo_filter_state.clear_filter_state(0);
24✔
2174
    }
2175
}
24✔
2176

2177
void
2178
logfile_sub_source::text_mark(const bookmark_type_t* bm,
146✔
2179
                              vis_line_t line,
2180
                              bool added)
2181
{
2182
    if (line >= (int) this->lss_index.size()) {
146✔
2183
        return;
×
2184
    }
2185

2186
    auto cl = this->at(line);
146✔
2187

2188
    if (bm == &textview_curses::BM_USER) {
146✔
2189
        auto* ll = this->find_line(cl);
57✔
2190

2191
        ll->set_mark(added);
57✔
2192
    }
2193
    auto lb = this->lss_user_marks[bm].bv_tree.lower_bound(cl);
146✔
2194
    if (added) {
146✔
2195
        if (lb == this->lss_user_marks[bm].bv_tree.end() || *lb != cl) {
65✔
2196
            this->lss_user_marks[bm].bv_tree.insert(cl);
60✔
2197
        }
2198
    } else if (lb != this->lss_user_marks[bm].bv_tree.end() && *lb == cl) {
81✔
2199
        this->lss_user_marks[bm].bv_tree.erase(lb);
7✔
2200
    }
2201
    if (bm == &textview_curses::BM_META
146✔
2202
        && this->lss_meta_grepper.gps_proc != nullptr)
16✔
2203
    {
2204
        this->tss_view->search_range(line, line + 1_vl);
1✔
2205
        this->tss_view->search_new_data();
1✔
2206
    }
2207
}
2208

2209
void
2210
logfile_sub_source::text_clear_marks(const bookmark_type_t* bm)
39✔
2211
{
2212
    if (bm == &textview_curses::BM_USER) {
39✔
2213
        for (auto iter = this->lss_user_marks[bm].bv_tree.begin();
6✔
2214
             iter != this->lss_user_marks[bm].bv_tree.end();
6✔
2215
             ++iter)
×
2216
        {
2217
            this->find_line(*iter)->set_mark(false);
×
2218
        }
2219
    }
2220
    this->lss_user_marks[bm].clear();
39✔
2221
}
39✔
2222

2223
void
2224
logfile_sub_source::remove_file(std::shared_ptr<logfile> lf)
504✔
2225
{
2226
    auto iter = std::find_if(
504✔
2227
        this->lss_files.begin(), this->lss_files.end(), logfile_data_eq(lf));
1,008✔
2228
    if (iter != this->lss_files.end()) {
504✔
2229
        int file_index = iter - this->lss_files.begin();
504✔
2230

2231
        (*iter)->clear();
504✔
2232
        for (auto& bv : this->lss_user_marks) {
4,536✔
2233
            auto mark_curr = content_line_t(file_index * MAX_LINES_PER_FILE);
4,032✔
2234
            auto mark_end
2235
                = content_line_t((file_index + 1) * MAX_LINES_PER_FILE);
4,032✔
2236
            auto file_range = bv.equal_range(mark_curr, mark_end);
4,032✔
2237

2238
            if (file_range.first != file_range.second) {
4,032✔
2239
                auto to_del = std::vector<content_line_t>{};
62✔
2240
                for (auto file_iter = file_range.first;
62✔
2241
                     file_iter != file_range.second;
147✔
2242
                     ++file_iter)
85✔
2243
                {
2244
                    to_del.emplace_back(*file_iter);
85✔
2245
                }
2246

2247
                for (auto cl : to_del) {
147✔
2248
                    bv.bv_tree.erase(cl);
85✔
2249
                }
2250
            }
62✔
2251
        }
2252

2253
        this->lss_force_rebuild = true;
504✔
2254
    }
2255
    while (!this->lss_files.empty()) {
1,008✔
2256
        if (this->lss_files.back()->get_file_ptr() == nullptr) {
554✔
2257
            this->lss_files.pop_back();
504✔
2258
        } else {
2259
            break;
50✔
2260
        }
2261
    }
2262
    this->lss_token_file = nullptr;
504✔
2263
}
504✔
2264

2265
std::optional<vis_line_t>
2266
logfile_sub_source::find_from_content(content_line_t cl)
5✔
2267
{
2268
    content_line_t line = cl;
5✔
2269
    std::shared_ptr<logfile> lf = this->find(line);
5✔
2270

2271
    if (lf != nullptr) {
5✔
2272
        auto ll_iter = lf->begin() + line;
5✔
2273
        auto& ll = *ll_iter;
5✔
2274
        auto vis_start_opt = this->find_from_time(ll.get_timeval());
5✔
2275

2276
        if (!vis_start_opt) {
5✔
2277
            return std::nullopt;
×
2278
        }
2279

2280
        auto vis_start = *vis_start_opt;
5✔
2281

2282
        while (vis_start < vis_line_t(this->text_line_count())) {
5✔
2283
            content_line_t guess_cl = this->at(vis_start);
5✔
2284

2285
            if (cl == guess_cl) {
5✔
2286
                return vis_start;
5✔
2287
            }
2288

2289
            auto guess_line = this->find_line(guess_cl);
×
2290

2291
            if (!guess_line || ll < *guess_line) {
×
2292
                return std::nullopt;
×
2293
            }
2294

2295
            ++vis_start;
×
2296
        }
2297
    }
2298

2299
    return std::nullopt;
×
2300
}
5✔
2301

2302
void
2303
logfile_sub_source::reload_index_delegate()
620✔
2304
{
2305
    if (this->lss_index_delegate == nullptr) {
620✔
2306
        return;
×
2307
    }
2308

2309
    this->lss_index_delegate->index_start(*this);
620✔
2310
    for (const auto index : this->lss_filtered_index) {
848✔
2311
        auto cl = this->lss_index[index].value();
228✔
2312
        uint64_t line_number;
2313
        auto ld = this->find_data(cl, line_number);
228✔
2314
        std::shared_ptr<logfile> lf = (*ld)->get_file();
228✔
2315

2316
        this->lss_index_delegate->index_line(
228✔
2317
            *this, lf.get(), lf->begin() + line_number);
228✔
2318
    }
228✔
2319
    this->lss_index_delegate->index_complete(*this);
620✔
2320
}
2321

2322
std::optional<std::shared_ptr<text_filter>>
2323
logfile_sub_source::get_sql_filter()
1,894✔
2324
{
2325
    return this->tss_filters | lnav::itertools::find_if([](const auto& filt) {
1,894✔
2326
               return filt->get_index() == 0;
349✔
2327
           })
2328
        | lnav::itertools::deref();
3,788✔
2329
}
2330

2331
void
2332
log_location_history::loc_history_append(vis_line_t top)
92✔
2333
{
2334
    if (top < 0_vl || top >= vis_line_t(this->llh_log_source.text_line_count()))
92✔
2335
    {
2336
        return;
1✔
2337
    }
2338

2339
    auto cl = this->llh_log_source.at(top);
91✔
2340

2341
    auto iter = this->llh_history.begin();
91✔
2342
    iter += this->llh_history.size() - this->lh_history_position;
91✔
2343
    this->llh_history.erase_from(iter);
91✔
2344
    this->lh_history_position = 0;
91✔
2345
    this->llh_history.push_back(cl);
91✔
2346
}
2347

2348
std::optional<vis_line_t>
2349
log_location_history::loc_history_back(vis_line_t current_top)
2✔
2350
{
2351
    while (this->lh_history_position < this->llh_history.size()) {
2✔
2352
        auto iter = this->llh_history.rbegin();
2✔
2353

2354
        auto vis_for_pos = this->llh_log_source.find_from_content(*iter);
2✔
2355

2356
        if (this->lh_history_position == 0 && vis_for_pos != current_top) {
2✔
2357
            return vis_for_pos;
2✔
2358
        }
2359

2360
        if ((this->lh_history_position + 1) >= this->llh_history.size()) {
2✔
2361
            break;
×
2362
        }
2363

2364
        this->lh_history_position += 1;
2✔
2365

2366
        iter += this->lh_history_position;
2✔
2367

2368
        vis_for_pos = this->llh_log_source.find_from_content(*iter);
2✔
2369

2370
        if (vis_for_pos) {
2✔
2371
            return vis_for_pos;
2✔
2372
        }
2373
    }
2374

2375
    return std::nullopt;
×
2376
}
2377

2378
std::optional<vis_line_t>
2379
log_location_history::loc_history_forward(vis_line_t current_top)
1✔
2380
{
2381
    while (this->lh_history_position > 0) {
1✔
2382
        this->lh_history_position -= 1;
1✔
2383

2384
        auto iter = this->llh_history.rbegin();
1✔
2385

2386
        iter += this->lh_history_position;
1✔
2387

2388
        auto vis_for_pos = this->llh_log_source.find_from_content(*iter);
1✔
2389

2390
        if (vis_for_pos) {
1✔
2391
            return vis_for_pos;
1✔
2392
        }
2393
    }
2394

2395
    return std::nullopt;
×
2396
}
2397

2398
bool
2399
sql_filter::matches(std::optional<line_source> ls_opt,
121✔
2400
                    const shared_buffer_ref& line)
2401
{
2402
    if (!ls_opt) {
121✔
2403
        return false;
×
2404
    }
2405

2406
    auto ls = ls_opt;
121✔
2407

2408
    if (!ls->ls_line->is_message()) {
121✔
2409
        return false;
3✔
2410
    }
2411
    if (this->sf_filter_stmt == nullptr) {
118✔
2412
        return false;
×
2413
    }
2414

2415
    auto lfp = ls->ls_file.shared_from_this();
118✔
2416
    auto ld = this->sf_log_source.find_data_i(lfp);
118✔
2417
    if (ld == this->sf_log_source.end()) {
118✔
2418
        return false;
×
2419
    }
2420

2421
    auto eval_res = this->sf_log_source.eval_sql_filter(
118✔
2422
        this->sf_filter_stmt, ld, ls->ls_line);
118✔
2423
    if (eval_res.unwrapOr(true)) {
118✔
2424
        return false;
72✔
2425
    }
2426

2427
    return true;
46✔
2428
}
118✔
2429

2430
std::string
2431
sql_filter::to_command() const
×
2432
{
2433
    return fmt::format(FMT_STRING("filter-expr {}"), this->lf_id);
×
2434
}
2435

2436
std::optional<line_info>
2437
logfile_sub_source::meta_grepper::grep_value_for_line(vis_line_t line,
×
2438
                                                      std::string& value_out)
2439
{
2440
    auto line_meta_opt = this->lmg_source.find_bookmark_metadata(line);
×
2441
    if (!line_meta_opt) {
×
2442
        value_out.clear();
×
2443
    } else {
2444
        auto& bm = *(line_meta_opt.value());
×
2445

2446
        {
2447
            md2attr_line mdal;
×
2448

2449
            auto parse_res = md4cpp::parse(bm.bm_comment, mdal);
×
2450
            if (parse_res.isOk()) {
×
2451
                value_out.append(parse_res.unwrap().get_string());
×
2452
            } else {
2453
                value_out.append(bm.bm_comment);
×
2454
            }
2455
        }
2456

2457
        value_out.append("\x1c");
×
2458
        for (const auto& tag : bm.bm_tags) {
×
2459
            value_out.append(tag);
×
2460
            value_out.append("\x1c");
×
2461
        }
2462
        value_out.append("\x1c");
×
2463
        for (const auto& pair : bm.bm_annotations.la_pairs) {
×
2464
            value_out.append(pair.first);
×
2465
            value_out.append("\x1c");
×
2466

2467
            md2attr_line mdal;
×
2468

2469
            auto parse_res = md4cpp::parse(pair.second, mdal);
×
2470
            if (parse_res.isOk()) {
×
2471
                value_out.append(parse_res.unwrap().get_string());
×
2472
            } else {
2473
                value_out.append(pair.second);
×
2474
            }
2475
            value_out.append("\x1c");
×
2476
        }
2477
        value_out.append("\x1c");
×
2478
        value_out.append(bm.bm_opid);
×
2479
    }
2480

2481
    if (!this->lmg_done) {
×
2482
        return line_info{};
×
2483
    }
2484

2485
    return std::nullopt;
×
2486
}
2487

2488
vis_line_t
2489
logfile_sub_source::meta_grepper::grep_initial_line(vis_line_t start,
×
2490
                                                    vis_line_t highest)
2491
{
2492
    auto& bm = this->lmg_source.tss_view->get_bookmarks();
×
2493
    auto& bv = bm[&textview_curses::BM_META];
×
2494

2495
    if (bv.empty()) {
×
2496
        return -1_vl;
×
2497
    }
2498
    return *bv.bv_tree.begin();
×
2499
}
2500

2501
void
2502
logfile_sub_source::meta_grepper::grep_next_line(vis_line_t& line)
×
2503
{
2504
    auto& bm = this->lmg_source.tss_view->get_bookmarks();
×
2505
    auto& bv = bm[&textview_curses::BM_META];
×
2506

2507
    auto line_opt = bv.next(vis_line_t(line));
×
2508
    if (!line_opt) {
×
2509
        this->lmg_done = true;
×
2510
    }
2511
    line = line_opt.value_or(-1_vl);
×
2512
}
2513

2514
void
2515
logfile_sub_source::meta_grepper::grep_begin(grep_proc<vis_line_t>& gp,
23✔
2516
                                             vis_line_t start,
2517
                                             vis_line_t stop)
2518
{
2519
    this->lmg_source.quiesce();
23✔
2520

2521
    this->lmg_source.tss_view->grep_begin(gp, start, stop);
23✔
2522
}
23✔
2523

2524
void
2525
logfile_sub_source::meta_grepper::grep_end(grep_proc<vis_line_t>& gp)
23✔
2526
{
2527
    this->lmg_source.tss_view->grep_end(gp);
23✔
2528
}
23✔
2529

2530
void
2531
logfile_sub_source::meta_grepper::grep_match(grep_proc<vis_line_t>& gp,
3✔
2532
                                             vis_line_t line)
2533
{
2534
    this->lmg_source.tss_view->grep_match(gp, line);
3✔
2535
}
3✔
2536

2537
static std::vector<breadcrumb::possibility>
2538
timestamp_poss()
11✔
2539
{
2540
    const static std::vector<breadcrumb::possibility> retval = {
2541
        breadcrumb::possibility{"-1 day"},
2542
        breadcrumb::possibility{"-1h"},
2543
        breadcrumb::possibility{"-30m"},
2544
        breadcrumb::possibility{"-15m"},
2545
        breadcrumb::possibility{"-5m"},
2546
        breadcrumb::possibility{"-1m"},
2547
        breadcrumb::possibility{"+1m"},
2548
        breadcrumb::possibility{"+5m"},
2549
        breadcrumb::possibility{"+15m"},
2550
        breadcrumb::possibility{"+30m"},
2551
        breadcrumb::possibility{"+1h"},
2552
        breadcrumb::possibility{"+1 day"},
2553
    };
95✔
2554

2555
    return retval;
11✔
2556
}
24✔
2557

2558
static attr_line_t
2559
to_display(const std::shared_ptr<logfile>& lf)
29✔
2560
{
2561
    attr_line_t retval;
29✔
2562

2563
    if (lf->get_open_options().loo_piper) {
29✔
2564
        if (!lf->get_open_options().loo_piper->is_finished()) {
×
2565
            retval.append("\u21bb "_list_glyph);
×
2566
        }
2567
    }
2568
    retval.append(lf->get_unique_path());
29✔
2569

2570
    return retval;
29✔
2571
}
×
2572

2573
void
2574
logfile_sub_source::text_crumbs_for_line(int line,
27✔
2575
                                         std::vector<breadcrumb::crumb>& crumbs)
2576
{
2577
    text_sub_source::text_crumbs_for_line(line, crumbs);
27✔
2578

2579
    if (this->lss_filtered_index.empty()) {
27✔
2580
        return;
9✔
2581
    }
2582

2583
    auto vl = vis_line_t(line);
18✔
2584
    auto bmc = this->get_bookmark_metadata_context(
18✔
2585
        vl, bookmark_metadata::categories::partition);
2586
    if (bmc.bmc_current_metadata) {
18✔
2587
        const auto& name = bmc.bmc_current_metadata.value()->bm_name;
1✔
2588
        auto key = text_anchors::to_anchor_string(name);
1✔
2589
        auto display = attr_line_t()
1✔
2590
                           .append("\u2291 "_symbol)
1✔
2591
                           .append(lnav::roles::variable(name))
2✔
2592
                           .move();
1✔
2593
        crumbs.emplace_back(
1✔
2594
            key,
2595
            display,
2596
            [this]() -> std::vector<breadcrumb::possibility> {
×
2597
                auto& vb = this->tss_view->get_bookmarks();
1✔
2598
                const auto& bv = vb[&textview_curses::BM_PARTITION];
1✔
2599
                std::vector<breadcrumb::possibility> retval;
1✔
2600

2601
                for (const auto& vl : bv.bv_tree) {
2✔
2602
                    auto meta_opt = this->find_bookmark_metadata(vl);
1✔
2603
                    if (!meta_opt || meta_opt.value()->bm_name.empty()) {
1✔
2604
                        continue;
×
2605
                    }
2606

2607
                    const auto& name = meta_opt.value()->bm_name;
1✔
2608
                    retval.emplace_back(text_anchors::to_anchor_string(name),
1✔
2609
                                        name);
2610
                }
2611

2612
                return retval;
1✔
2613
            },
×
2614
            [ec = this->lss_exec_context](const auto& part) {
1✔
2615
                auto cmd = fmt::format(FMT_STRING(":goto {}"),
×
2616
                                       part.template get<std::string>());
2617
                ec->execute(INTERNAL_SRC_LOC, cmd);
×
2618
            });
×
2619
    }
1✔
2620

2621
    auto line_pair_opt = this->find_line_with_file(vl);
18✔
2622
    if (!line_pair_opt) {
18✔
2623
        return;
×
2624
    }
2625
    auto line_pair = line_pair_opt.value();
18✔
2626
    auto& lf = line_pair.first;
18✔
2627
    auto format = lf->get_format();
18✔
2628
    char ts[64];
2629

2630
    sql_strftime(ts, sizeof(ts), line_pair.second->get_timeval(), 'T');
18✔
2631

2632
    crumbs.emplace_back(std::string(ts),
18✔
2633
                        timestamp_poss,
2634
                        [ec = this->lss_exec_context](const auto& ts) {
18✔
2635
                            auto cmd
×
2636
                                = fmt::format(FMT_STRING(":goto {}"),
×
2637
                                              ts.template get<std::string>());
2638
                            ec->execute(INTERNAL_SRC_LOC, cmd);
×
2639
                        });
×
2640
    crumbs.back().c_expected_input
18✔
2641
        = breadcrumb::crumb::expected_input_t::anything;
18✔
2642
    crumbs.back().c_search_placeholder = "(Enter an absolute or relative time)";
18✔
2643

2644
    auto format_name = format->get_name().to_string();
18✔
2645

2646
    crumbs.emplace_back(
18✔
2647
        format_name,
2648
        attr_line_t().append(format_name),
18✔
2649
        [this]() -> std::vector<breadcrumb::possibility> {
×
2650
            return this->lss_files
11✔
2651
                | lnav::itertools::filter_in([](const auto& file_data) {
22✔
2652
                       return file_data->is_visible();
11✔
2653
                   })
2654
                | lnav::itertools::map(&logfile_data::get_file_ptr)
33✔
2655
                | lnav::itertools::map(&logfile::get_format_name)
33✔
2656
                | lnav::itertools::unique()
33✔
2657
                | lnav::itertools::map([](const auto& elem) {
44✔
2658
                       return breadcrumb::possibility{
2659
                           elem.to_string(),
2660
                       };
11✔
2661
                   })
2662
                | lnav::itertools::to_vector();
33✔
2663
        },
2664
        [ec = this->lss_exec_context](const auto& format_name) {
18✔
2665
            static const std::string MOVE_STMT = R"(;UPDATE lnav_views
2666
     SET selection = ifnull(
2667
         (SELECT log_line FROM all_logs WHERE log_format = $format_name LIMIT 1),
2668
         (SELECT raise_error(
2669
            'Could not find format: ' || $format_name,
2670
            'The corresponding log messages might have been filtered out'))
2671
       )
2672
     WHERE name = 'log'
2673
)";
2674

2675
            ec->execute_with(
×
2676
                INTERNAL_SRC_LOC,
×
2677
                MOVE_STMT,
2678
                std::make_pair("format_name",
2679
                               format_name.template get<std::string>()));
2680
        });
×
2681

2682
    auto msg_start_iter = lf->message_start(line_pair.second);
18✔
2683
    auto file_line_number = std::distance(lf->begin(), msg_start_iter);
18✔
2684
    crumbs.emplace_back(
36✔
2685
        lf->get_unique_path(),
18✔
2686
        to_display(lf).appendf(FMT_STRING("[{:L}]"), file_line_number),
72✔
2687
        [this]() -> std::vector<breadcrumb::possibility> {
×
2688
            return this->lss_files
11✔
2689
                | lnav::itertools::filter_in([](const auto& file_data) {
22✔
2690
                       return file_data->is_visible();
11✔
2691
                   })
2692
                | lnav::itertools::map([](const auto& file_data) {
22✔
2693
                       return breadcrumb::possibility{
2694
                           file_data->get_file_ptr()->get_unique_path(),
11✔
2695
                           to_display(file_data->get_file()),
2696
                       };
11✔
2697
                   });
22✔
2698
        },
2699
        [ec = this->lss_exec_context](const auto& uniq_path) {
18✔
2700
            static const std::string MOVE_STMT = R"(;UPDATE lnav_views
2701
     SET selection = ifnull(
2702
          (SELECT log_line FROM all_logs WHERE log_unique_path = $uniq_path LIMIT 1),
2703
          (SELECT raise_error(
2704
            'Could not find file: ' || $uniq_path,
2705
            'The corresponding log messages might have been filtered out'))
2706
         )
2707
     WHERE name = 'log'
2708
)";
2709

2710
            ec->execute_with(
×
2711
                INTERNAL_SRC_LOC,
×
2712
                MOVE_STMT,
2713
                std::make_pair("uniq_path",
2714
                               uniq_path.template get<std::string>()));
2715
        });
×
2716

2717
    shared_buffer sb;
18✔
2718
    logline_value_vector values;
18✔
2719
    auto& sbr = values.lvv_sbr;
18✔
2720

2721
    lf->read_full_message(msg_start_iter, sbr);
18✔
2722
    attr_line_t al(to_string(sbr));
18✔
2723
    if (!sbr.get_metadata().m_valid_utf) {
18✔
2724
        scrub_to_utf8(&al.al_string[0], al.al_string.length());
×
2725
    }
2726
    if (sbr.get_metadata().m_has_ansi) {
18✔
2727
        // bleh
2728
        scrub_ansi_string(al.get_string(), &al.al_attrs);
×
2729
        sbr.share(sb, al.al_string.data(), al.al_string.size());
×
2730
    }
2731
    format->annotate(lf.get(), file_line_number, al.get_attrs(), values);
18✔
2732

2733
    {
2734
        static const std::string MOVE_STMT = R"(;UPDATE lnav_views
30✔
2735
          SET selection = ifnull(
2736
            (SELECT log_line FROM all_logs WHERE log_opid = $opid LIMIT 1),
2737
            (SELECT raise_error('Could not find opid: ' || $opid,
2738
                                'The corresponding log messages might have been filtered out')))
2739
          WHERE name = 'log'
2740
        )";
2741
        static const std::string ELLIPSIS = "\u22ef";
30✔
2742

2743
        auto opid_display = values.lvv_opid_value.has_value()
18✔
2744
            ? lnav::roles::identifier(values.lvv_opid_value.value())
10✔
2745
            : lnav::roles::hidden(ELLIPSIS);
28✔
2746
        crumbs.emplace_back(
36✔
2747
            values.lvv_opid_value.has_value() ? values.lvv_opid_value.value()
44✔
2748
                                              : "",
2749
            attr_line_t().append(opid_display),
18✔
2750
            [this]() -> std::vector<breadcrumb::possibility> {
×
2751
                std::set<std::string> poss_strs;
11✔
2752

2753
                for (const auto& file_data : this->lss_files) {
22✔
2754
                    if (file_data->get_file_ptr() == nullptr) {
11✔
2755
                        continue;
×
2756
                    }
2757
                    safe::ReadAccess<logfile::safe_opid_state> r_opid_map(
2758
                        file_data->get_file_ptr()->get_opids());
11✔
2759

2760
                    for (const auto& pair : r_opid_map->los_opid_ranges) {
786✔
2761
                        poss_strs.emplace(pair.first.to_string());
775✔
2762
                    }
2763
                }
11✔
2764

2765
                std::vector<breadcrumb::possibility> retval;
11✔
2766

2767
                std::transform(poss_strs.begin(),
11✔
2768
                               poss_strs.end(),
2769
                               std::back_inserter(retval),
2770
                               [](const auto& opid_str) {
775✔
2771
                                   return breadcrumb::possibility(opid_str);
775✔
2772
                               });
2773

2774
                return retval;
22✔
2775
            },
11✔
2776
            [ec = this->lss_exec_context](const auto& opid) {
18✔
2777
                ec->execute_with(
×
2778
                    INTERNAL_SRC_LOC,
×
2779
                    MOVE_STMT,
2780
                    std::make_pair("opid", opid.template get<std::string>()));
2781
            });
×
2782
    }
18✔
2783

2784
    auto sf = string_fragment::from_str(al.get_string());
18✔
2785
    auto body_opt = get_string_attr(al.get_attrs(), SA_BODY);
18✔
2786
    auto nl_pos_opt = sf.find('\n');
18✔
2787
    auto msg_line_number = std::distance(msg_start_iter, line_pair.second);
18✔
2788
    auto line_from_top = line - msg_line_number;
18✔
2789
    if (body_opt && nl_pos_opt) {
18✔
2790
        if (this->lss_token_meta_line != file_line_number
18✔
2791
            || this->lss_token_meta_size != sf.length())
9✔
2792
        {
2793
            if (body_opt->saw_string_attr->sa_range.length() < 128 * 1024) {
3✔
2794
                this->lss_token_meta
2795
                    = lnav::document::discover(al)
3✔
2796
                          .over_range(
3✔
2797
                              body_opt.value().saw_string_attr->sa_range)
3✔
2798
                          .perform();
3✔
2799
                // XXX discover_structure() changes `al`, have to recompute
2800
                // stuff
2801
                sf = al.to_string_fragment();
3✔
2802
                body_opt = get_string_attr(al.get_attrs(), SA_BODY);
3✔
2803
            } else {
2804
                this->lss_token_meta = lnav::document::metadata{};
×
2805
            }
2806
            this->lss_token_meta_line = file_line_number;
3✔
2807
            this->lss_token_meta_size = sf.length();
3✔
2808
        }
2809

2810
        const auto initial_size = crumbs.size();
9✔
2811
        auto sf_body
2812
            = sf.sub_range(body_opt->saw_string_attr->sa_range.lr_start,
9✔
2813
                           body_opt->saw_string_attr->sa_range.lr_end);
9✔
2814
        file_off_t line_offset = body_opt->saw_string_attr->sa_range.lr_start;
9✔
2815
        file_off_t line_end_offset = sf.length();
9✔
2816
        ssize_t line_number = 0;
9✔
2817

2818
        for (const auto& sf_line : sf_body.split_lines()) {
18✔
2819
            if (line_number >= msg_line_number) {
12✔
2820
                line_end_offset = line_offset + sf_line.length();
3✔
2821
                break;
3✔
2822
            }
2823
            line_number += 1;
9✔
2824
            line_offset += sf_line.length();
9✔
2825
        }
9✔
2826

2827
        this->lss_token_meta.m_sections_tree.visit_overlapping(
9✔
2828
            line_offset,
2829
            line_end_offset,
2830
            [this,
2✔
2831
             initial_size,
2832
             meta = &this->lss_token_meta,
9✔
2833
             &crumbs,
2834
             line_from_top](const auto& iv) {
2835
                auto path = crumbs | lnav::itertools::skip(initial_size)
6✔
2836
                    | lnav::itertools::map(&breadcrumb::crumb::c_key)
4✔
2837
                    | lnav::itertools::append(iv.value);
2✔
2838
                auto curr_node = lnav::document::hier_node::lookup_path(
2✔
2839
                    meta->m_sections_root.get(), path);
2✔
2840

2841
                crumbs.emplace_back(
4✔
2842
                    iv.value,
2✔
2843
                    [meta, path]() { return meta->possibility_provider(path); },
4✔
2844
                    [this, curr_node, path, line_from_top](const auto& key) {
4✔
2845
                        if (!curr_node) {
×
2846
                            return;
×
2847
                        }
2848
                        auto* parent_node = curr_node.value()->hn_parent;
×
2849
                        if (parent_node == nullptr) {
×
2850
                            return;
×
2851
                        }
2852
                        key.match(
2853
                            [parent_node](const std::string& str) {
×
2854
                                return parent_node->find_line_number(str);
×
2855
                            },
2856
                            [parent_node](size_t index) {
×
2857
                                return parent_node->find_line_number(index);
×
2858
                            })
2859
                            | [this, line_from_top](auto line_number) {
×
2860
                                  this->tss_view->set_selection(
×
2861
                                      vis_line_t(line_from_top + line_number));
×
2862
                              };
2863
                    });
2864
                if (curr_node && !curr_node.value()->hn_parent->is_named_only())
2✔
2865
                {
2866
                    auto node = lnav::document::hier_node::lookup_path(
×
2867
                        meta->m_sections_root.get(), path);
×
2868

2869
                    crumbs.back().c_expected_input
×
2870
                        = curr_node.value()
×
2871
                              ->hn_parent->hn_named_children.empty()
×
2872
                        ? breadcrumb::crumb::expected_input_t::index
×
2873
                        : breadcrumb::crumb::expected_input_t::index_or_exact;
2874
                    crumbs.back().with_possible_range(
×
2875
                        node | lnav::itertools::map([](const auto hn) {
×
2876
                            return hn->hn_parent->hn_children.size();
×
2877
                        })
2878
                        | lnav::itertools::unwrap_or(size_t{0}));
×
2879
                }
2880
            });
2✔
2881

2882
        auto path = crumbs | lnav::itertools::skip(initial_size)
18✔
2883
            | lnav::itertools::map(&breadcrumb::crumb::c_key);
18✔
2884
        auto node = lnav::document::hier_node::lookup_path(
9✔
2885
            this->lss_token_meta.m_sections_root.get(), path);
9✔
2886

2887
        if (node && !node.value()->hn_children.empty()) {
9✔
2888
            auto poss_provider = [curr_node = node.value()]() {
1✔
2889
                std::vector<breadcrumb::possibility> retval;
1✔
2890
                for (const auto& child : curr_node->hn_named_children) {
1✔
2891
                    retval.emplace_back(child.first);
×
2892
                }
2893
                return retval;
1✔
2894
            };
2895
            auto path_performer
2896
                = [this, curr_node = node.value(), line_from_top](
2✔
2897
                      const breadcrumb::crumb::key_t& value) {
2898
                      value.match(
×
2899
                          [curr_node](const std::string& str) {
×
2900
                              return curr_node->find_line_number(str);
×
2901
                          },
2902
                          [curr_node](size_t index) {
×
2903
                              return curr_node->find_line_number(index);
×
2904
                          })
2905
                          | [this, line_from_top](size_t line_number) {
×
2906
                                this->tss_view->set_selection(
×
2907
                                    vis_line_t(line_from_top + line_number));
×
2908
                            };
2909
                  };
1✔
2910
            crumbs.emplace_back("", "\u22ef", poss_provider, path_performer);
1✔
2911
            crumbs.back().c_expected_input
1✔
2912
                = node.value()->hn_named_children.empty()
2✔
2913
                ? breadcrumb::crumb::expected_input_t::index
1✔
2914
                : breadcrumb::crumb::expected_input_t::index_or_exact;
2915
        }
2916
    }
9✔
2917
}
18✔
2918

2919
void
2920
logfile_sub_source::quiesce()
42✔
2921
{
2922
    for (auto& ld : this->lss_files) {
84✔
2923
        auto* lf = ld->get_file_ptr();
42✔
2924

2925
        if (lf == nullptr) {
42✔
2926
            continue;
×
2927
        }
2928

2929
        lf->quiesce();
42✔
2930
    }
2931
}
42✔
2932

2933
bookmark_metadata&
2934
logfile_sub_source::get_bookmark_metadata(content_line_t cl)
25✔
2935
{
2936
    auto line_pair = this->find_line_with_file(cl).value();
25✔
2937
    auto line_number = static_cast<uint32_t>(
2938
        std::distance(line_pair.first->begin(), line_pair.second));
25✔
2939

2940
    return line_pair.first->get_bookmark_metadata()[line_number];
50✔
2941
}
25✔
2942

2943
logfile_sub_source::bookmark_metadata_context
2944
logfile_sub_source::get_bookmark_metadata_context(
3,073✔
2945
    vis_line_t vl, bookmark_metadata::categories desired) const
2946
{
2947
    const auto& vb = this->tss_view->get_bookmarks();
3,073✔
2948
    const auto& bv = vb[desired == bookmark_metadata::categories::partition
2949
                            ? &textview_curses::BM_PARTITION
2950
                            : &textview_curses::BM_META];
3,073✔
2951
    auto vl_iter = bv.bv_tree.lower_bound(vl + 1_vl);
3,073✔
2952

2953
    std::optional<vis_line_t> next_line;
3,073✔
2954
    for (auto next_vl_iter = vl_iter; next_vl_iter != bv.bv_tree.end();
3,073✔
2955
         ++next_vl_iter)
×
2956
    {
2957
        auto bm_opt = this->find_bookmark_metadata(*next_vl_iter);
2✔
2958
        if (!bm_opt) {
2✔
2959
            continue;
×
2960
        }
2961

2962
        if (bm_opt.value()->has(desired)) {
2✔
2963
            next_line = *next_vl_iter;
2✔
2964
            break;
2✔
2965
        }
2966
    }
2967
    if (vl_iter == bv.bv_tree.begin()) {
3,073✔
2968
        return bookmark_metadata_context{std::nullopt, std::nullopt, next_line};
3,057✔
2969
    }
2970

2971
    --vl_iter;
16✔
2972
    while (true) {
2973
        auto bm_opt = this->find_bookmark_metadata(*vl_iter);
16✔
2974
        if (bm_opt) {
16✔
2975
            if (bm_opt.value()->has(desired)) {
13✔
2976
                return bookmark_metadata_context{
2977
                    *vl_iter, bm_opt.value(), next_line};
16✔
2978
            }
2979
        }
2980

2981
        if (vl_iter == bv.bv_tree.begin()) {
3✔
2982
            return bookmark_metadata_context{
2983
                std::nullopt, std::nullopt, next_line};
3✔
2984
        }
2985
        --vl_iter;
×
2986
    }
2987
    return bookmark_metadata_context{std::nullopt, std::nullopt, next_line};
2988
}
2989

2990
std::optional<bookmark_metadata*>
2991
logfile_sub_source::find_bookmark_metadata(content_line_t cl) const
20,432✔
2992
{
2993
    auto line_pair = this->find_line_with_file(cl).value();
20,432✔
2994
    auto line_number = static_cast<uint32_t>(
2995
        std::distance(line_pair.first->begin(), line_pair.second));
20,432✔
2996

2997
    auto& bm = line_pair.first->get_bookmark_metadata();
20,432✔
2998
    auto bm_iter = bm.find(line_number);
20,432✔
2999
    if (bm_iter == bm.end()) {
20,432✔
3000
        return std::nullopt;
20,054✔
3001
    }
3002

3003
    return &bm_iter->second;
378✔
3004
}
20,432✔
3005

3006
void
3007
logfile_sub_source::erase_bookmark_metadata(content_line_t cl)
26✔
3008
{
3009
    auto line_pair = this->find_line_with_file(cl).value();
26✔
3010
    auto line_number = static_cast<uint32_t>(
3011
        std::distance(line_pair.first->begin(), line_pair.second));
26✔
3012

3013
    auto& bm = line_pair.first->get_bookmark_metadata();
26✔
3014
    auto bm_iter = bm.find(line_number);
26✔
3015
    if (bm_iter != bm.end()) {
26✔
3016
        bm.erase(bm_iter);
6✔
3017
    }
3018
}
26✔
3019

3020
void
3021
logfile_sub_source::clear_bookmark_metadata()
6✔
3022
{
3023
    for (auto& ld : *this) {
14✔
3024
        if (ld->get_file_ptr() == nullptr) {
8✔
3025
            continue;
×
3026
        }
3027

3028
        ld->get_file_ptr()->get_bookmark_metadata().clear();
8✔
3029
    }
3030
}
6✔
3031

3032
void
3033
logfile_sub_source::increase_line_context()
×
3034
{
3035
    auto old_context = this->lss_line_context;
×
3036

3037
    switch (this->lss_line_context) {
×
3038
        case line_context_t::filename:
×
3039
            // nothing to do
3040
            break;
×
3041
        case line_context_t::basename:
×
3042
            this->lss_line_context = line_context_t::filename;
×
3043
            break;
×
3044
        case line_context_t::none:
×
3045
            this->lss_line_context = line_context_t::basename;
×
3046
            break;
×
3047
        case line_context_t::time_column:
×
3048
            this->lss_line_context = line_context_t::none;
×
3049
            break;
×
3050
    }
3051
    if (old_context != this->lss_line_context) {
×
3052
        this->clear_line_size_cache();
×
3053
    }
3054
}
3055

3056
bool
3057
logfile_sub_source::decrease_line_context()
×
3058
{
3059
    static const auto& cfg
3060
        = injector::get<const logfile_sub_source_ns::config&>();
×
3061
    auto old_context = this->lss_line_context;
×
3062

3063
    switch (this->lss_line_context) {
×
3064
        case line_context_t::filename:
×
3065
            this->lss_line_context = line_context_t::basename;
×
3066
            break;
×
3067
        case line_context_t::basename:
×
3068
            this->lss_line_context = line_context_t::none;
×
3069
            break;
×
3070
        case line_context_t::none:
×
3071
            if (cfg.c_time_column
×
3072
                != logfile_sub_source_ns::time_column_feature_t::Disabled)
3073
            {
3074
                this->lss_line_context = line_context_t::time_column;
×
3075
            }
3076
            break;
×
3077
        case line_context_t::time_column:
×
3078
            break;
×
3079
    }
3080
    if (old_context != this->lss_line_context) {
×
3081
        this->clear_line_size_cache();
×
3082

3083
        return true;
×
3084
    }
3085

3086
    return false;
×
3087
}
3088

3089
size_t
3090
logfile_sub_source::get_filename_offset() const
238✔
3091
{
3092
    switch (this->lss_line_context) {
238✔
3093
        case line_context_t::filename:
×
3094
            return this->lss_filename_width;
×
3095
        case line_context_t::basename:
×
3096
            return this->lss_basename_width;
×
3097
        default:
238✔
3098
            return 0;
238✔
3099
    }
3100
}
3101

3102
size_t
3103
logfile_sub_source::file_count() const
3,867✔
3104
{
3105
    size_t retval = 0;
3,867✔
3106
    const_iterator iter;
3,867✔
3107

3108
    for (iter = this->cbegin(); iter != this->cend(); ++iter) {
7,366✔
3109
        if (*iter != nullptr && (*iter)->get_file() != nullptr) {
3,499✔
3110
            retval += 1;
3,493✔
3111
        }
3112
    }
3113

3114
    return retval;
3,867✔
3115
}
3116

3117
size_t
3118
logfile_sub_source::text_size_for_line(textview_curses& tc,
×
3119
                                       int row,
3120
                                       text_sub_source::line_flags_t flags)
3121
{
3122
    size_t index = row % LINE_SIZE_CACHE_SIZE;
×
3123

3124
    if (this->lss_line_size_cache[index].first != row) {
×
3125
        std::string value;
×
3126

3127
        this->text_value_for_line(tc, row, value, flags);
×
3128
        scrub_ansi_string(value, nullptr);
×
3129
        auto line_width = string_fragment::from_str(value).column_width();
×
3130
        if (this->lss_line_context == line_context_t::time_column) {
×
3131
            auto time_attr
3132
                = find_string_attr(this->lss_token_attrs, &L_TIMESTAMP);
×
3133
            if (time_attr != this->lss_token_attrs.end()) {
×
3134
                line_width -= time_attr->sa_range.length();
×
3135
                auto format = this->lss_token_file->get_format();
×
3136
                if (format->lf_level_hideable) {
×
3137
                    auto level_attr
3138
                        = find_string_attr(this->lss_token_attrs, &L_LEVEL);
×
3139
                    if (level_attr != this->lss_token_attrs.end()) {
×
3140
                        line_width -= level_attr->sa_range.length();
×
3141
                    }
3142
                }
3143
            }
3144
        }
3145
        this->lss_line_size_cache[index].second = line_width;
×
3146
        this->lss_line_size_cache[index].first = row;
×
3147
    }
3148
    return this->lss_line_size_cache[index].second;
×
3149
}
3150

3151
int
3152
logfile_sub_source::get_filtered_count_for(size_t filter_index) const
1✔
3153
{
3154
    int retval = 0;
1✔
3155

3156
    for (const auto& ld : this->lss_files) {
2✔
3157
        retval += ld->ld_filter_state.lfo_filter_state
1✔
3158
                      .tfs_filter_hits[filter_index];
1✔
3159
    }
3160

3161
    return retval;
1✔
3162
}
3163

3164
std::optional<vis_line_t>
3165
logfile_sub_source::row_for(const row_info& ri)
247✔
3166
{
3167
    auto lb = std::lower_bound(this->lss_filtered_index.begin(),
494✔
3168
                               this->lss_filtered_index.end(),
3169
                               ri.ri_time,
247✔
3170
                               filtered_logline_cmp(*this));
3171
    if (lb != this->lss_filtered_index.end()) {
247✔
3172
        auto first_lb = lb;
242✔
3173
        while (true) {
3174
            auto cl = this->lss_index[*lb].value();
256✔
3175
            if (content_line_t(ri.ri_id) == cl) {
256✔
3176
                first_lb = lb;
214✔
3177
                break;
214✔
3178
            }
3179
            auto ll = this->find_line(cl);
42✔
3180
            if (ll->get_timeval() != ri.ri_time) {
42✔
3181
                break;
28✔
3182
            }
3183
            auto next_lb = std::next(lb);
14✔
3184
            if (next_lb == this->lss_filtered_index.end()) {
14✔
3185
                break;
×
3186
            }
3187
            lb = next_lb;
14✔
3188
        }
14✔
3189

3190
        const auto dst
3191
            = std::distance(this->lss_filtered_index.begin(), first_lb);
242✔
3192
        return vis_line_t(dst);
242✔
3193
    }
3194

3195
    return std::nullopt;
5✔
3196
}
3197

3198
std::unique_ptr<logline_window>
3199
logfile_sub_source::window_at(vis_line_t start_vl, vis_line_t end_vl)
29✔
3200
{
3201
    return std::make_unique<logline_window>(*this, start_vl, end_vl);
29✔
3202
}
3203

3204
std::unique_ptr<logline_window>
3205
logfile_sub_source::window_at(vis_line_t start_vl)
203✔
3206
{
3207
    return std::make_unique<logline_window>(*this, start_vl, start_vl + 1_vl);
203✔
3208
}
3209

3210
std::unique_ptr<logline_window>
3211
logfile_sub_source::window_to_end(vis_line_t start_vl)
×
3212
{
3213
    return std::make_unique<logline_window>(
3214
        *this, start_vl, vis_line_t(this->text_line_count()));
×
3215
}
3216

3217
std::optional<vis_line_t>
3218
logfile_sub_source::row_for_anchor(const std::string& id)
3✔
3219
{
3220
    if (startswith(id, "#msg")) {
3✔
3221
        static const auto ANCHOR_RE
3222
            = lnav::pcre2pp::code::from_const(R"(#msg([0-9a-fA-F]+)-(.+))");
3✔
3223
        thread_local auto md = lnav::pcre2pp::match_data::unitialized();
3✔
3224

3225
        if (ANCHOR_RE.capture_from(id).into(md).found_p()) {
3✔
3226
            auto scan_res = scn::scan<int64_t>(md[1]->to_string_view(), "{:x}");
3✔
3227
            if (scan_res) {
3✔
3228
                auto ts_low = std::chrono::microseconds{scan_res->value()};
3✔
3229
                auto ts_high = ts_low + 1us;
3✔
3230

3231
                auto low_vl = this->row_for_time(to_timeval(ts_low));
3✔
3232
                auto high_vl = this->row_for_time(to_timeval(ts_high));
3✔
3233
                if (low_vl) {
3✔
3234
                    auto lw = this->window_at(
3235
                        low_vl.value(),
3✔
3236
                        high_vl.value_or(low_vl.value() + 1_vl));
6✔
3237

3238
                    for (const auto& li : *lw) {
3✔
3239
                        auto hash_res = li.get_line_hash();
3✔
3240
                        if (hash_res.isErr()) {
3✔
3241
                            auto errmsg = hash_res.unwrapErr();
×
3242

3243
                            log_error("unable to get line hash: %s",
×
3244
                                      errmsg.c_str());
3245
                            continue;
×
3246
                        }
3247

3248
                        auto hash = hash_res.unwrap();
3✔
3249
                        if (hash == md[2]) {
3✔
3250
                            return li.get_vis_line();
3✔
3251
                        }
3252
                    }
12✔
3253
                }
3✔
3254
            }
3255
        }
3256

3257
        return std::nullopt;
×
3258
    }
3259

3260
    auto& vb = this->tss_view->get_bookmarks();
×
3261
    const auto& bv = vb[&textview_curses::BM_PARTITION];
×
3262

3263
    for (const auto& vl : bv.bv_tree) {
×
3264
        auto meta_opt = this->find_bookmark_metadata(vl);
×
3265
        if (!meta_opt || meta_opt.value()->bm_name.empty()) {
×
3266
            continue;
×
3267
        }
3268

3269
        const auto& name = meta_opt.value()->bm_name;
×
3270
        if (id == text_anchors::to_anchor_string(name)) {
×
3271
            return vl;
×
3272
        }
3273
    }
3274

3275
    return std::nullopt;
×
3276
}
3277

3278
std::optional<vis_line_t>
3279
logfile_sub_source::adjacent_anchor(vis_line_t vl, text_anchors::direction dir)
2✔
3280
{
3281
    if (vl < this->lss_filtered_index.size()) {
2✔
3282
        auto file_and_line_pair = this->find_line_with_file(vl);
2✔
3283
        if (file_and_line_pair) {
2✔
3284
            const auto& [lf, line] = file_and_line_pair.value();
2✔
3285
            if (line->is_continued()) {
2✔
3286
                auto retval = vl;
×
3287
                switch (dir) {
×
3288
                    case direction::prev: {
×
3289
                        auto first_line = line;
×
3290
                        while (first_line->is_continued()) {
×
3291
                            --first_line;
×
3292
                            retval -= 1_vl;
×
3293
                        }
3294
                        return retval;
×
3295
                    }
3296
                    case direction::next: {
×
3297
                        auto first_line = line;
×
3298
                        while (first_line->is_continued()) {
×
3299
                            ++first_line;
×
3300
                            retval += 1_vl;
×
3301
                        }
3302
                        return retval;
×
3303
                    }
3304
                }
3305
            }
3306
        }
3307
    }
2✔
3308

3309
    auto bmc = this->get_bookmark_metadata_context(
2✔
3310
        vl, bookmark_metadata::categories::partition);
3311
    switch (dir) {
2✔
3312
        case direction::prev: {
×
3313
            if (bmc.bmc_current && bmc.bmc_current.value() != vl) {
×
3314
                return bmc.bmc_current;
×
3315
            }
3316
            if (!bmc.bmc_current || bmc.bmc_current.value() == 0_vl) {
×
3317
                return 0_vl;
×
3318
            }
3319
            auto prev_bmc = this->get_bookmark_metadata_context(
×
3320
                bmc.bmc_current.value() - 1_vl,
×
3321
                bookmark_metadata::categories::partition);
3322
            if (!prev_bmc.bmc_current) {
×
3323
                return 0_vl;
×
3324
            }
3325
            return prev_bmc.bmc_current;
×
3326
        }
3327
        case direction::next:
2✔
3328
            return bmc.bmc_next_line;
2✔
3329
    }
3330
    return std::nullopt;
×
3331
}
3332

3333
std::optional<std::string>
3334
logfile_sub_source::anchor_for_row(vis_line_t vl)
75✔
3335
{
3336
    auto line_meta = this->get_bookmark_metadata_context(
75✔
3337
        vl, bookmark_metadata::categories::partition);
3338
    if (!line_meta.bmc_current_metadata) {
75✔
3339
        auto lw = window_at(vl);
72✔
3340

3341
        for (const auto& li : *lw) {
72✔
3342
            auto hash_res = li.get_line_hash();
72✔
3343
            if (hash_res.isErr()) {
72✔
3344
                auto errmsg = hash_res.unwrapErr();
×
3345
                log_error("unable to compute line hash: %s", errmsg.c_str());
×
3346
                break;
×
3347
            }
3348
            auto hash = hash_res.unwrap();
72✔
3349
            auto retval = fmt::format(
3350
                FMT_STRING("#msg{:016x}-{}"),
144✔
3351
                li.get_logline().get_time<std::chrono::microseconds>().count(),
72✔
3352
                hash);
×
3353

3354
            return retval;
72✔
3355
        }
288✔
3356

3357
        return std::nullopt;
×
3358
    }
72✔
3359

3360
    return text_anchors::to_anchor_string(
3✔
3361
        line_meta.bmc_current_metadata.value()->bm_name);
3✔
3362
}
3363

3364
std::unordered_set<std::string>
3365
logfile_sub_source::get_anchors()
×
3366
{
3367
    auto& vb = this->tss_view->get_bookmarks();
×
3368
    const auto& bv = vb[&textview_curses::BM_PARTITION];
×
3369
    std::unordered_set<std::string> retval;
×
3370

3371
    for (const auto& vl : bv.bv_tree) {
×
3372
        auto meta_opt = this->find_bookmark_metadata(vl);
×
3373
        if (!meta_opt || meta_opt.value()->bm_name.empty()) {
×
3374
            continue;
×
3375
        }
3376

3377
        const auto& name = meta_opt.value()->bm_name;
×
3378
        retval.emplace(text_anchors::to_anchor_string(name));
×
3379
    }
3380

3381
    return retval;
×
3382
}
×
3383

3384
bool
3385
logfile_sub_source::text_handle_mouse(
×
3386
    textview_curses& tc,
3387
    const listview_curses::display_line_content_t& mouse_line,
3388
    mouse_event& me)
3389
{
NEW
3390
    if (mouse_line.is<listview_curses::static_overlay_content>()
×
NEW
3391
        && this->text_line_count() > 0)
×
3392
    {
3393
        auto top = tc.get_top();
×
3394
        if (top > 0) {
×
3395
            auto win = this->window_at(top - 1_vl);
×
3396
            for (const auto& li : *win) {
×
3397
                tc.set_top(li.get_vis_line());
×
3398
                tc.set_selection(li.get_vis_line());
×
3399
                return true;
×
3400
            }
3401
        }
3402
    }
3403

3404
    if (tc.get_overlay_selection()) {
×
3405
        auto nci = ncinput{};
×
3406
        if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 2, 4)) {
×
3407
            nci.id = ' ';
×
3408
            nci.eff_text[0] = ' ';
×
3409
            this->list_input_handle_key(tc, nci);
×
3410
        } else if (me.is_click_in(mouse_button_t::BUTTON_LEFT, 5, 6)) {
×
3411
            nci.id = '#';
×
3412
            nci.eff_text[0] = '#';
×
3413
            this->list_input_handle_key(tc, nci);
×
3414
        }
3415
    }
3416
    return true;
×
3417
}
3418

3419
void
3420
logfile_sub_source::reload_config(error_reporter& reporter)
639✔
3421
{
3422
    static const auto& cfg
3423
        = injector::get<const logfile_sub_source_ns::config&>();
639✔
3424

3425
    switch (cfg.c_time_column) {
639✔
3426
        case logfile_sub_source_ns::time_column_feature_t::Default:
×
3427
            if (this->lss_line_context == line_context_t::none) {
×
3428
                this->lss_line_context = line_context_t::time_column;
×
3429
            }
3430
            break;
×
3431
        case logfile_sub_source_ns::time_column_feature_t::Disabled:
639✔
3432
            if (this->lss_line_context == line_context_t::time_column) {
639✔
3433
                this->lss_line_context = line_context_t::none;
×
3434
            }
3435
            break;
639✔
3436
        case logfile_sub_source_ns::time_column_feature_t::Enabled:
×
3437
            break;
×
3438
    }
3439
}
639✔
3440

3441
void
3442
logfile_sub_source::update_filter_hash_state(hasher& h) const
5✔
3443
{
3444
    text_sub_source::update_filter_hash_state(h);
5✔
3445

3446
    for (const auto& ld : this->lss_files) {
5✔
3447
        if (ld->get_file_ptr() == nullptr || !ld->is_visible()) {
×
3448
            h.update(0);
×
3449
        } else {
3450
            h.update(1);
×
3451
        }
3452
    }
3453
    h.update(this->lss_min_log_level);
5✔
3454
    h.update(this->lss_marked_only);
5✔
3455
}
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc