Skip to content

Commit 904d1e9

Browse files
committed
util: Minor updates to Statman
1 parent 4780d29 commit 904d1e9

3 files changed

Lines changed: 14 additions & 32 deletions

File tree

api/util/statman.hpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,27 @@
2525
#include <membitmap>
2626
#include <smp_utils>
2727

28-
/** This type is thrown when Statman's span is full */
2928
struct Stats_out_of_memory : public std::out_of_range {
3029
explicit Stats_out_of_memory()
31-
: std::out_of_range(std::string{"Statman has no room for more statistics"})
30+
: std::out_of_range("Statman has no room for more statistics")
3231
{}
33-
}; //< struct Stats_out_of_memory
32+
};
3433

35-
36-
/** This type is thrown from within the operations of class Statman */
3734
struct Stats_exception : public std::runtime_error {
3835
using runtime_error::runtime_error;
39-
}; //< struct Stats_exception
36+
};
4037

41-
///
42-
///
43-
///
4438
class Stat {
4539
public:
46-
static const int MAX_NAME_LEN {47};
47-
///
48-
///
49-
///
40+
static const int MAX_NAME_LEN = 47;
41+
5042
enum Stat_type: uint8_t
5143
{
5244
FLOAT,
5345
UINT32,
5446
UINT64
5547
};
5648

57-
///
58-
///
59-
///
6049
Stat(const Stat_type type, const std::string& name);
6150
~Stat() = default;
6251

@@ -93,7 +82,7 @@ class Stat {
9382
};
9483
Stat_type type_;
9584

96-
char name_[MAX_NAME_LEN];
85+
char name_[MAX_NAME_LEN+1];
9786

9887
Stat(const Stat& other) = delete;
9988
Stat(const Stat&& other) = delete;

src/kernel/timers.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ struct alignas(SMP_ALIGN) timer_system
6565
// timers sorted by timestamp
6666
std::multimap<duration_t, Timers::id_t> scheduled;
6767
/** Stats */
68-
int64_t* oneshot_started;
69-
int64_t* oneshot_stopped;
70-
uint32_t* periodic_started;
71-
uint32_t* periodic_stopped;
68+
int64_t* oneshot_started = nullptr;
69+
int64_t* oneshot_stopped = nullptr;
70+
uint32_t* periodic_started = nullptr;
71+
uint32_t* periodic_stopped = nullptr;
7272
};
7373
static SMP_ARRAY<timer_system> systems;
7474

@@ -83,7 +83,7 @@ void Timers::init(const start_func_t& start, const stop_func_t& stop)
8383
system.arch_start_func = start;
8484
system.arch_stop_func = stop;
8585

86-
std::string CPU = "cpu" + std::to_string(SMP::cpu_id());
86+
const std::string CPU = "cpu" + std::to_string(SMP::cpu_id());
8787
system.oneshot_started = (int64_t*) &Statman::get().create(Stat::UINT64, CPU + ".timers.oneshot_started").get_uint64();
8888
system.oneshot_stopped = (int64_t*) &Statman::get().create(Stat::UINT64, CPU + ".timers.oneshot_stopped").get_uint64();
8989
system.periodic_started = &Statman::get().create(Stat::UINT32, CPU + ".timers.periodic_started").get_uint32();

src/util/statman.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,11 @@ Statman& Statman::get() {
2828

2929
///////////////////////////////////////////////////////////////////////////////
3030
Stat::Stat(const Stat_type type, const std::string& name)
31-
: type_{type}
31+
: ui64(0), type_{type}
3232
{
3333
if(name.size() > MAX_NAME_LEN)
3434
throw Stats_exception{"Creating stat: Name cannot be longer than " + std::to_string(MAX_NAME_LEN) + " characters"};
3535

36-
switch (type) {
37-
case UINT32: ui32 = 0; break;
38-
case UINT64: ui64 = 0; break;
39-
case FLOAT: f = 0.0f; break;
40-
default: throw Stats_exception{"Unimplemented stat type"};
41-
}
42-
4336
snprintf(name_, sizeof(name_), "%s", name.c_str());
4437
}
4538

@@ -79,7 +72,7 @@ uint64_t& Stat::get_uint64() {
7972
void Statman::init(const uintptr_t start, const Size_type num_bytes)
8073
{
8174
if (num_bytes < 0)
82-
throw Stats_exception{"Creating Statman: A negative number of bytes has been given"};
75+
throw Stats_exception("Can't initialize statman with negative size");
8376

8477
const int N = num_bytes / sizeof(Stat);
8578
this->stats_ = reinterpret_cast<Stat*>(start);
@@ -103,7 +96,7 @@ Stat& Statman::create(const Stat::Stat_type type, const std::string& name) {
10396
volatile scoped_spinlock lock(this->stlock);
10497
#endif
10598
if (name.empty())
106-
throw Stats_exception{"Cannot create Stat with no name"};
99+
throw Stats_exception("Cannot create Stat with no name");
107100

108101
const int idx = bitmap.first_free();
109102
if (idx == -1 || idx >= capacity())

0 commit comments

Comments
 (0)