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

randombit / botan / 19012754211

02 Nov 2025 01:10PM UTC coverage: 90.677% (+0.006%) from 90.671%
19012754211

push

github

web-flow
Merge pull request #5137 from randombit/jack/clang-tidy-includes

Remove various unused includes flagged by clang-tidy misc-include-cleaner

100457 of 110786 relevant lines covered (90.68%)

12189873.8 hits per line

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

90.24
/src/cli/timer.cpp
1
/*
2
* (C) 2018 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "timer.h"
8

9
#include <chrono>
10
#include <sstream>
11

12
#if defined(BOTAN_HAS_OS_UTILS)
13
   #include <botan/internal/os_utils.h>
14
#endif
15

16
namespace Botan_CLI {
17

18
namespace {
19

20
std::string format_timer_name(std::string_view name, std::string_view provider) {
506✔
21
   if(provider.empty() || provider == "base") {
507✔
22
      return std::string(name);
486✔
23
   }
24

25
   std::ostringstream out;
20✔
26
   out << name << " [" << provider << "]";
20✔
27
   return out.str();
20✔
28
}
20✔
29

30
}  // namespace
31

32
Timer::Timer(std::string_view name,
506✔
33
             std::string_view provider,
34
             std::string_view doing,
35
             uint64_t event_mult,
36
             size_t buf_size,
37
             double clock_cycle_ratio,
38
             uint64_t clock_speed) :
506✔
39
      m_name(format_timer_name(name, provider)),
506✔
40
      m_doing(doing),
1,012✔
41
      m_buf_size(buf_size),
506✔
42
      m_event_mult(event_mult),
506✔
43
      m_clock_cycle_ratio(clock_cycle_ratio),
506✔
44
      m_clock_speed(clock_speed) {}
506✔
45

46
void Timer::start() {
21,281✔
47
   stop();
21,281✔
48
   m_timer_start = timestamp_ns();
42,562✔
49
   m_cpu_cycles_start = cycle_counter();
42,562✔
50
}
21,281✔
51

52
uint64_t Timer::timestamp_ns() {
42,562✔
53
   auto now = std::chrono::high_resolution_clock::now().time_since_epoch();
42,562✔
54
   return std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
42,562✔
55
}
56

57
uint64_t Timer::cycle_counter() {
42,562✔
58
#if defined(BOTAN_HAS_OS_UTILS)
59
   return Botan::OS::get_cpu_cycle_counter();
21,281✔
60
#else
61
   return 0;
62
#endif
63
}
64

65
void Timer::stop() {
42,562✔
66
   if(m_timer_start != 0) {
42,562✔
67
      const uint64_t now = timestamp_ns();
21,281✔
68

69
      if(now > m_timer_start) {
21,281✔
70
         m_time_used += (now - m_timer_start);
21,281✔
71
      }
72

73
      if(m_cpu_cycles_start != 0) {
21,281✔
74
         const uint64_t cycles_taken = cycle_counter() - m_cpu_cycles_start;
21,281✔
75
         if(cycles_taken > 0) {
21,281✔
76
            m_cpu_cycles_used += static_cast<size_t>(cycles_taken * m_clock_cycle_ratio);
21,281✔
77
         }
78
      }
79

80
      m_timer_start = 0;
21,281✔
81
      ++m_event_count;
21,281✔
82
   }
83
}
42,562✔
84

85
bool Timer::operator<(const Timer& other) const {
×
86
   if(this->doing() != other.doing()) {
×
87
      return (this->doing() < other.doing());
×
88
   }
89

90
   return (this->get_name() < other.get_name());
×
91
}
92

93
}  // namespace Botan_CLI
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