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

tstack / lnav / 19771053824-2723

28 Nov 2025 06:05PM UTC coverage: 68.861% (-0.009%) from 68.87%
19771053824-2723

push

github

tstack
[docs] remove mention of module stuff

51231 of 74398 relevant lines covered (68.86%)

436147.0 hits per line

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

63.86
/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,167✔
157
    : text_sub_source(1), lnav_config_listener(__FILE__),
158
      lss_meta_grepper(*this), lss_location_history(*this)
1,167✔
159
{
160
    this->tss_supports_filtering = true;
1,167✔
161
    this->clear_line_size_cache();
1,167✔
162
    this->clear_min_max_row_times();
1,167✔
163
}
1,167✔
164

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

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

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

188
    return retval;
25✔
189
}
×
190

191
struct filtered_logline_cmp {
192
    filtered_logline_cmp(const logfile_sub_source& lc) : llss_controller(lc) {}
346✔
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,146✔
211
    {
212
        const auto cl_lhs = llss_controller.lss_index[lhs].value();
1,146✔
213
        const auto* ll_lhs = this->llss_controller.find_line(cl_lhs);
1,146✔
214

215
        if (ll_lhs == nullptr) {
1,146✔
216
            return true;
×
217
        }
218
        return (*ll_lhs) < rhs;
1,146✔
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
83✔
226
{
227
    const auto lb = std::lower_bound(this->lss_filtered_index.begin(),
83✔
228
                                     this->lss_filtered_index.end(),
229
                                     start,
230
                                     filtered_logline_cmp(*this));
231
    if (lb != this->lss_filtered_index.end()) {
83✔
232
        auto retval = std::distance(this->lss_filtered_index.begin(), lb);
66✔
233
        return vis_line_t(retval);
66✔
234
    }
235

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

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

251
    line_info retval;
4,044✔
252
    content_line_t line(0);
4,044✔
253

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

257
    line = this->at(vis_line_t(row));
4,044✔
258

259
    if (flags & RF_RAW) {
4,044✔
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);
4,012✔
282

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

289
    this->lss_token_attrs.clear();
4,012✔
290
    this->lss_token_values.clear();
4,012✔
291
    this->lss_share_manager.invalidate_refs();
4,012✔
292
    if (flags & text_sub_source::RF_FULL) {
4,012✔
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)
7,928✔
304
                  .map([](auto sbr) { return to_string(sbr); })
7,928✔
305
                  .unwrapOr({});
3,964✔
306
        if (this->lss_token_line->has_ansi()) {
3,964✔
307
            scrub_ansi_string(this->lss_token_value, &this->lss_token_attrs);
24✔
308
        }
309
    }
310
    this->lss_token_shift_start = 0;
4,012✔
311
    this->lss_token_shift_size = 0;
4,012✔
312

313
    auto format = this->lss_token_file->get_format();
4,012✔
314

315
    value_out = this->lss_token_value;
4,012✔
316

317
    auto& sbr = this->lss_token_values.lvv_sbr;
4,012✔
318

319
    sbr.share(this->lss_share_manager,
4,012✔
320
              (char*) this->lss_token_value.c_str(),
321
              this->lss_token_value.size());
322
    format->annotate(this->lss_token_file.get(),
8,024✔
323
                     line,
324
                     this->lss_token_attrs,
4,012✔
325
                     this->lss_token_values);
4,012✔
326
    if (flags & RF_REWRITE) {
4,012✔
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()};
4,012✔
345
        this->lss_token_attrs.emplace_back(lr, SA_ORIGINAL_LINE.value());
4,012✔
346
    }
347

348
    std::optional<exttm> adjusted_tm;
4,012✔
349
    auto time_attr = find_string_attr(this->lss_token_attrs, &L_TIMESTAMP);
4,012✔
350
    if (!this->lss_token_line->is_continued() && !format->lf_formatted_lines
6,170✔
351
        && (this->lss_token_file->is_time_adjusted()
1,917✔
352
            || ((format->lf_timestamp_flags & ETF_ZONE_SET
1,902✔
353
                 || format->lf_date_time.dts_default_zone != nullptr)
1,387✔
354
                && format->lf_date_time.dts_zoned_to_local)
599✔
355
            || format->lf_timestamp_flags & ETF_MACHINE_ORIENTED
1,303✔
356
            || !(format->lf_timestamp_flags & ETF_DAY_SET)
1,303✔
357
            || !(format->lf_timestamp_flags & ETF_MONTH_SET))
1,282✔
358
        && format->lf_date_time.dts_fmt_lock != -1)
6,170✔
359
    {
360
        if (time_attr != this->lss_token_attrs.end()) {
579✔
361
            const auto time_range = time_attr->sa_range;
579✔
362
            const auto time_sf = string_fragment::from_str_range(
579✔
363
                this->lss_token_value, time_range.lr_start, time_range.lr_end);
579✔
364
            adjusted_tm = format->tm_for_display(this->lss_token_line, time_sf);
579✔
365

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

370
            if (format->lf_timestamp_flags & ETF_MACHINE_ORIENTED
579✔
371
                || !(format->lf_timestamp_flags & ETF_DAY_SET)
323✔
372
                || !(format->lf_timestamp_flags & ETF_MONTH_SET))
902✔
373
            {
374
                if (format->lf_timestamp_flags & ETF_NANOS_SET) {
262✔
375
                    fmt = "%Y-%m-%d %H:%M:%S.%N";
×
376
                } else if (format->lf_timestamp_flags & ETF_MICROS_SET) {
262✔
377
                    fmt = "%Y-%m-%d %H:%M:%S.%f";
257✔
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(
262✔
384
                    buffer, sizeof(buffer), fmt, adjusted_tm.value());
262✔
385
            } else {
386
                len = format->lf_date_time.ftime(
634✔
387
                    buffer,
388
                    sizeof(buffer),
389
                    format->get_timestamp_formats(),
390
                    adjusted_tm.value());
317✔
391
            }
392

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

400
    // Insert space for the file/search-hit markers.
401
    value_out.insert(0, 1, ' ');
4,012✔
402
    this->lss_time_column_size = 0;
4,012✔
403
    if (this->lss_line_context == line_context_t::time_column) {
4,012✔
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
            adjusted_tm->et_flags |= this->lss_all_timestamp_flags
×
425
                & (ETF_MILLIS_SET | ETF_MICROS_SET | ETF_NANOS_SET);
×
426
            char buffer[128];
427
            this->lss_time_column_size
428
                = ftime_fmt(buffer, sizeof(buffer), fmt, adjusted_tm.value());
×
429
            if (this->tss_view->is_selectable()
×
430
                && this->tss_view->get_selection() == row)
×
431
            {
432
                buffer[this->lss_time_column_size] = ' ';
×
433
                buffer[this->lss_time_column_size + 1] = ' ';
×
434
                this->lss_time_column_size += 2;
×
435
            } else {
436
                constexpr char block[] = "\u258c ";
×
437

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

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

487
    this->lss_in_value_for_line = false;
4,012✔
488

489
    return retval;
4,012✔
490
}
4,012✔
491

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

501
    auto& vc = view_colors::singleton();
4,012✔
502
    logline* next_line = nullptr;
4,012✔
503
    line_range lr;
4,012✔
504
    int time_offset_end = 0;
4,012✔
505
    text_attrs attrs;
4,012✔
506

507
    value_out = this->lss_token_attrs;
4,012✔
508

509
    if ((row + 1) < (int) this->lss_filtered_index.size()) {
4,012✔
510
        next_line = this->find_line(this->at(vis_line_t(row + 1)));
3,822✔
511
    }
512

513
    if (next_line != nullptr
4,012✔
514
        && (day_num(next_line->get_time<std::chrono::seconds>().count())
7,834✔
515
            > day_num(this->lss_token_line->get_time<std::chrono::seconds>()
7,834✔
516
                          .count())))
517
    {
518
        attrs |= text_attrs::style::underline;
15✔
519
    }
520

521
    const auto& line_values = this->lss_token_values;
4,012✔
522

523
    lr.lr_start = 0;
4,012✔
524
    lr.lr_end = -1;
4,012✔
525
    value_out.emplace_back(
4,012✔
526
        lr, SA_LEVEL.value(this->lss_token_line->get_msg_level()));
8,024✔
527

528
    lr.lr_start = time_offset_end;
4,012✔
529
    lr.lr_end = -1;
4,012✔
530

531
    if (!attrs.empty()) {
4,012✔
532
        value_out.emplace_back(lr, VC_STYLE.value(attrs));
15✔
533
    }
534

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

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

546
    for (const auto& line_value : line_values.lvv_values) {
34,360✔
547
        if ((!(this->lss_token_flags & RF_FULL)
66,973✔
548
             && line_value.lv_sub_offset
60,252✔
549
                 != this->lss_token_line->get_sub_offset())
30,126✔
550
            || !line_value.lv_origin.is_valid())
60,474✔
551
        {
552
            continue;
6,277✔
553
        }
554

555
        if (line_value.lv_meta.is_hidden()) {
24,071✔
556
            value_out.emplace_back(line_value.lv_origin,
146✔
557
                                   SA_HIDDEN.value(ui_icon_t::hidden));
292✔
558
        }
559

560
        if (!line_value.lv_meta.lvm_identifier
62,438✔
561
            || !line_value.lv_origin.is_valid())
24,071✔
562
        {
563
            continue;
14,296✔
564
        }
565

566
        value_out.emplace_back(line_value.lv_origin,
9,775✔
567
                               VC_ROLE.value(role_t::VCR_IDENTIFIER));
19,550✔
568
    }
569

570
    if (this->lss_token_shift_size) {
4,012✔
571
        shift_string_attrs(value_out,
290✔
572
                           this->lss_token_shift_start + 1,
290✔
573
                           this->lss_token_shift_size);
574
    }
575

576
    shift_string_attrs(value_out, 0, 1);
4,012✔
577

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

597
        if (!(this->lss_token_flags & RF_FULL)) {
4,012✔
598
            const auto& bv_search = bm[&textview_curses::BM_SEARCH];
3,964✔
599

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

609
    value_out.emplace_back(lr,
4,012✔
610
                           VC_STYLE.value(vc.attrs_for_ident(
8,024✔
611
                               this->lss_token_file->get_filename())));
4,012✔
612

613
    if (this->lss_line_context < line_context_t::none) {
4,012✔
614
        size_t file_offset_end
×
615
            = (this->lss_line_context == line_context_t::filename)
×
616
            ? this->lss_filename_width
×
617
            : this->lss_basename_width;
618

619
        shift_string_attrs(value_out, 0, file_offset_end);
×
620

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

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

687
    if (this->tas_display_time_offset) {
4,012✔
688
        time_offset_end = 13;
210✔
689
        lr.lr_start = 0;
210✔
690
        lr.lr_end = time_offset_end;
210✔
691

692
        shift_string_attrs(value_out, 0, time_offset_end);
210✔
693

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

698
        auto bar_role = role_t::VCR_NONE;
210✔
699

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

715
    lr.lr_start = 0;
4,012✔
716
    lr.lr_end = -1;
4,012✔
717
    value_out.emplace_back(lr, L_FILE.value(this->lss_token_file));
4,012✔
718
    value_out.emplace_back(
4,012✔
719
        lr, SA_FORMAT.value(this->lss_token_file->get_format()->get_name()));
8,024✔
720

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

733
        auto line_meta_opt = this->find_bookmark_metadata(vis_line_t(row));
4,012✔
734

735
        if (line_meta_opt) {
4,012✔
736
            lr.lr_start = 0;
31✔
737
            lr.lr_end = -1;
31✔
738
            value_out.emplace_back(lr, L_META.value(line_meta_opt.value()));
31✔
739
        }
740
    }
741

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

755
    if (this->lss_time_column_size == 0) {
4,012✔
756
        if (this->lss_token_file->is_time_adjusted()) {
4,012✔
757
            auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);
17✔
758

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

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

773
    if (this->ttt_preview_min_time
4,012✔
774
        && this->lss_token_line->get_timeval() < this->ttt_preview_min_time)
4,012✔
775
    {
776
        auto color = styling::color_unit::from_palette(
×
777
            lnav::enums::to_underlying(ansi_color::red));
×
778
        value_out.emplace_back(line_range{0, 1}, VC_BACKGROUND.value(color));
×
779
    }
780
    if (this->ttt_preview_max_time
4,012✔
781
        && this->ttt_preview_max_time < this->lss_token_line->get_timeval())
4,012✔
782
    {
783
        auto color = styling::color_unit::from_palette(
×
784
            lnav::enums::to_underlying(ansi_color::red));
×
785
        value_out.emplace_back(line_range{0, 1}, VC_BACKGROUND.value(color));
×
786
    }
787
    if (!this->lss_token_line->is_continued()) {
4,012✔
788
        if (this->lss_preview_filter_stmt != nullptr) {
2,158✔
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();
2,158✔
820
        if (sql_filter_opt) {
2,158✔
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
    }
2,158✔
838
}
839

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

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

849
        return (*ll_lhs) < (*ll_rhs);
105,060✔
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,432✔
893
{
894
    if (this->tss_view == nullptr) {
4,432✔
895
        return rebuild_result::rr_no_change;
124✔
896
    }
897

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

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

912
    if (force) {
4,308✔
913
        log_debug("forced to full rebuild");
479✔
914
        retval = rebuild_result::rr_full_rebuild;
479✔
915
        full_sort = true;
479✔
916
        this->lss_index.clear();
479✔
917
    }
918

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

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

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

938
                             return left_ld->get_file_ptr()->back()
250✔
939
                                 < right_ld->get_file_ptr()->back();
500✔
940
                         });
941
    }
942

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1167
        for (auto& ld : this->lss_files) {
1,690✔
1168
            auto* lf = ld->get_file_ptr();
552✔
1169

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

1182
        if (full_sort) {
1,138✔
1183
            log_trace("rebuild_index full sort");
1,138✔
1184
            for (auto& ld : this->lss_files) {
1,690✔
1185
                auto* lf = ld->get_file_ptr();
552✔
1186

1187
                if (lf == nullptr) {
552✔
1188
                    continue;
1✔
1189
                }
1190

1191
                for (size_t line_index = 0; line_index < lf->size();
14,794✔
1192
                     line_index++)
1193
                {
1194
                    const auto lf_iter
1195
                        = ld->get_file_ptr()->begin() + line_index;
14,243✔
1196
                    if (lf_iter->is_ignored()) {
14,243✔
1197
                        continue;
417✔
1198
                    }
1199

1200
                    content_line_t con_line(
1201
                        ld->ld_file_index * MAX_LINES_PER_FILE + line_index);
13,826✔
1202

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

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

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

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

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

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

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

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

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

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

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

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

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

1328
            if (lf == nullptr) {
552✔
1329
                continue;
1✔
1330
            }
1331

1332
            (*iter)->ld_lines_indexed = lf->size();
551✔
1333
        }
1334

1335
        this->lss_filtered_index.reserve(this->lss_index.size());
1,138✔
1336

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

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

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

1353
            if (!(*ld)->is_visible()) {
13,826✔
1354
                continue;
×
1355
            }
1356

1357
            auto* lf = (*ld)->get_file_ptr();
13,826✔
1358
            auto line_iter = lf->begin() + line_number;
13,826✔
1359

1360
            if (line_iter->is_ignored()) {
13,826✔
1361
                continue;
×
1362
            }
1363

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

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

1391
        this->lss_indexing_in_progress = false;
1,138✔
1392

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

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

1419
    return retval;
4,308✔
1420
}
4,308✔
1421

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

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

1432
    bm_warnings.clear();
2,207✔
1433
    bm_errors.clear();
2,207✔
1434
    bm_files.clear();
2,207✔
1435

1436
    std::vector<const bookmark_type_t*> used_marks;
2,207✔
1437
    for (const auto* bmt : {
11,035✔
1438
             &textview_curses::BM_USER,
1439
             &textview_curses::BM_USER_EXPR,
1440
             &textview_curses::BM_PARTITION,
1441
             &textview_curses::BM_META,
1442
         })
13,242✔
1443
    {
1444
        bm[bmt].clear();
8,828✔
1445
        if (!this->lss_user_marks[bmt].empty()) {
8,828✔
1446
            used_marks.emplace_back(bmt);
118✔
1447
        }
1448
    }
1449

1450
    for (; vl < (int) this->lss_filtered_index.size(); ++vl) {
19,548✔
1451
        const auto& orig_ic = this->lss_index[this->lss_filtered_index[vl]];
17,341✔
1452
        auto cl = orig_ic.value();
17,341✔
1453
        auto* lf = this->find_file_ptr(cl);
17,341✔
1454

1455
        for (const auto& bmt : used_marks) {
19,479✔
1456
            auto& user_mark = this->lss_user_marks[bmt];
2,138✔
1457
            if (user_mark.bv_tree.exists(orig_ic.value())) {
2,138✔
1458
                bm[bmt].insert_once(vl);
156✔
1459
            }
1460
        }
1461

1462
        if (lf != last_file) {
17,341✔
1463
            bm_files.insert_once(vl);
965✔
1464
        }
1465

1466
        switch (orig_ic.level()) {
17,341✔
1467
            case indexed_content::level_t::warning:
94✔
1468
                bm_warnings.insert_once(vl);
94✔
1469
                break;
94✔
1470

1471
            case indexed_content::level_t::error:
3,420✔
1472
                bm_errors.insert_once(vl);
3,420✔
1473
                break;
3,420✔
1474

1475
            default:
13,827✔
1476
                break;
13,827✔
1477
        }
1478

1479
        last_file = lf;
17,341✔
1480
    }
1481
}
2,207✔
1482

1483
void
1484
logfile_sub_source::text_filters_changed()
166✔
1485
{
1486
    this->lss_index_generation += 1;
166✔
1487

1488
    if (this->lss_line_meta_changed) {
166✔
1489
        this->invalidate_sql_filter();
24✔
1490
        this->lss_line_meta_changed = false;
24✔
1491
    }
1492

1493
    for (auto& ld : *this) {
284✔
1494
        auto* lf = ld->get_file_ptr();
118✔
1495

1496
        if (lf != nullptr) {
118✔
1497
            ld->ld_filter_state.clear_deleted_filter_state();
118✔
1498
            lf->reobserve_from(lf->begin()
118✔
1499
                               + ld->ld_filter_state.get_min_count(lf->size()));
118✔
1500
        }
1501
    }
1502

1503
    if (this->lss_force_rebuild) {
166✔
1504
        return;
×
1505
    }
1506

1507
    auto& vis_bm = this->tss_view->get_bookmarks();
166✔
1508
    uint32_t filtered_in_mask, filtered_out_mask;
1509

1510
    this->get_filters().get_enabled_mask(filtered_in_mask, filtered_out_mask);
166✔
1511

1512
    if (this->lss_index_delegate != nullptr) {
166✔
1513
        this->lss_index_delegate->index_start(*this);
166✔
1514
    }
1515
    vis_bm[&textview_curses::BM_USER_EXPR].clear();
166✔
1516

1517
    this->lss_filtered_index.clear();
166✔
1518
    for (size_t index_index = 0; index_index < this->lss_index.size();
1,494✔
1519
         index_index++)
1520
    {
1521
        auto cl = this->lss_index[index_index].value();
1,328✔
1522
        uint64_t line_number;
1523
        auto ld = this->find_data(cl, line_number);
1,328✔
1524

1525
        if (!(*ld)->is_visible()) {
1,328✔
1526
            continue;
213✔
1527
        }
1528

1529
        auto lf = (*ld)->get_file_ptr();
1,115✔
1530
        auto line_iter = lf->begin() + line_number;
1,115✔
1531

1532
        if (!this->tss_apply_filters
2,230✔
1533
            || (!(*ld)->ld_filter_state.excluded(
2,094✔
1534
                    filtered_in_mask, filtered_out_mask, line_number)
1535
                && this->check_extra_filters(ld, line_iter)))
979✔
1536
        {
1537
            auto eval_res = this->eval_sql_filter(
1538
                this->lss_marker_stmt.in(), ld, line_iter);
937✔
1539
            if (eval_res.isErr()) {
937✔
1540
                line_iter->set_expr_mark(false);
×
1541
            } else {
1542
                auto matched = eval_res.unwrap();
937✔
1543

1544
                line_iter->set_expr_mark(matched);
937✔
1545
                if (matched) {
937✔
1546
                    vis_bm[&textview_curses::BM_USER_EXPR].insert_once(
×
1547
                        vis_line_t(this->lss_filtered_index.size()));
×
1548
                    this->lss_user_marks[&textview_curses::BM_USER_EXPR]
×
1549
                        .insert_once(cl);
×
1550
                }
1551
            }
1552
            this->lss_filtered_index.push_back(index_index);
937✔
1553
            if (this->lss_index_delegate != nullptr) {
937✔
1554
                this->lss_index_delegate->index_line(*this, lf, line_iter);
937✔
1555
            }
1556
        }
937✔
1557
    }
1558

1559
    if (this->lss_index_delegate != nullptr) {
166✔
1560
        this->lss_index_delegate->index_complete(*this);
166✔
1561
    }
1562

1563
    if (this->tss_view != nullptr) {
166✔
1564
        this->tss_view->reload_data();
166✔
1565
        this->tss_view->redo_search();
166✔
1566
    }
1567
}
1568

1569
std::optional<json_string>
1570
logfile_sub_source::text_row_details(const textview_curses& tc)
28✔
1571
{
1572
    if (this->lss_index.empty()) {
28✔
1573
        log_trace("logfile_sub_source::text_row_details empty");
1✔
1574
        return std::nullopt;
1✔
1575
    }
1576

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

1587
                {
1588
                    yajlpp_map root(gen);
×
1589

1590
                    root.gen("value");
×
1591
                    root.gen(iter->second.ri_value);
×
1592
                }
1593

1594
                return json_string(gen);
×
1595
            }
1596
        }
1597
    }
1598

1599
    return std::nullopt;
27✔
1600
}
1601

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

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

1695
std::optional<
1696
    std::pair<grep_proc_source<vis_line_t>*, grep_proc_sink<vis_line_t>*>>
1697
logfile_sub_source::get_grepper()
9✔
1698
{
1699
    return std::make_pair(
18✔
1700
        (grep_proc_source<vis_line_t>*) &this->lss_meta_grepper,
×
1701
        (grep_proc_sink<vis_line_t>*) &this->lss_meta_grepper);
9✔
1702
}
1703

1704
/**
1705
 * Functor for comparing the ld_file field of the logfile_data struct.
1706
 */
1707
struct logfile_data_eq {
1708
    explicit logfile_data_eq(std::shared_ptr<logfile> lf)
1,036✔
1709
        : lde_file(std::move(lf))
1,036✔
1710
    {
1711
    }
1,036✔
1712

1713
    bool operator()(
634✔
1714
        const std::unique_ptr<logfile_sub_source::logfile_data>& ld) const
1715
    {
1716
        return this->lde_file == ld->get_file();
634✔
1717
    }
1718

1719
    std::shared_ptr<logfile> lde_file;
1720
};
1721

1722
bool
1723
logfile_sub_source::insert_file(const std::shared_ptr<logfile>& lf)
518✔
1724
{
1725
    iterator existing;
518✔
1726

1727
    require_lt(lf->size(), MAX_LINES_PER_FILE);
518✔
1728

1729
    existing = std::find_if(this->lss_files.begin(),
518✔
1730
                            this->lss_files.end(),
1731
                            logfile_data_eq(nullptr));
1,036✔
1732
    if (existing == this->lss_files.end()) {
518✔
1733
        if (this->lss_files.size() >= MAX_FILES) {
518✔
1734
            return false;
×
1735
        }
1736

1737
        auto ld = std::make_unique<logfile_data>(
1738
            this->lss_files.size(), this->get_filters(), lf);
518✔
1739
        ld->set_visibility(lf->get_open_options().loo_is_visible);
518✔
1740
        this->lss_files.push_back(std::move(ld));
518✔
1741
    } else {
518✔
1742
        (*existing)->set_file(lf);
×
1743
    }
1744

1745
    return true;
518✔
1746
}
1747

1748
Result<void, lnav::console::user_message>
1749
logfile_sub_source::set_sql_filter(std::string stmt_str, sqlite3_stmt* stmt)
772✔
1750
{
1751
    if (stmt != nullptr && !this->lss_filtered_index.empty()) {
772✔
1752
        auto top_cl = this->at(0_vl);
8✔
1753
        auto ld = this->find_data(top_cl);
8✔
1754
        auto eval_res
1755
            = this->eval_sql_filter(stmt, ld, (*ld)->get_file_ptr()->begin());
8✔
1756

1757
        if (eval_res.isErr()) {
8✔
1758
            sqlite3_finalize(stmt);
1✔
1759
            return Err(eval_res.unwrapErr());
1✔
1760
        }
1761
    }
8✔
1762

1763
    for (auto& ld : *this) {
788✔
1764
        ld->ld_filter_state.lfo_filter_state.clear_filter_state(0);
17✔
1765
    }
1766

1767
    auto old_filter = this->get_sql_filter();
771✔
1768
    if (stmt != nullptr) {
771✔
1769
        auto new_filter
1770
            = std::make_shared<sql_filter>(*this, std::move(stmt_str), stmt);
7✔
1771

1772
        if (old_filter) {
7✔
1773
            auto existing_iter = std::find(this->tss_filters.begin(),
×
1774
                                           this->tss_filters.end(),
1775
                                           old_filter.value());
×
1776
            *existing_iter = new_filter;
×
1777
        } else {
1778
            this->tss_filters.add_filter(new_filter);
7✔
1779
        }
1780
    } else if (old_filter) {
771✔
1781
        this->tss_filters.delete_filter(old_filter.value()->get_id());
7✔
1782
    }
1783

1784
    return Ok();
771✔
1785
}
771✔
1786

1787
Result<void, lnav::console::user_message>
1788
logfile_sub_source::set_sql_marker(std::string stmt_str, sqlite3_stmt* stmt)
769✔
1789
{
1790
    static auto op = lnav_operation{"set_sql_marker"};
769✔
1791
    if (stmt != nullptr && !this->lss_filtered_index.empty()) {
769✔
1792
        auto top_cl = this->at(0_vl);
5✔
1793
        auto ld = this->find_data(top_cl);
5✔
1794
        auto eval_res
1795
            = this->eval_sql_filter(stmt, ld, (*ld)->get_file_ptr()->begin());
5✔
1796

1797
        if (eval_res.isErr()) {
5✔
1798
            sqlite3_finalize(stmt);
×
1799
            return Err(eval_res.unwrapErr());
×
1800
        }
1801
    }
5✔
1802

1803
    auto op_guard = lnav_opid_guard::internal(op);
769✔
1804
    log_info("setting SQL marker: %s", stmt_str.c_str());
769✔
1805
    this->lss_marker_stmt_text = std::move(stmt_str);
769✔
1806
    this->lss_marker_stmt = stmt;
769✔
1807

1808
    if (this->tss_view == nullptr || this->lss_force_rebuild) {
769✔
1809
        log_info("skipping SQL marker update");
130✔
1810
        return Ok();
130✔
1811
    }
1812

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

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

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

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

1843
            ll->set_expr_mark(matched);
432✔
1844
            if (matched) {
432✔
1845
                expr_marks_bv.insert_once(row);
22✔
1846
                cl_marks_bv.insert_once(cl);
22✔
1847
            }
1848
        }
1849
        if (this->lss_index_delegate) {
432✔
1850
            this->lss_index_delegate->index_line(
432✔
1851
                *this, (*ld)->get_file_ptr(), ll);
432✔
1852
        }
1853
    }
432✔
1854
    if (this->lss_index_delegate) {
639✔
1855
        this->lss_index_delegate->index_complete(*this);
639✔
1856
    }
1857
    log_info("SQL marker update complete");
639✔
1858

1859
    return Ok();
639✔
1860
}
769✔
1861

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

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

1877
    this->lss_preview_filter_stmt = stmt;
764✔
1878

1879
    return Ok();
764✔
1880
}
1881

1882
Result<bool, lnav::console::user_message>
1883
logfile_sub_source::eval_sql_filter(sqlite3_stmt* stmt,
15,351✔
1884
                                    iterator ld,
1885
                                    logfile::const_iterator ll)
1886
{
1887
    if (stmt == nullptr) {
15,351✔
1888
        return Ok(false);
29,472✔
1889
    }
1890

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

1904
    sqlite3_reset(stmt);
615✔
1905
    sqlite3_clear_bindings(stmt);
615✔
1906

1907
    auto count = sqlite3_bind_parameter_count(stmt);
615✔
1908
    for (int lpc = 0; lpc < count; lpc++) {
1,242✔
1909
        const auto* name = sqlite3_bind_parameter_name(stmt, lpc + 1);
627✔
1910

1911
        if (name[0] == '$') {
627✔
1912
            const char* env_value;
1913

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

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

1989
                yajl_gen_config(gen, yajl_gen_beautify, false);
1✔
1990

1991
                {
1992
                    yajlpp_array arr(gen);
1✔
1993

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

1999
                string_fragment sf = gen.to_string_fragment();
1✔
2000

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

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

2076
            if (res.isOk()) {
×
2077
                raw_sbr = res.unwrap();
×
2078
                sqlite3_bind_text(stmt,
×
2079
                                  lpc + 1,
2080
                                  raw_sbr.get_data(),
2081
                                  raw_sbr.length(),
×
2082
                                  SQLITE_STATIC);
2083
            }
2084
            continue;
×
2085
        }
2086
        for (const auto& lv : values.lvv_values) {
6,782✔
2087
            if (lv.lv_meta.lvm_name != &name[1]) {
6,777✔
2088
                continue;
6,201✔
2089
            }
2090

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

2116
    auto step_res = sqlite3_step(stmt);
615✔
2117

2118
    sqlite3_reset(stmt);
615✔
2119
    sqlite3_clear_bindings(stmt);
615✔
2120
    switch (step_res) {
615✔
2121
        case SQLITE_OK:
474✔
2122
        case SQLITE_DONE:
2123
            return Ok(false);
948✔
2124
        case SQLITE_ROW:
140✔
2125
            return Ok(true);
280✔
2126
        default:
1✔
2127
            return Err(sqlite3_error_to_user_message(sqlite3_db_handle(stmt)));
1✔
2128
    }
2129
}
615✔
2130

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

2157
    if (ll->get_msg_level() < this->lss_min_log_level) {
14,772✔
2158
        return false;
2✔
2159
    }
2160

2161
    if (*ll < this->ttt_min_row_time) {
14,770✔
2162
        return false;
36✔
2163
    }
2164

2165
    if (!(*ll <= this->ttt_max_row_time)) {
14,734✔
2166
        return false;
4✔
2167
    }
2168

2169
    return true;
14,730✔
2170
}
2171

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

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

2189
    auto cl = this->at(line);
148✔
2190

2191
    if (bm == &textview_curses::BM_USER) {
148✔
2192
        auto* ll = this->find_line(cl);
59✔
2193

2194
        ll->set_mark(added);
59✔
2195
    }
2196
    if (added) {
148✔
2197
        this->lss_user_marks[bm].insert_once(cl);
67✔
2198
    } else {
2199
        this->lss_user_marks[bm].erase(cl);
81✔
2200
    }
2201
    if (bm == &textview_curses::BM_META
148✔
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)
518✔
2225
{
2226
    auto iter = std::find_if(
518✔
2227
        this->lss_files.begin(), this->lss_files.end(), logfile_data_eq(lf));
1,036✔
2228
    if (iter != this->lss_files.end()) {
518✔
2229
        int file_index = iter - this->lss_files.begin();
518✔
2230

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

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

2247
                for (auto cl : to_del) {
178✔
2248
                    bv.erase(cl);
109✔
2249
                }
2250
            }
69✔
2251
        }
2252

2253
        this->lss_force_rebuild = true;
518✔
2254
    }
2255
    while (!this->lss_files.empty()) {
1,036✔
2256
        if (this->lss_files.back()->get_file_ptr() == nullptr) {
569✔
2257
            this->lss_files.pop_back();
518✔
2258
        } else {
2259
            break;
51✔
2260
        }
2261
    }
2262
    this->lss_token_file = nullptr;
518✔
2263
}
518✔
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()
641✔
2304
{
2305
    if (this->lss_index_delegate == nullptr) {
641✔
2306
        return;
×
2307
    }
2308

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

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

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

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

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

2341
    auto iter = this->llh_history.begin();
94✔
2342
    iter += this->llh_history.size() - this->lh_history_position;
94✔
2343
    this->llh_history.erase_from(iter);
94✔
2344
    this->lh_history_position = 0;
94✔
2345
    this->llh_history.push_back(cl);
94✔
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,
124✔
2400
                    const shared_buffer_ref& line)
2401
{
2402
    if (!ls_opt) {
124✔
2403
        return false;
×
2404
    }
2405

2406
    auto ls = ls_opt;
124✔
2407

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

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

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

2427
    return true;
47✔
2428
}
121✔
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(
4,107✔
2945
    vis_line_t vl, bookmark_metadata::categories desired) const
2946
{
2947
    const auto& vb = this->tss_view->get_bookmarks();
4,107✔
2948
    const auto& bv = vb[desired == bookmark_metadata::categories::partition
2949
                            ? &textview_curses::BM_PARTITION
2950
                            : &textview_curses::BM_META];
4,107✔
2951
    auto vl_iter = bv.bv_tree.lower_bound(vl + 1_vl);
4,107✔
2952

2953
    std::optional<vis_line_t> next_line;
4,107✔
2954
    for (auto next_vl_iter = vl_iter; next_vl_iter != bv.bv_tree.end();
4,107✔
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()) {
4,107✔
2968
        return bookmark_metadata_context{std::nullopt, std::nullopt, next_line};
4,091✔
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
23,218✔
2992
{
2993
    auto line_pair = this->find_line_with_file(cl).value();
23,218✔
2994
    auto line_number = static_cast<uint32_t>(
2995
        std::distance(line_pair.first->begin(), line_pair.second));
23,218✔
2996

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

3003
    return &bm_iter->second;
362✔
3004
}
23,218✔
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
222✔
3091
{
3092
    switch (this->lss_line_context) {
222✔
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:
222✔
3098
            return 0;
222✔
3099
    }
3100
}
3101

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

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

3114
    return retval;
4,009✔
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)
263✔
3166
{
3167
    auto lb = std::lower_bound(this->lss_filtered_index.begin(),
526✔
3168
                               this->lss_filtered_index.end(),
3169
                               ri.ri_time,
263✔
3170
                               filtered_logline_cmp(*this));
3171
    if (lb != this->lss_filtered_index.end()) {
263✔
3172
        auto first_lb = lb;
258✔
3173
        while (true) {
3174
            auto cl = this->lss_index[*lb].value();
272✔
3175
            if (content_line_t(ri.ri_id) == cl) {
272✔
3176
                first_lb = lb;
226✔
3177
                break;
226✔
3178
            }
3179
            auto ll = this->find_line(cl);
46✔
3180
            if (ll->get_timeval() != ri.ri_time) {
46✔
3181
                break;
32✔
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);
258✔
3192
        return vis_line_t(dst);
258✔
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)
35✔
3200
{
3201
    return std::make_unique<logline_window>(*this, start_vl, end_vl);
35✔
3202
}
3203

3204
std::unique_ptr<logline_window>
3205
logfile_sub_source::window_at(vis_line_t start_vl)
201✔
3206
{
3207
    return std::make_unique<logline_window>(*this, start_vl, start_vl + 1_vl);
201✔
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
{
3390
    if (mouse_line.is<listview_curses::static_overlay_content>()
×
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)
662✔
3421
{
3422
    static const auto& cfg
3423
        = injector::get<const logfile_sub_source_ns::config&>();
662✔
3424

3425
    switch (cfg.c_time_column) {
662✔
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:
662✔
3432
            if (this->lss_line_context == line_context_t::time_column) {
662✔
3433
                this->lss_line_context = line_context_t::none;
×
3434
            }
3435
            break;
662✔
3436
        case logfile_sub_source_ns::time_column_feature_t::Enabled:
×
3437
            break;
×
3438
    }
3439
}
662✔
3440

3441
void
3442
logfile_sub_source::add_commands_for_session(
47✔
3443
    const std::function<void(const std::string&)>& receiver)
3444
{
3445
    text_sub_source::add_commands_for_session(receiver);
47✔
3446

3447
    auto mark_expr = this->get_sql_marker_text();
47✔
3448
    if (!mark_expr.empty()) {
47✔
3449
        receiver(fmt::format(FMT_STRING("mark-expr {}"), mark_expr));
4✔
3450
    }
3451
    auto filter_expr = this->get_sql_filter_text();
47✔
3452
    if (!filter_expr.empty()) {
47✔
3453
        receiver(fmt::format(FMT_STRING("filter-expr {}"), filter_expr));
×
3454
    }
3455

3456
    for (const auto& format : log_format::get_root_formats()) {
3,522✔
3457
        auto field_states = format->get_field_states();
3,475✔
3458

3459
        for (const auto& fs_pair : field_states) {
47,294✔
3460
            if (!fs_pair.second.lvm_user_hidden) {
43,819✔
3461
                continue;
43,817✔
3462
            }
3463

3464
            if (fs_pair.second.lvm_user_hidden.value()) {
2✔
3465
                receiver(fmt::format(FMT_STRING("hide-fields {}.{}"),
8✔
3466
                                     format->get_name().to_string(),
4✔
3467
                                     fs_pair.first.to_string()));
4✔
3468
            } else if (fs_pair.second.lvm_hidden) {
×
3469
                receiver(fmt::format(FMT_STRING("show-fields {}.{}"),
×
3470
                                     format->get_name().to_string(),
×
3471
                                     fs_pair.first.to_string()));
×
3472
            }
3473
        }
3474
    }
3,475✔
3475
}
47✔
3476

3477
void
3478
logfile_sub_source::update_filter_hash_state(hasher& h) const
5✔
3479
{
3480
    text_sub_source::update_filter_hash_state(h);
5✔
3481

3482
    for (const auto& ld : this->lss_files) {
5✔
3483
        if (ld->get_file_ptr() == nullptr || !ld->is_visible()) {
×
3484
            h.update(0);
×
3485
        } else {
3486
            h.update(1);
×
3487
        }
3488
    }
3489
    h.update(this->lss_min_log_level);
5✔
3490
    h.update(this->lss_marked_only);
5✔
3491
}
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