Skip to content

Commit

Permalink
Merge pull request #2015 from igchor/tracker_extend
Browse files Browse the repository at this point in the history
[Common] Add total count and sum of latency measurements
  • Loading branch information
pbalcer committed Sep 6, 2024
2 parents 70e85f2 + ed26d04 commit cded5d9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
22 changes: 14 additions & 8 deletions source/common/latency_tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static constexpr double percentiles[numPercentiles] = {
50.0, 90.0, 99.0, 99.9, 99.99, 99.999, 99.9999};

struct latencyValues {
int64_t count;
int64_t min;
int64_t max;
int64_t mean;
Expand All @@ -54,6 +55,7 @@ using histogram_ptr =

static inline latencyValues getValues(const struct hdr_histogram *histogram) {
latencyValues values;
values.count = histogram->total_count;
values.max = hdr_max(histogram);
values.min = hdr_min(histogram);
values.mean = static_cast<int64_t>(hdr_mean(histogram));
Expand Down Expand Up @@ -92,21 +94,25 @@ class latency_printer {

for (auto &[name, histogram] : values) {
auto value = getValues(histogram.get());
logger.log(logger::Level::INFO,
"{},{},{},{},{},{},{},{},{},{},{},{},ns", name,
value.min, value.max, value.mean, value.stddev,
value.percentileValues[0], value.percentileValues[1],
value.percentileValues[2], value.percentileValues[3],
value.percentileValues[4], value.percentileValues[5],
value.percentileValues[6]);
auto f = groupDigits<int64_t>;
logger.log(
logger::Level::INFO,
"{},{},{},{},{},{},{},{},{},{},{},{},{},{},ns", name,
f(value.mean), f(value.percentileValues[0]),
f(value.percentileValues[1]), f(value.percentileValues[2]),
f(value.percentileValues[3]), f(value.percentileValues[4]),
f(value.percentileValues[5]), f(value.percentileValues[6]),
f(value.count), f(value.count * value.mean), f(value.min),
f(value.max), value.stddev);
}
}

private:
inline void printHeader() {
logger.log(logger::Level::INFO, "Latency histogram:");
logger.log(logger::Level::INFO,
"name,min,max,mean,stdev,p{},p{},p{},p{},p{},p{},p{},unit",
"name,mean,p{},p{},p{},p{},p{},p{}"
",p{},count,sum,min,max,stdev,unit",
percentiles[0], percentiles[1], percentiles[2],
percentiles[3], percentiles[4], percentiles[5],
percentiles[6]);
Expand Down
19 changes: 19 additions & 0 deletions source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,25 @@ template <typename T> class AtomicSingleton {
}
};

template <typename Numeric>
static inline std::string groupDigits(Numeric numeric) {
auto number = std::to_string(numeric);
std::string sign = numeric >= 0 ? "" : "-";
auto digits = number.substr(sign.size(), number.size() - sign.size());

std::string separated;

for (size_t i = 0; i < digits.size(); i++) {
separated.push_back(digits[i]);

if (i != digits.size() - 1 && (digits.size() - i - 1) % 3 == 0) {
separated.push_back('\'');
}
}

return sign + separated;
}

template <typename T> Spinlock<Rc<T>> AtomicSingleton<T>::instance;

#endif /* UR_UTIL_H */
3 changes: 3 additions & 0 deletions test/unit/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ add_unit_test(params

add_unit_test(print
print.cpp)

add_unit_test(helpers
helpers.cpp)
30 changes: 30 additions & 0 deletions test/unit/utils/helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2024 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "ur_util.hpp"

TEST(groupDigits, Success) {
EXPECT_EQ(groupDigits(-1), "-1");
EXPECT_EQ(groupDigits(-12), "-12");
EXPECT_EQ(groupDigits(-123), "-123");
EXPECT_EQ(groupDigits(-1234), "-1'234");
EXPECT_EQ(groupDigits(-12345), "-12'345");
EXPECT_EQ(groupDigits(-123456), "-123'456");
EXPECT_EQ(groupDigits(-1234567), "-1'234'567");
EXPECT_EQ(groupDigits(-12345678), "-12'345'678");

EXPECT_EQ(groupDigits(0), "0");
EXPECT_EQ(groupDigits(1), "1");
EXPECT_EQ(groupDigits(12), "12");
EXPECT_EQ(groupDigits(123), "123");
EXPECT_EQ(groupDigits(1234), "1'234");
EXPECT_EQ(groupDigits(12345), "12'345");
EXPECT_EQ(groupDigits(123456), "123'456");
EXPECT_EQ(groupDigits(1234567), "1'234'567");
EXPECT_EQ(groupDigits(12345678), "12'345'678");
}

0 comments on commit cded5d9

Please sign in to comment.