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

llnl / dftracer-utils / 29119036378

10 Jul 2026 07:44PM UTC coverage: 52.775% (+0.09%) from 52.688%
29119036378

Pull #87

github

web-flow
Merge a50187f92 into a382a566d
Pull Request #87: fix(comparator): fix wrong counting files

39413 of 96771 branches covered (40.73%)

Branch coverage included in aggregate %.

57 of 61 new or added lines in 9 files covered. (93.44%)

3 existing lines in 3 files now uncovered.

35056 of 44336 relevant lines covered (79.07%)

21258.84 hits per line

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

48.18
/src/dftracer/utils/core/utils/timer.cpp
1
#include <dftracer/utils/core/common/logging.h>
2
#include <dftracer/utils/core/utils/timer.h>
3

4
#include <algorithm>
5
#include <cinttypes>
6
#include <cstdio>
7
#include <utility>
8
#include <vector>
9

10
namespace dftracer::utils {
11

12
Timer::Timer(bool autostart, bool verbose)
76!
13
    : verbose_(verbose), running_(false) {
57✔
14
    if (autostart) {
38✔
15
        start();
38!
16
    }
19✔
17
}
57✔
18

19
Timer::Timer(const std::string& name, bool autostart, bool verbose)
76!
20
    : verbose_(verbose), running_(false), name_(name) {
57✔
21
    if (autostart) {
38✔
22
        start();
6!
23
    }
3✔
24
}
57✔
25

26
Timer::Timer(const char* name, bool autostart, bool verbose)
38✔
27
    : Timer(std::string(name), autostart, verbose) {}
38!
28

29
Timer::~Timer() {
132✔
30
    stop();
88!
31
    if (verbose_) {
88✔
32
        if (name_.empty()) {
×
33
            std::printf("Elapsed time: %" PRId64 " ns\n", elapsed());
×
34
        } else {
35
            std::printf("[%s] Elapsed time: %" PRId64 " ns\n", name_.c_str(),
×
36
                        elapsed());
×
37
        }
38
    }
39
}
132✔
40

41
void Timer::start() {
44✔
42
    start_time = Clock::now();
44✔
43
    running_ = true;
44✔
44
}
44✔
45

46
void Timer::stop() {
114✔
47
    if (running_) {
114✔
48
        end_time = Clock::now();
56✔
49
        running_ = false;
56✔
50
    }
28✔
51
}
114✔
52

53
std::int64_t Timer::elapsed() const {
40✔
54
    if (running_) {
40✔
55
        return std::chrono::duration_cast<std::chrono::nanoseconds>(
21!
56
                   Clock::now() - start_time)
21!
57
            .count();
14✔
58
    } else {
59
        return std::chrono::duration_cast<std::chrono::nanoseconds>(end_time -
65!
60
                                                                    start_time)
26✔
61
            .count();
26✔
62
    }
63
}
20✔
64

65
void Timer::increment(const std::string& key, std::uint64_t by) {
16✔
66
    counters_[key] += by;
16✔
67
}
16✔
68

69
void Timer::set_counter(const std::string& key, std::uint64_t value) {
×
70
    counters_[key] = value;
×
71
}
×
72

73
const std::unordered_map<std::string, std::uint64_t>& Timer::counters() const {
6✔
74
    return counters_;
6✔
75
}
76

77
void Timer::print_stages(const std::string& prefix) const {
×
78
    if (counters_.empty()) return;
×
79

80
    std::vector<std::pair<std::string, std::uint64_t>> sorted(counters_.begin(),
81
                                                              counters_.end());
×
82
    std::sort(sorted.begin(), sorted.end());
×
83

84
    std::uint64_t total_ns = 0;
×
85
    for (const auto& [_, ns] : sorted) total_ns += ns;
×
86

87
    if (!name_.empty()) {
×
88
        std::printf("%s%s (%.2f ms)\n", prefix.c_str(), name_.c_str(),
×
89
                    static_cast<double>(total_ns) / 1e6);
×
90
    }
91
    for (std::size_t i = 0; i < sorted.size(); ++i) {
×
92
        const auto& [key, ns] = sorted[i];
×
93
        bool last = (i + 1 == sorted.size());
×
94
        double ms = static_cast<double>(ns) / 1e6;
×
NEW
95
        double pct = total_ns > 0 ? 100.0 * static_cast<double>(ns) /
×
NEW
96
                                        static_cast<double>(total_ns)
×
97
                                  : 0.0;
UNCOV
98
        std::printf("%s%s %-28s %8.2f ms  (%5.1f%%)\n", prefix.c_str(),
×
99
                    last ? "\\-- " : "|-- ", key.c_str(), ms, pct);
×
100
    }
101
}
×
102

103
}  // namespace dftracer::utils
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