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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

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

73.68
/src/db_sub_source.hh
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
#ifndef db_sub_source_hh
31
#define db_sub_source_hh
32

33
#include <chrono>
34
#include <map>
35
#include <memory>
36
#include <optional>
37
#include <string>
38
#include <vector>
39

40
#include <sqlite3.h>
41

42
#include "ArenaAlloc/arenaalloc.h"
43
#include "base/cell_container.hh"
44
#include "base/lnav.resolver.hh"
45
#include "hist_source.hh"
46
#include "textview_curses.hh"
47

48
class db_label_source
49
    : public text_sub_source
50
    , public text_time_translator
51
    , public list_input_delegate
52
    , public text_delegate
53
    , public text_detail_provider {
54
public:
55
    bool has_log_time_column() const { return !this->dls_time_column.empty(); }
52✔
56

57
    bool empty() const override { return this->dls_headers.empty(); }
×
58

59
    size_t text_line_count() override { return this->dls_row_cursors.size(); }
16,841✔
60

61
    size_t text_size_for_line(textview_curses& tc,
×
62
                              int line,
63
                              line_flags_t flags) override
64
    {
UNCOV
65
        return this->text_line_width(tc);
×
66
    }
67

68
    size_t text_line_width(textview_curses& curses) override
5,717✔
69
    {
70
        size_t retval = 0;
5,717✔
71

72
        for (const auto& dls_header : this->dls_headers) {
6,428✔
73
            retval += dls_header.hm_column_size + 1;
711✔
74
        }
75
        return retval;
5,717✔
76
    }
77

78
    line_info text_value_for_line(textview_curses& tc,
79
                                  int row,
80
                                  std::string& label_out,
81
                                  line_flags_t flags) override;
82

83
    void text_attrs_for_line(textview_curses& tc,
84
                             int row,
85
                             string_attrs_t& sa) override;
86

87
    void push_header(const std::string& colstr, int type);
88

89
    void set_col_as_graphable(int lpc);
90

91
    using column_value_t
92
        = mapbox::util::variant<string_fragment, int64_t, double, null_value_t>;
93

94
    static_assert(!column_value_t::needs_destruct);
95
    void push_column(const column_value_t& sv);
96

97
    void clear();
98

99
    std::optional<size_t> column_name_to_index(const std::string& name) const;
100

101
    std::optional<vis_line_t> row_for_time(timeval time_bucket) override;
102

103
    std::optional<row_info> time_for_row(vis_line_t row) override;
104

105
    bool text_handle_mouse(textview_curses& tc,
106
                           const listview_curses::display_line_content_t&,
107
                           mouse_event& me) override;
108

109
    bool list_input_handle_key(listview_curses& lv, const ncinput& ch) override;
110

111
    std::string get_row_as_string(vis_line_t row);
112

113
    std::optional<json_string> text_row_details(
114
        const textview_curses& tc) override;
115

116
    std::string get_cell_as_string(vis_line_t row, size_t col);
117
    std::optional<int64_t> get_cell_as_int64(vis_line_t row, size_t col);
118
    std::optional<double> get_cell_as_double(vis_line_t row, size_t col);
119

120
    void update_time_column(const timeval& tv);
121
    void update_time_column(const string_fragment& sf);
122

123
    void reset_user_state();
124

125
    struct header_meta {
126
        explicit header_meta(std::string name) : hm_name(std::move(name)) {}
2,908✔
127

128
        bool operator==(const std::string& name) const
48✔
129
        {
130
            return this->hm_name == name;
48✔
131
        }
132

133
        bool is_graphable() const
20,041✔
134
        {
135
            return this->hm_graphable && this->hm_graphable.value();
20,041✔
136
        }
137

138
        std::string hm_name;
139
        int hm_column_type{SQLITE3_TEXT};
140
        unsigned int hm_sub_type{0};
141
        bool hm_hidden{false};
142
        std::optional<bool> hm_graphable;
143
        size_t hm_column_size{0};
144
        text_align_t hm_align{text_align_t::start};
145
        text_attrs hm_title_attrs{text_attrs::with_underline()};
146
        stacked_bar_chart<std::string> hm_chart;
147
    };
148

149
    struct row_style {
150
        std::map<int, text_attrs> rs_column_config;
151
    };
152

153
    uint32_t dls_generation{0};
154
    std::optional<std::chrono::steady_clock::time_point> dls_query_start;
155
    std::optional<std::chrono::steady_clock::time_point> dls_query_end;
156
    size_t dls_max_column_width{120};
157
    std::vector<header_meta> dls_headers;
158
    lnav::cell_container dls_cell_container;
159
    std::vector<lnav::cell_container::cursor> dls_row_cursors;
160
    size_t dls_push_column{0};
161
    std::vector<timeval> dls_time_column;
162
    std::vector<size_t> dls_cell_width;
163
    size_t dls_time_column_index{SIZE_MAX};
164
    std::optional<size_t> dls_time_column_invalidated_at;
165
    std::optional<size_t> dls_level_column;
166
    std::vector<row_style> dls_row_styles;
167
    bool dls_row_styles_have_errors{false};
168
    size_t dls_row_style_column{SIZE_MAX};
169
    ArenaAlloc::Alloc<char> dls_cell_allocator{1024};
170
    string_attrs_t dls_ansi_attrs;
171

172
    static const unsigned char NULL_STR[];
173
};
174

175
class db_overlay_source : public list_overlay_source {
176
public:
177
    bool list_static_overlay(const listview_curses& lv,
178
                             int y,
179
                             int bottom,
180
                             attr_line_t& value_out) override;
181

182
    void list_value_for_overlay(const listview_curses& lv,
183
                                vis_line_t line,
184
                                std::vector<attr_line_t>& value_out) override;
185

186
    std::optional<attr_line_t> list_header_for_overlay(
187
        const listview_curses& lv, vis_line_t line) override;
188

UNCOV
189
    void set_show_details_in_overlay(bool val) override
×
190
    {
UNCOV
191
        this->dos_active = val;
×
192
    }
193

194
    bool get_show_details_in_overlay() const override
2✔
195
    {
196
        return this->dos_active;
2✔
197
    }
198

199
    bool dos_active{false};
200
    db_label_source* dos_labels{nullptr};
201
};
202

203
#endif
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