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

vbpf / ebpf-verifier / 14231336081

02 Apr 2025 11:08PM UTC coverage: 87.272% (-0.9%) from 88.177%
14231336081

push

github

web-flow
Propogate ebpf_verifier_options_t to thread_local_options (#856)

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

5 of 5 new or added lines in 2 files covered. (100.0%)

58 existing lines in 19 files now uncovered.

8324 of 9538 relevant lines covered (87.27%)

4881701.3 hits per line

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

5.63
/src/crab_utils/stats.cpp
1
// Copyright (c) Prevail Verifier contributors.
2
// SPDX-License-Identifier: Apache-2.0
3
#include "stats.hpp"
4

5
#include <optional>
6
#ifdef _WIN32
7
#include <windows.h>
8
#undef max
9
#else
10
#include <sys/resource.h>
11
#include <sys/time.h>
12
#endif
13

14
namespace crab {
15

16
thread_local crab::lazy_allocator<std::map<std::string, unsigned>> CrabStats::counters;
17
thread_local crab::lazy_allocator<std::map<std::string, Stopwatch>> CrabStats::sw;
18

19
void CrabStats::clear_thread_local_state() {
×
20
    counters.clear();
×
21
    sw.clear();
×
22
}
×
23

24
// Gets the amount of user CPU time used, in microseconds.
25
long Stopwatch::systemTime() const {
×
26
#ifdef _WIN32
27
    FILETIME creation_time, exit_time, kernel_time, user_time;
28
    if (!GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time)) {
29
        return 0;
30
    }
31

32
    // Convert from 100ns intervals to microseconds.
33
    uint64_t total_us =
34
        ((static_cast<uint64_t>(user_time.dwHighDateTime) << 32) | static_cast<uint64_t>(user_time.dwLowDateTime)) / 10;
35

36
    return (long)total_us;
37
#else
UNCOV
38
    struct rusage ru;
×
39
    getrusage(RUSAGE_SELF, &ru);
×
40
    const long r = ru.ru_utime.tv_sec * 1000000L + ru.ru_utime.tv_usec;
×
41
    return r;
×
42
#endif
43
}
44

45
Stopwatch::Stopwatch() { start(); }
×
46

47
void Stopwatch::start() {
×
48
    started = systemTime();
×
49
    finished = -1;
×
50
    timeElapsed = 0;
×
51
}
×
52

53
void Stopwatch::stop() {
×
54
    if (finished < started) {
×
55
        finished = systemTime();
×
56
    }
57
}
×
58

59
void Stopwatch::resume() {
×
60
    if (finished >= started) {
×
61
        timeElapsed += finished - started;
×
62
        started = systemTime();
×
63
        finished = -1;
×
64
    }
65
}
×
66

67
long Stopwatch::getTimeElapsed() const {
×
68
    if (finished < started) {
×
69
        return timeElapsed + systemTime() - started;
×
70
    } else {
71
        return timeElapsed + finished - started;
×
72
    }
73
}
74

75
double Stopwatch::toSeconds() const { return static_cast<double>(getTimeElapsed()) / 1000000; }
×
76

77
void Stopwatch::Print(std::ostream& out) const {
×
78
    const long time = getTimeElapsed();
×
79
    const long h = time / 3600000000L;
×
80
    const long m = time / 60000000L - h * 60;
×
81
    const float s = ((float)time / 1000000L) - m * 60 - h * 3600;
×
82

83
    if (h > 0) {
×
84
        out << h << "h";
×
85
    }
86
    if (m > 0) {
×
87
        out << m << "m";
×
88
    }
89
    out << s << "s";
×
90
}
×
91

92
void CrabStats::reset() {
×
93
    counters.clear();
×
94
    sw.clear();
×
95
}
×
96

97
void CrabStats::count_max(const std::string& name, const unsigned v) {
×
98
    (*counters)[name] = std::max((*counters)[name], v);
×
99
}
×
100

101
unsigned CrabStats::uset(const std::string& n, const unsigned v) { return (*counters)[n] = v; }
×
102
unsigned CrabStats::get(const std::string& n) { return (*counters)[n]; }
×
103

104
/** Outputs all statistics to std output */
105
void CrabStats::Print(std::ostream& OS) {
×
106
    OS << "\n\n************** STATS ***************** \n";
×
107
    for (const auto& kv : (*counters)) {
×
108
        OS << kv.first << ": " << kv.second << "\n";
×
109
    }
110
    for (const auto& kv : (*sw)) {
×
111
        OS << kv.first << ": " << kv.second << "\n";
×
112
    }
113
    OS << "************** STATS END ***************** \n";
×
114
}
×
115

116
void CrabStats::PrintBrunch(std::ostream& OS) {
×
117
    OS << "\n\n************** BRUNCH STATS ***************** \n";
×
118
    for (const auto& kv : *counters) {
×
119
        OS << "BRUNCH_STAT " << kv.first << " " << kv.second << "\n";
×
120
    }
121
    for (const auto& kv : *sw) {
×
122
        OS << "BRUNCH_STAT " << kv.first << " " << kv.second.toSeconds() << "sec \n";
×
123
    }
124
    OS << "************** BRUNCH STATS END ***************** \n";
×
125
}
×
126

127
ScopedCrabStats::ScopedCrabStats(const std::string& name, const bool reset) : m_name(name) {
5,043,159✔
128
    if (reset) {
5,043,159✔
129
        m_name += ".last";
×
130
        CrabStats::start(m_name);
131
    } else {
132
        CrabStats::resume(m_name);
133
    }
134
}
5,043,159✔
135

136
ScopedCrabStats::~ScopedCrabStats() { CrabStats::stop(m_name); }
5,043,159✔
137

138
} // namespace crab
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

© 2025 Coveralls, Inc