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

llnl / dftracer-utils / 27052412546

06 Jun 2026 04:20AM UTC coverage: 50.862% (+1.0%) from 49.905%
27052412546

Pull #73

github

web-flow
Merge 734572730 into 88a3c8457
Pull Request #73: add portable dependencies wheel support

31801 of 79859 branches covered (39.82%)

Branch coverage included in aggregate %.

32491 of 46545 relevant lines covered (69.81%)

9947.11 hits per line

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

44.09
/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)
105!
13
    : verbose_(verbose), running_(false) {
70✔
14
    if (autostart) {
35!
15
        start();
35!
16
    }
35✔
17
}
70✔
18

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

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

38
void Timer::start() {
38✔
39
    start_time = Clock::now();
38✔
40
    running_ = true;
38✔
41
}
38✔
42

43
void Timer::stop() {
57✔
44
    if (running_) {
57✔
45
        end_time = Clock::now();
44✔
46
        running_ = false;
44✔
47
    }
44✔
48
}
57✔
49

50
std::int64_t Timer::elapsed() const {
20✔
51
    if (running_) {
20✔
52
        return std::chrono::duration_cast<std::chrono::nanoseconds>(
14✔
53
                   Clock::now() - start_time)
7✔
54
            .count();
7✔
55
    } else {
56
        return std::chrono::duration_cast<std::chrono::nanoseconds>(end_time -
39✔
57
                                                                    start_time)
13✔
58
            .count();
13✔
59
    }
60
}
20✔
61

62
void Timer::increment(const std::string& key, std::uint64_t by) {
8✔
63
    counters_[key] += by;
8✔
64
}
8✔
65

66
void Timer::set_counter(const std::string& key, std::uint64_t value) {
×
67
    counters_[key] = value;
×
68
}
×
69

70
const std::unordered_map<std::string, std::uint64_t>& Timer::counters() const {
3✔
71
    return counters_;
3✔
72
}
73

74
void Timer::print_stages(const std::string& prefix) const {
×
75
    if (counters_.empty()) return;
×
76

77
    std::vector<std::pair<std::string, std::uint64_t>> sorted(counters_.begin(),
×
78
                                                              counters_.end());
×
79
    std::sort(sorted.begin(), sorted.end());
×
80

81
    std::uint64_t total_ns = 0;
×
82
    for (const auto& [_, ns] : sorted) total_ns += ns;
×
83

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

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