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

tstack / lnav / 17955647695-2537

23 Sep 2025 06:33PM UTC coverage: 64.851% (-0.1%) from 64.974%
17955647695-2537

push

github

tstack
[build] left local path in cargo

45984 of 70907 relevant lines covered (64.85%)

406352.74 hits per line

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

90.91
/src/base/distributed_slice.hh
1
/**
2
 * Copyright (c) 2025, 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_distributed_slice
31
#define lnav_distributed_slice
32

33
#include <vector>
34

35
#define DS_STRINGIZE(A) #A
36

37
#if defined(__APPLE__)
38
#    define DIST_SLICE(id) \
39
        __attribute__((no_sanitize_address, \
40
                       used, \
41
                       section("__DATA,__ds_" DS_STRINGIZE( \
42
                           id) ",regular,no_dead_strip")))
43
#    define DIST_SLICE_BEGIN(id) \
44
        __asm("section$start$__DATA$__ds_" DS_STRINGIZE(id))
45
#    define DIST_SLICE_END(id) \
46
        __asm("section$end$__DATA$__ds_" DS_STRINGIZE(id))
47
#else
48
#    define DIST_SLICE(id) \
49
        __attribute__(( \
50
            no_sanitize_address, used, section("ds_" DS_STRINGIZE(id))))
51
#    define DIST_SLICE_BEGIN(id) __asm("__start_ds_" DS_STRINGIZE(id))
52
#    define DIST_SLICE_END(id)   __asm("__stop_ds_" DS_STRINGIZE(id))
53
#endif
54

55
template<typename T>
56
struct dist_slice_container {
57
    using iterator = T*;
58
    using const_iterator = const T*;
59

60
    constexpr dist_slice_container(iterator start, iterator end)
61
        : ds_start(start), ds_end(end)
62
    {
63
    }
64

65
    constexpr iterator begin() { return this->ds_start; }
×
66

67
    constexpr const_iterator begin() const { return this->ds_start; }
68,271✔
68

69
    constexpr iterator end() { return this->ds_end; }
×
70

71
    constexpr const_iterator end() const { return this->ds_end; }
1,155✔
72

73
    size_t size() const { return this->ds_end - this->ds_start; }
23,136✔
74

75
    template<typename U>
76
    struct slice_indexed_array {
77
        using iterator = typename std::vector<U>::iterator;
78

79
        explicit slice_indexed_array(const dist_slice_container& slices)
23,135✔
80
            : sia_slices(slices), sia_array(std::vector<U>(slices.size()))
46,270✔
81
        {
82
        }
23,135✔
83

84
        U& operator[](const T* slice)
64,286✔
85
        {
86
            auto index = std::distance(this->sia_slices.begin(), slice);
64,286✔
87
            return this->sia_array[index];
64,286✔
88
        }
89

90
        const U& operator[](const T* slice) const
2,830✔
91
        {
92
            auto index = std::distance(this->sia_slices.begin(), slice);
2,830✔
93
            return this->sia_array[index];
2,830✔
94
        }
95

96
        iterator begin() { return this->sia_array.begin(); }
487✔
97

98
        iterator end() { return this->sia_array.end(); }
487✔
99

100
        void clear()
12,615✔
101
        {
102
            for (auto& elem : this->sia_array) {
113,535✔
103
                elem.clear();
100,920✔
104
            }
105
        }
12,615✔
106

107
    private:
108
        const dist_slice_container& sia_slices;
109
        std::vector<U> sia_array;
110
    };
111

112
    template<typename U>
113
    slice_indexed_array<U> create_array_indexed_by() const
23,135✔
114
    {
115
        return slice_indexed_array<U>(*this);
23,135✔
116
    }
117

118
private:
119
    iterator ds_start;
120
    iterator ds_end;
121
};
122

123
#define DIST_SLICE_CONTAINER(T, id) \
124
    (+[]() -> auto { \
125
        extern T start DIST_SLICE_BEGIN(id); \
126
        extern T end DIST_SLICE_END(id); \
127
\
128
        return dist_slice_container<T>(&start, &end); \
129
    })()
130

131
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc