• 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.08
/src/pollable.cc
1
/**
2
 * Copyright (c) 2022, 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

32
#include "pollable.hh"
33

34
#include "base/itertools.hh"
35
#include "base/lnav_log.hh"
36

37
pollable::pollable(std::shared_ptr<pollable_supervisor> supervisor,
20✔
38
                   category cat)
20✔
39
    : p_supervisor(supervisor), p_category(cat)
20✔
40
{
41
    log_debug("pollable attach %p to %p", this, this->p_supervisor.get());
20✔
42
    this->p_supervisor->attach(this);
20✔
43
}
20✔
44

45
pollable::~pollable()
20✔
46
{
47
    log_debug("pollable detach %p from %p", this, this->p_supervisor.get());
20✔
48
    this->p_supervisor->detach(this);
20✔
49
}
20✔
50

51
pollable_supervisor::update_result
52
pollable_supervisor::update_poll_set(std::vector<struct pollfd>& pollfds)
2,074✔
53
{
54
    update_result retval;
2,074✔
55
    size_t old_size = pollfds.size();
2,074✔
56

57
    for (auto& pol : this->b_components) {
2,176✔
58
        pol->update_poll_set(pollfds);
102✔
59
        switch (pol->get_category()) {
102✔
60
            case pollable::category::background:
102✔
61
                retval.ur_background += pollfds.size() - old_size;
102✔
62
                break;
102✔
UNCOV
63
            case pollable::category::interactive:
×
UNCOV
64
                retval.ur_interactive += pollfds.size() - old_size;
×
UNCOV
65
                break;
×
66
        }
67
        old_size = pollfds.size();
102✔
68
    }
69

70
    return retval;
2,074✔
71
}
72

73
void
74
pollable_supervisor::check_poll_set(const std::vector<struct pollfd>& pollfds)
25✔
75
{
76
    std::vector<pollable*> visited;
25✔
77
    auto found_new = false;
25✔
78

79
    // TODO move this loop into the superclass
80
    do {
75✔
81
        found_new = false;
75✔
82
        for (auto* pol : this->b_components) {
150✔
83
            if (std::find(visited.begin(), visited.end(), pol) == visited.end())
125✔
84
            {
85
                visited.emplace_back(pol);
50✔
86
                pol->check_poll_set(pollfds);
50✔
87
                found_new = true;
50✔
88
                break;
50✔
89
            }
90
        }
91
    } while (found_new);
92
}
25✔
93

94
size_t
UNCOV
95
pollable_supervisor::count(pollable::category cat)
×
96
{
UNCOV
97
    size_t retval = 0;
×
98

UNCOV
99
    for (const auto* pol : this->b_components) {
×
UNCOV
100
        if (pol->get_category() == cat) {
×
UNCOV
101
            retval += 1;
×
102
        }
103
    }
104

105
    return retval;
×
106
}
107

108
short
109
pollfd_revents(const std::vector<struct pollfd>& pollfds, int fd)
×
110
{
111
    return pollfds | lnav::itertools::find_if([fd](const auto& entry) {
×
UNCOV
112
               return entry.fd == fd;
×
113
           })
UNCOV
114
        | lnav::itertools::deref() | lnav::itertools::map(&pollfd::revents)
×
115
        | lnav::itertools::unwrap_or((short) 0);
×
116
}
117

118
bool
119
pollfd_ready(const std::vector<struct pollfd>& pollfds, int fd, short events)
82✔
120
{
121
    return std::any_of(
82✔
122
        pollfds.begin(), pollfds.end(), [fd, events](const auto& entry) {
200✔
123
            return entry.fd == fd && entry.revents & events;
200✔
124
        });
82✔
125
}
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