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

tstack / lnav / 23418727412-2872

23 Mar 2026 02:22AM UTC coverage: 69.027% (+0.02%) from 69.01%
23418727412-2872

push

github

tstack
[tests] add expected for filter test

52768 of 76445 relevant lines covered (69.03%)

522597.39 hits per line

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

98.04
/src/filter_observer.cc
1
/**
2
 * Copyright (c) 2019, 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 <iterator>
32

33
#include "filter_observer.hh"
34

35
#include "base/lnav_log.hh"
36
#include "config.h"
37
#include "log_format.hh"
38
#include "shared_buffer.hh"
39

40
void
41
line_filter_observer::logline_clear(const logfile& lf)
5✔
42
{
43
    this->lfo_filter_state.clear_for_rebuild();
5✔
44
}
5✔
45

46
bool
47
line_filter_observer::logline_new_lines(const logfile& lf,
19,723✔
48
                                        logfile::const_iterator ll_begin,
49
                                        logfile::const_iterator ll_end,
50
                                        const shared_buffer_ref& sbr)
51
{
52
    const auto offset = std::distance(lf.begin(), ll_begin);
19,723✔
53

54
    require(&lf == this->lfo_filter_state.tfs_logfile.get());
19,723✔
55

56
    auto retval = false;
19,723✔
57

58
    this->lfo_filter_state.resize(lf.size());
19,723✔
59
    if (this->lfo_filter_stack.empty()) {
19,723✔
60
        return retval;
18,823✔
61
    }
62

63
    for (; ll_begin != ll_end; ++ll_begin) {
2,355✔
64
        auto sbr_copy = sbr.clone();
1,455✔
65
        auto* format = lf.get_format_ptr();
1,455✔
66
        if (format != nullptr) {
1,455✔
67
            format->get_subline(
1,440✔
68
                lf.get_format_file_state(), *ll_begin, sbr_copy);
2,880✔
69
        }
70
        sbr_copy.erase_ansi();
1,455✔
71
        for (const auto& filter : this->lfo_filter_stack) {
2,963✔
72
            if (filter->lf_deleted) {
1,508✔
73
                continue;
×
74
            }
75
            if (offset >= (ssize_t) this->lfo_filter_state
1,508✔
76
                              .tfs_filter_count[filter->get_index()])
1,508✔
77
            {
78
                retval = filter->add_line(
2,910✔
79
                             this->lfo_filter_state, ll_begin, sbr_copy)
1,455✔
80
                    || retval;
1,455✔
81
            }
82
        }
83
    }
1,455✔
84

85
    return retval;
900✔
86
}
87

88
void
89
line_filter_observer::logline_eof(const logfile& lf)
2,497✔
90
{
91
    this->lfo_filter_state.reserve(lf.size() + lf.estimated_remaining_lines());
2,497✔
92
    for (const auto& iter : this->lfo_filter_stack) {
2,660✔
93
        if (iter->lf_deleted) {
163✔
94
            continue;
4✔
95
        }
96
        iter->end_of_message(this->lfo_filter_state);
159✔
97
    }
98
}
2,497✔
99

100
size_t
101
line_filter_observer::get_min_count(size_t max) const
128✔
102
{
103
    size_t retval = max;
128✔
104

105
    for (const auto& filter : this->lfo_filter_stack) {
196✔
106
        if (filter->lf_deleted) {
68✔
107
            continue;
4✔
108
        }
109
        retval = std::min(
64✔
110
            retval,
111
            this->lfo_filter_state.tfs_filter_count[filter->get_index()]);
64✔
112
    }
113

114
    return retval;
128✔
115
}
116

117
void
118
line_filter_observer::clear_deleted_filter_state()
128✔
119
{
120
    uint32_t used_mask = 0;
128✔
121

122
    for (auto& filter : this->lfo_filter_stack) {
196✔
123
        if (filter->lf_deleted) {
68✔
124
            log_debug("skipping deleted %p %zu %d",
4✔
125
                      filter.get(),
126
                      filter->get_index(),
127
                      filter->get_lang());
128
            continue;
4✔
129
        }
130
        used_mask |= (1UL << filter->get_index());
64✔
131
    }
132
    this->lfo_filter_state.clear_deleted_filter_state(used_mask);
128✔
133
}
128✔
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