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

tstack / lnav / 18889873042-2614

28 Oct 2025 09:33PM UTC coverage: 68.919% (+0.03%) from 68.891%
18889873042-2614

push

github

tstack
[test] fix rust tracing thread stuff

50245 of 72904 relevant lines covered (68.92%)

428705.0 hits per line

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

95.45
/src/all_logs_vtab.cc
1
/**
2
 * Copyright (c) 2020, 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 "all_logs_vtab.hh"
31

32
#include "base/attr_line.hh"
33
#include "base/intern_string.hh"
34
#include "config.h"
35
#include "data_parser.hh"
36
#include "elem_to_json.hh"
37
#include "hasher.hh"
38
#include "scn/scan.h"
39

40
#ifdef HAVE_RUST_DEPS
41
#    include "lnav_rs_ext.cxx.hh"
42
#endif
43

44
static auto intern_lifetime = intern_string::get_table_lifetime();
45

46
all_logs_vtab::all_logs_vtab()
610✔
47
    : log_vtab_impl(intern_string::lookup("all_logs")),
48
      alv_msg_meta(intern_string::lookup("log_msg_format"),
1,220✔
49
                   value_kind_t::VALUE_TEXT,
50
                   logline_value_meta::table_column{0}),
610✔
51
      alv_schema_meta(intern_string::lookup("log_msg_schema"),
1,830✔
52
                      value_kind_t::VALUE_TEXT,
53
                      logline_value_meta::table_column{1}),
610✔
54
      alv_values_meta(intern_string::lookup("log_msg_values"),
1,830✔
55
                      value_kind_t::VALUE_JSON,
56
                      logline_value_meta::table_column{2}),
610✔
57
      alv_src_meta(intern_string::lookup("log_msg_src"),
1,830✔
58
                   value_kind_t::VALUE_JSON,
59
                   logline_value_meta::table_column{3}),
610✔
60
      alv_thread_meta(intern_string::lookup("log_thread_id"),
1,830✔
61
                      value_kind_t::VALUE_TEXT,
62
                      logline_value_meta::table_column{4}),
610✔
63
      alv_stacktrace_meta(intern_string::lookup("log_stack_trace"),
1,830✔
64
                          value_kind_t::VALUE_TEXT,
65
                          logline_value_meta::table_column{5})
2,440✔
66
{
67
    this->alv_msg_meta.lvm_identifier = true;
610✔
68
    this->alv_schema_meta.lvm_identifier = true;
610✔
69
    this->alv_thread_meta.lvm_identifier = true;
610✔
70
    this->alv_thread_meta.lvm_foreign_key = true;
610✔
71
}
610✔
72

73
void
74
all_logs_vtab::get_columns(std::vector<vtab_column>& cols) const
610✔
75
{
76
    cols.emplace_back(
610✔
77
        vtab_column(this->alv_msg_meta.lvm_name.get())
3,660✔
78
            .with_comment(
79
                "The message format with variables replaced by hash marks"));
80
    cols.emplace_back(this->alv_schema_meta.lvm_name.get(),
610✔
81
                      SQLITE3_TEXT,
×
82
                      "",
83
                      true,
610✔
84
                      "The ID for the message schema");
85
    cols.emplace_back(this->alv_values_meta.lvm_name.get(),
610✔
86
                      SQLITE3_TEXT,
×
87
                      "",
88
                      false,
610✔
89
                      "The values extracted from the message");
90
    cols.emplace_back(this->alv_src_meta.lvm_name.get(),
610✔
91
                      SQLITE3_TEXT,
×
92
                      "",
93
                      false,
610✔
94
                      "The source code that generated this message");
95
    cols.emplace_back(this->alv_thread_meta.lvm_name.get(),
610✔
96
                      SQLITE3_TEXT,
×
97
                      "",
98
                      false,
610✔
99
                      "The ID of the thread that generated this message");
100
    cols.emplace_back(this->alv_stacktrace_meta.lvm_name.get(),
610✔
101
                      SQLITE3_TEXT,
×
102
                      "",
103
                      false,
610✔
104
                      "If found, the stack trace details");
105
}
610✔
106

107
void
108
all_logs_vtab::extract(logfile* lf,
136✔
109
                       uint64_t line_number,
110
                       string_attrs_t& sa,
111
                       logline_value_vector& values)
112
{
113
    auto& line = values.lvv_sbr;
136✔
114
    auto* format = lf->get_format_ptr();
136✔
115

116
    logline_value_vector sub_values;
136✔
117

118
    sa.clear();
136✔
119
    sub_values.lvv_sbr = line.clone();
136✔
120
    format->annotate(lf, line_number, sa, sub_values, false);
136✔
121

122
    auto body = find_string_attr_range(sa, &SA_BODY);
136✔
123
    if (!body.is_valid()) {
136✔
124
        body.lr_start = 0;
43✔
125
        body.lr_end = line.length();
43✔
126
    }
127
    auto body_sf = line.to_string_fragment(body);
136✔
128
    auto src_file = find_string_attr_range(sa, &SA_SRC_FILE);
136✔
129
    auto src_line = find_string_attr_range(sa, &SA_SRC_LINE);
136✔
130
    auto src_file_sf = line.to_string_fragment(src_file);
136✔
131
    auto src_line_sf = line.to_string_fragment(src_line);
136✔
132
    auto h = hasher();
136✔
133
    if (src_file_sf.is_valid() && src_line_sf.is_valid()) {
136✔
134
        h.update(format->get_name().c_str());
30✔
135
        h.update(src_file_sf);
30✔
136
        h.update(src_line_sf);
30✔
137
    }
138
#ifdef HAVE_RUST_DEPS
139
    auto file_rust_str = rust::Str();
136✔
140
    auto lineno = 0UL;
136✔
141
    if (src_file_sf.is_valid()) {
136✔
142
        file_rust_str = rust::Str(src_file_sf.data(), src_file_sf.length());
30✔
143
    }
144
    if (src_line_sf.is_valid()) {
136✔
145
        auto scan_res
146
            = scn::scan_int<decltype(lineno)>(src_line_sf.to_string_view());
30✔
147
        if (scan_res) {
30✔
148
            lineno = scan_res->value();
30✔
149
        }
150
    }
151
    auto body_rust_str = rust::Str(body_sf.data(), body_sf.length());
136✔
152
    auto find_res = lnav_rs_ext::find_log_statement_json(
153
        file_rust_str, lineno, body_rust_str);
136✔
154
    if (find_res != nullptr) {
136✔
155
        if (!src_file_sf.is_valid() || !src_line_sf.is_valid()) {
5✔
156
            h.update(find_res->src.c_str());
10✔
157
            h.update(find_res->pattern.c_str());
10✔
158
        }
159
        auto line_iter = lf->begin() + line_number;
5✔
160
        if (!line_iter->has_schema()) {
5✔
161
            line_iter->set_schema(h.to_array());
5✔
162
        }
163
        values.lvv_values.emplace_back(this->alv_msg_meta,
5✔
164
                                       (std::string) find_res->pattern);
10✔
165
        values.lvv_values.emplace_back(this->alv_schema_meta, h.to_string());
5✔
166
        values.lvv_values.emplace_back(this->alv_values_meta,
5✔
167
                                       (std::string) find_res->variables);
10✔
168
        values.lvv_values.emplace_back(this->alv_src_meta,
5✔
169
                                       (std::string) find_res->src);
10✔
170
        if (!find_res->stack_trace.empty()) {
5✔
171
            values.lvv_values.emplace_back(this->alv_stacktrace_meta,
1✔
172
                                           (std::string) find_res->stack_trace);
2✔
173
        }
174
    } else
175
#endif
176
    {
177
        data_scanner ds(body_sf);
131✔
178
        data_parser dp(&ds);
131✔
179
        std::string str;
131✔
180

181
        dp.dp_msg_format = &str;
131✔
182
        dp.parse();
131✔
183

184
        yajlpp_gen gen;
131✔
185
        yajl_gen_config(gen, yajl_gen_beautify, false);
131✔
186

187
        elements_to_json(gen, dp, &dp.dp_pairs);
131✔
188

189
        auto schema_id = (src_file_sf.is_valid() && src_line_sf.is_valid())
161✔
190
            ? h.to_string()
131✔
191
            : dp.dp_schema_id.to_string();
131✔
192
        values.lvv_values.emplace_back(this->alv_msg_meta, std::move(str));
131✔
193
        values.lvv_values.emplace_back(this->alv_schema_meta, schema_id);
131✔
194
        values.lvv_values.emplace_back(
262✔
195
            this->alv_values_meta,
131✔
196
            json_string(gen).to_string_fragment().to_string());
262✔
197
    }
131✔
198
    if (sub_values.lvv_thread_id_value) {
136✔
199
        values.lvv_values.emplace_back(this->alv_thread_meta,
57✔
200
                                       sub_values.lvv_thread_id_value.value());
201
    } else {
202
        values.lvv_values.emplace_back(this->alv_thread_meta);
79✔
203
    }
204
    values.lvv_opid_value = std::move(sub_values.lvv_opid_value);
136✔
205
    values.lvv_opid_provenance = sub_values.lvv_opid_provenance;
136✔
206
}
136✔
207

208
bool
209
all_logs_vtab::next(log_cursor& lc, logfile_sub_source& lss)
141✔
210
{
211
    return true;
141✔
212
}
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