Skip to content

Commit cded5d9

Browse files
authored
Merge pull request #2015 from igchor/tracker_extend
[Common] Add total count and sum of latency measurements
2 parents 70e85f2 + ed26d04 commit cded5d9

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
lines changed

source/common/latency_tracker.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static constexpr double percentiles[numPercentiles] = {
4242
50.0, 90.0, 99.0, 99.9, 99.99, 99.999, 99.9999};
4343

4444
struct latencyValues {
45+
int64_t count;
4546
int64_t min;
4647
int64_t max;
4748
int64_t mean;
@@ -54,6 +55,7 @@ using histogram_ptr =
5455

5556
static inline latencyValues getValues(const struct hdr_histogram *histogram) {
5657
latencyValues values;
58+
values.count = histogram->total_count;
5759
values.max = hdr_max(histogram);
5860
values.min = hdr_min(histogram);
5961
values.mean = static_cast<int64_t>(hdr_mean(histogram));
@@ -92,21 +94,25 @@ class latency_printer {
9294

9395
for (auto &[name, histogram] : values) {
9496
auto value = getValues(histogram.get());
95-
logger.log(logger::Level::INFO,
96-
"{},{},{},{},{},{},{},{},{},{},{},{},ns", name,
97-
value.min, value.max, value.mean, value.stddev,
98-
value.percentileValues[0], value.percentileValues[1],
99-
value.percentileValues[2], value.percentileValues[3],
100-
value.percentileValues[4], value.percentileValues[5],
101-
value.percentileValues[6]);
97+
auto f = groupDigits<int64_t>;
98+
logger.log(
99+
logger::Level::INFO,
100+
"{},{},{},{},{},{},{},{},{},{},{},{},{},{},ns", name,
101+
f(value.mean), f(value.percentileValues[0]),
102+
f(value.percentileValues[1]), f(value.percentileValues[2]),
103+
f(value.percentileValues[3]), f(value.percentileValues[4]),
104+
f(value.percentileValues[5]), f(value.percentileValues[6]),
105+
f(value.count), f(value.count * value.mean), f(value.min),
106+
f(value.max), value.stddev);
102107
}
103108
}
104109

105110
private:
106111
inline void printHeader() {
107112
logger.log(logger::Level::INFO, "Latency histogram:");
108113
logger.log(logger::Level::INFO,
109-
"name,min,max,mean,stdev,p{},p{},p{},p{},p{},p{},p{},unit",
114+
"name,mean,p{},p{},p{},p{},p{},p{}"
115+
",p{},count,sum,min,max,stdev,unit",
110116
percentiles[0], percentiles[1], percentiles[2],
111117
percentiles[3], percentiles[4], percentiles[5],
112118
percentiles[6]);

source/common/ur_util.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,25 @@ template <typename T> class AtomicSingleton {
480480
}
481481
};
482482

483+
template <typename Numeric>
484+
static inline std::string groupDigits(Numeric numeric) {
485+
auto number = std::to_string(numeric);
486+
std::string sign = numeric >= 0 ? "" : "-";
487+
auto digits = number.substr(sign.size(), number.size() - sign.size());
488+
489+
std::string separated;
490+
491+
for (size_t i = 0; i < digits.size(); i++) {
492+
separated.push_back(digits[i]);
493+
494+
if (i != digits.size() - 1 && (digits.size() - i - 1) % 3 == 0) {
495+
separated.push_back('\'');
496+
}
497+
}
498+
499+
return sign + separated;
500+
}
501+
483502
template <typename T> Spinlock<Rc<T>> AtomicSingleton<T>::instance;
484503

485504
#endif /* UR_UTIL_H */

test/unit/utils/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ add_unit_test(params
1313

1414
add_unit_test(print
1515
print.cpp)
16+
17+
add_unit_test(helpers
18+
helpers.cpp)

test/unit/utils/helpers.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include <gmock/gmock.h>
7+
#include <gtest/gtest.h>
8+
9+
#include "ur_util.hpp"
10+
11+
TEST(groupDigits, Success) {
12+
EXPECT_EQ(groupDigits(-1), "-1");
13+
EXPECT_EQ(groupDigits(-12), "-12");
14+
EXPECT_EQ(groupDigits(-123), "-123");
15+
EXPECT_EQ(groupDigits(-1234), "-1'234");
16+
EXPECT_EQ(groupDigits(-12345), "-12'345");
17+
EXPECT_EQ(groupDigits(-123456), "-123'456");
18+
EXPECT_EQ(groupDigits(-1234567), "-1'234'567");
19+
EXPECT_EQ(groupDigits(-12345678), "-12'345'678");
20+
21+
EXPECT_EQ(groupDigits(0), "0");
22+
EXPECT_EQ(groupDigits(1), "1");
23+
EXPECT_EQ(groupDigits(12), "12");
24+
EXPECT_EQ(groupDigits(123), "123");
25+
EXPECT_EQ(groupDigits(1234), "1'234");
26+
EXPECT_EQ(groupDigits(12345), "12'345");
27+
EXPECT_EQ(groupDigits(123456), "123'456");
28+
EXPECT_EQ(groupDigits(1234567), "1'234'567");
29+
EXPECT_EQ(groupDigits(12345678), "12'345'678");
30+
}

0 commit comments

Comments
 (0)