• 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

68.42
/src/timeline_source.hh
1
/**
2
 * Copyright (c) 2023, 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 lnav_timeline_source_hh
31
#define lnav_timeline_source_hh
32

33
#include <functional>
34
#include <vector>
35

36
#include "base/attr_line.hh"
37
#include "base/map_util.hh"
38
#include "base/progress.hh"
39
#include "logfile_sub_source.hh"
40
#include "plain_text_source.hh"
41
#include "text_overlay_menu.hh"
42
#include "textview_curses.hh"
43
#include "timeline_status_source.hh"
44

45
class timeline_preview_overlay : public list_overlay_source {
46
public:
47
    std::vector<attr_line_t> list_overlay_menu(const listview_curses& lv,
48
                                               vis_line_t line) override;
49
};
50

51
class timeline_source
52
    : public text_sub_source
53
    , public list_input_delegate
54
    , public text_time_translator
55
    , public text_delegate {
56
public:
57
    explicit timeline_source(textview_curses& log_view,
58
                             logfile_sub_source& lss,
59
                             textview_curses& preview_view,
60
                             plain_text_source& preview_source,
61
                             statusview_curses& preview_status_view,
62
                             timeline_status_source& preview_status_source);
63

UNCOV
64
    bool empty() const override { return false; }
×
65

66
    bool list_input_handle_key(listview_curses& lv, const ncinput& ch) override;
67

68
    bool text_handle_mouse(textview_curses& tc,
69
                           const listview_curses::display_line_content_t&,
70
                           mouse_event& me) override;
71

72
    size_t text_line_count() override;
73

74
    size_t text_line_width(textview_curses& curses) override;
75

76
    line_info text_value_for_line(textview_curses& tc,
77
                                  int line,
78
                                  std::string& value_out,
79
                                  line_flags_t flags) override;
80

81
    void text_attrs_for_line(textview_curses& tc,
82
                             int line,
83
                             string_attrs_t& value_out) override;
84

85
    size_t text_size_for_line(textview_curses& tc,
86
                              int line,
87
                              line_flags_t raw) override;
88

89
    void text_selection_changed(textview_curses& tc) override;
90

91
    void text_filters_changed() override;
92
    int get_filtered_count() const override;
93
    int get_filtered_count_for(size_t filter_index) const override;
94

95
    void text_crumbs_for_line(int line,
96
                              std::vector<breadcrumb::crumb>& crumbs) override;
97

98
    std::optional<vis_line_t> row_for_time(struct timeval time_bucket) override;
99
    std::optional<row_info> time_for_row(vis_line_t row) override;
100

101
    bool rebuild_indexes();
102

103
    std::pair<timeval, timeval> get_time_bounds_for(int line);
104

105
    textview_curses& gs_log_view;
106
    logfile_sub_source& gs_lss;
107
    textview_curses& gs_preview_view;
108
    plain_text_source& gs_preview_source;
109
    statusview_curses& gs_preview_status_view;
110
    timeline_status_source& gs_preview_status_source;
111
    ArenaAlloc::Alloc<char> gs_allocator{64 * 1024};
112

113
    struct opid_description_def_key {
114
        intern_string_t oddk_format_name;
115
        intern_string_t oddk_desc_name;
116

117
        bool operator<(const opid_description_def_key& rhs) const
1,992✔
118
        {
119
            if (this->oddk_format_name < rhs.oddk_format_name) {
1,992✔
UNCOV
120
                return true;
×
121
            }
122
            if (this->oddk_format_name == rhs.oddk_format_name) {
1,992✔
123
                return this->oddk_desc_name < rhs.oddk_desc_name;
1,992✔
124
            }
125

UNCOV
126
            return false;
×
127
        }
128
    };
129

130
    struct opid_description_defs {
131
        lnav::map::small<opid_description_def_key, log_format::opid_descriptors>
132
            odd_defs;
133
    };
134

135
    using timeline_subid_map
136
        = robin_hood::unordered_map<string_fragment,
137
                                    bool,
138
                                    frag_hasher,
139
                                    std::equal_to<string_fragment>>;
140

141
    timeline_subid_map gs_subid_map;
142

143
    struct opid_row {
144
        string_fragment or_name;
145
        opid_time_range or_value;
146
        string_fragment or_description;
147
        opid_description_defs or_description_defs;
148
        lnav::map::small<opid_description_def_key,
149
                         lnav::map::small<size_t, std::string>>
150
            or_descriptions;
151
        size_t or_max_subid_width{0};
152

153
        bool operator<(const opid_row& rhs) const
5,058✔
154
        {
155
            if (this->or_value.otr_range < rhs.or_value.otr_range) {
5,058✔
156
                return true;
2,388✔
157
            }
158
            if (this->or_value.otr_range.tr_begin
5,340✔
159
                    == rhs.or_value.otr_range.tr_begin
2,670✔
160
                && this->or_name < rhs.or_name)
2,670✔
161
            {
UNCOV
162
                return true;
×
163
            }
164

165
            return false;
2,670✔
166
        }
167
    };
168

169
    using timeline_opid_row_map
170
        = robin_hood::unordered_map<string_fragment,
171
                                    opid_row,
172
                                    frag_hasher,
173
                                    std::equal_to<string_fragment>>;
174
    using timeline_desc_map
175
        = robin_hood::unordered_set<string_fragment,
176
                                    frag_hasher,
177
                                    std::equal_to<string_fragment>>;
178

179
    timeline_preview_overlay gs_preview_overlay;
180
    attr_line_t gs_rendered_line;
181
    size_t gs_opid_width{0};
182
    size_t gs_total_width{0};
183
    timeline_opid_row_map gs_active_opids;
184
    timeline_desc_map gs_descriptions;
185
    std::vector<std::reference_wrapper<opid_row>> gs_time_order;
186
    timeval gs_lower_bound{};
187
    timeval gs_upper_bound{};
188
    size_t gs_filtered_count{0};
189
    std::array<size_t, logfile_filter_state::MAX_FILTERS> gs_filter_hits{};
190
    exec_context* gs_exec_context{nullptr};
191
    bool gs_preview_focused{false};
192
    std::vector<row_info> gs_preview_rows;
193

194
    struct progress_t {
195
        size_t p_curr{0};
196
        size_t p_total{0};
197
    };
198

199
    std::function<lnav::progress_result_t(std::optional<progress_t>)>
200
        gs_index_progress;
201
};
202

203
class timeline_header_overlay : public text_overlay_menu {
204
public:
205
    explicit timeline_header_overlay(
206
        const std::shared_ptr<timeline_source>& src);
207

208
    bool list_static_overlay(const listview_curses& lv,
209
                             int y,
210
                             int bottom,
211
                             attr_line_t& value_out) override;
212

213
    std::optional<attr_line_t> list_header_for_overlay(
214
        const listview_curses& lv, vis_line_t line) override;
215

216
    void list_value_for_overlay(const listview_curses& lv,
217
                                vis_line_t line,
218
                                std::vector<attr_line_t>& value_out) override;
219

UNCOV
220
    void set_show_details_in_overlay(bool val) override
×
221
    {
UNCOV
222
        this->gho_show_details = val;
×
223
    }
224

225
    bool get_show_details_in_overlay() const override
2✔
226
    {
227
        return this->gho_show_details;
2✔
228
    }
229

230
private:
231
    bool gho_show_details{false};
232
    std::shared_ptr<timeline_source> gho_src;
233
};
234

235
#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