• 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

81.82
/src/spectro_source.hh
1
/**
2
 * Copyright (c) 2016, 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
 * @file spectroview_curses.hh
30
 */
31

32
#ifndef spectro_source_hh
33
#define spectro_source_hh
34

35
#include <chrono>
36
#include <functional>
37
#include <unordered_map>
38
#include <vector>
39

40
#include <math.h>
41

42
#include "hasher.hh"
43
#include "statusview_curses.hh"
44
#include "textview_curses.hh"
45

46
struct exec_context;
47

48
struct spectrogram_bounds {
49
    std::chrono::microseconds sb_begin_time{0};
50
    std::chrono::microseconds sb_end_time{0};
51
    double sb_min_value_out{0.0};
52
    double sb_max_value_out{0.0};
53
    int64_t sb_count{0};
54
};
55

56
struct spectrogram_thresholds {
57
    int st_green_threshold{0};
58
    int st_yellow_threshold{0};
59
};
60

61
struct spectrogram_request {
62
    explicit spectrogram_request(spectrogram_bounds& sb) : sr_bounds(sb) {}
27✔
63

64
    spectrogram_bounds& sr_bounds;
65
    unsigned long sr_width{0};
66
    std::chrono::microseconds sr_begin_time{0};
9✔
67
    std::chrono::microseconds sr_end_time{0};
9✔
68
    double sr_column_size{0};
69
};
70

71
struct spectrogram_row {
72
    spectrogram_row() = default;
2✔
73
    spectrogram_row(const spectrogram_row&) = delete;
74

75
    struct row_bucket {
76
        int rb_counter{0};
77
        int rb_marks{0};
78
    };
79

80
    std::vector<row_bucket> sr_values;
81
    unsigned long sr_width{0};
82
    double sr_column_size{0.0};
83
    std::function<std::unique_ptr<text_sub_source>(
84
        const spectrogram_request&, double range_min, double range_max)>
85
        sr_details_source_provider;
86

87
    void add_value(spectrogram_request& sr, double value, bool marked)
197✔
88
    {
89
        long index = std::floor((value - sr.sr_bounds.sb_min_value_out)
197✔
90
                                / sr.sr_column_size);
197✔
91

92
        this->sr_values[index].rb_counter += 1;
197✔
93
        if (marked) {
197✔
UNCOV
94
            this->sr_values[index].rb_marks += 1;
×
95
        }
96
    }
197✔
97

98
    std::optional<size_t> nearest_column(size_t current) const;
99
};
100

101
class spectrogram_value_source {
102
public:
103
    virtual ~spectrogram_value_source() = default;
5✔
104

105
    virtual void spectro_bounds(spectrogram_bounds& sb_out) = 0;
106

107
    virtual void spectro_row(spectrogram_request& sr, spectrogram_row& row_out)
108
        = 0;
109

110
    virtual void spectro_mark(textview_curses& tc,
111
                              std::chrono::microseconds begin_time,
112
                              std::chrono::microseconds end_time,
113
                              double range_min,
114
                              double range_max)
115
        = 0;
116
};
117

118
class spectrogram_source
119
    : public text_sub_source
120
    , public text_time_translator
121
    , public list_overlay_source
122
    , public list_input_delegate
123
    , public text_delegate {
124
public:
125
    ~spectrogram_source() override = default;
1,158✔
126

UNCOV
127
    bool empty() const override { return this->ss_details_source == nullptr; }
×
128

129
    void invalidate()
5✔
130
    {
131
        this->ss_cached_bounds.sb_count = 0;
5✔
132
        this->ss_row_cache.clear();
5✔
133
        this->ss_cursor_column = std::nullopt;
5✔
134
        this->ss_cursor_details_checksum.clear();
5✔
135
    }
5✔
136

137
    bool list_input_handle_key(listview_curses& lv, const ncinput& ch) override;
138

139
    bool text_handle_mouse(textview_curses& tc,
140
                           const listview_curses::display_line_content_t&,
141
                           mouse_event& me) override;
142

143
    bool list_static_overlay(const listview_curses& lv,
144
                             int y,
145
                             int bottom,
146
                             attr_line_t& value_out) override;
147

148
    void list_value_for_overlay(const listview_curses& lv,
149
                                vis_line_t row,
150
                                std::vector<attr_line_t>& value_out) override;
151

152
    size_t text_line_count() override;
153

154
    size_t text_line_width(textview_curses& tc) override;
155

UNCOV
156
    size_t text_size_for_line(textview_curses& tc,
×
157
                              int row,
158
                              line_flags_t flags) override
159
    {
UNCOV
160
        return 0;
×
161
    }
162

163
    bool text_is_row_selectable(textview_curses& tc, vis_line_t row) override;
164

165
    void text_selection_changed(textview_curses& tc) override;
166

167
    std::optional<row_info> time_for_row(vis_line_t row) override;
168

169
    std::optional<vis_line_t> row_for_time(struct timeval time_bucket) override;
170

171
    line_info text_value_for_line(textview_curses& tc,
172
                                  int row,
173
                                  std::string& value_out,
174
                                  line_flags_t flags) override;
175

176
    void text_attrs_for_line(textview_curses& tc,
177
                             int row,
178
                             string_attrs_t& value_out) override;
179

180
    void chart_attrs_for_line(textview_curses& tc,
181
                              int row,
182
                              string_attrs_t& value_out);
183

184
    void cache_bounds();
185

186
    std::optional<row_info> time_for_row_int(vis_line_t row);
187

188
    const spectrogram_row& load_row(const listview_curses& lv, int row);
189

190
    void reset_details_source();
191

192
    textview_curses* ss_details_view{nullptr};
193
    text_sub_source* ss_no_details_source{nullptr};
194
    exec_context* ss_exec_context{nullptr};
195
    std::unique_ptr<text_sub_source> ss_details_source;
196
    std::chrono::microseconds ss_granularity
197
        = std::chrono::duration_cast<std::chrono::microseconds>(
198
            std::chrono::seconds{60});
199
    spectrogram_value_source* ss_value_source{nullptr};
200
    spectrogram_bounds ss_cached_bounds;
201
    spectrogram_thresholds ss_cached_thresholds;
202
    size_t ss_cached_line_count{0};
203
    std::unordered_map<std::chrono::microseconds,
204
                       spectrogram_row,
205
                       lnav::duration_hasher>
206
        ss_row_cache;
207
    std::optional<size_t> ss_cursor_column;
208
    attr_line_t ss_cursor_details;
209
    hasher::array_t ss_cursor_details_checksum;
210
};
211

212
class spectro_status_source : public status_data_source {
213
public:
214
    enum field_t {
215
        F_TITLE,
216
        F_HELP,
217

218
        F_MAX
219
    };
220

221
    spectro_status_source();
222

223
    size_t statusview_fields() override;
224

225
    status_field& statusview_value_for_field(int field) override;
226

227
private:
228
    status_field sss_fields[F_MAX];
229
};
230

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