Skip to content

Commit

Permalink
Updated Tests::Perf::Timestamps, added scripts/clear.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarneliuk committed Apr 30, 2024
1 parent e2532fb commit a40c575
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
25 changes: 13 additions & 12 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# See: https://clang.llvm.org/extra/clang-tidy/

Checks: '
clang-diagnostic-*,
clang-analyzer-*,
Expand All @@ -7,18 +9,17 @@ misc-*,
modernize-*,
performance-*,
portability-*,
-cppcoreguidelines-avoid-const-or-ref-data-members
-cppcoreguidelines-avoid-magic-numbers
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-cppcoreguidelines-pro-type-reinterpret-cast
-cppcoreguidelines-special-member-functions
-hicpp-braces-around-statements
-misc-const-correctness
-misc-include-cleaner
-misc-non-private-member-variables-in-classes
-modernize-use-trailing-return-type
-modernize-use-nodiscard
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-special-member-functions,
-hicpp-braces-around-statements,
-misc-const-correctness,
-misc-include-cleaner,
-misc-non-private-member-variables-in-classes,
-modernize-use-trailing-return-type,
-modernize-use-nodiscard,
'
WarningsAsErrors: '
clang-diagnostic-*,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![build](https://github.com/pkarneliuk/dlsm/actions/workflows/ci.yml/badge.svg)](https://github.com/pkarneliuk/dlsm/actions/workflows/ci.yml)
[![coverage](https://codecov.io/gh/pkarneliuk/dlsm/branch/master/graph/badge.svg)](https://codecov.io/gh/pkarneliuk/dlsm)

## Intruduction
## Introduction
This project contains scripts and snippets in C++.

## Features
Expand All @@ -30,3 +30,4 @@ This project contains scripts and snippets in C++.

## Links and References
- [Measuring Latency in Linux](http://btorpey.github.io/blog/2014/02/18/clock-sources-in-linux/)
- [Weak vs. Strong Memory Models](https://preshing.com/20120930/weak-vs-strong-memory-models/)
2 changes: 1 addition & 1 deletion include/impl/Signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace dlsm::Signal {

enum Type : int {
enum Type : std::int8_t {
NONE = 0,
BUS = SIGBUS,
INT = SIGINT,
Expand Down
6 changes: 6 additions & 0 deletions scripts/clear.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -el

Root=$(realpath $(dirname $(realpath $0))/..)

find $Root/build-fedora* -mindepth 1 ! -regex '^.*/.conan2\(/.*\)?' -delete
find $Root/build-ubuntu* -mindepth 1 ! -regex '^.*/.conan2\(/.*\)?' -delete
4 changes: 3 additions & 1 deletion src/Signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <cstring>
#include <format>
#include <system_error>
#include <type_traits>
#include <utility>

namespace dlsm::Signal {

std::string str(const Type signal) {
const auto description = ::sigdescr_np(signal);
// C++23 std::to_underlying()
if (description == nullptr) return "Unknown signal " + std::to_string(static_cast<int>(signal));
if (description == nullptr) return "Unknown signal " + std::to_string(std::underlying_type_t<Type>(signal));
return description;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ sudo perf stat -e L1-dcache-loads,L1-dcache-load-misses,mem_inst_retired.lock_lo
--benchmark_enable_random_interleaving=true \
--benchmark_counters_tabular=true \
--benchmark_display_aggregates_only=true

# Watch memory statistics(may affect performance measurements)
watch -n 0.2 "grep -E Mem\|Huge\|Swap\|Cache\|locked\|Shmem /proc/meminfo && free -hwv"
# Drop all caches
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
# Virtual Memory statistics measurements interval, default is 1 second
sudo sysctl vm.stat_interval=300
```

## [delays.py](delays.py)
Expand All @@ -39,6 +46,7 @@ numactl --hardware # Display NUMA nodes
sudo grubby --update-kernel=ALL --args="isolcpus=6-11" # Isolate CPU #6 - #11 from OS scheduling
sudo grubby --update-kernel=ALL --remove-args="isolcpus=6-11"
cat /proc/cmdline # Display kernel startup parameters
cat /sys/devices/system/cpu/isolated # display isolated cores
taskset -c 0,4,6-8 pid # Setting CPU affinity
```

Expand Down
17 changes: 10 additions & 7 deletions tests/perf/Timestamps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Tests::Perf {

template <dlsm::Clock::Concept Clock = dlsm::Clock::System, template <typename> typename Allocator = std::allocator>
template <dlsm::Clock::Concept Clock = dlsm::Clock::Steady, template <typename> typename Allocator = std::allocator>
struct Timestamps {
static constexpr std::chrono::nanoseconds Initial{0}, Max{100'000'000};
static constexpr std::chrono::nanoseconds delta(const std::chrono::nanoseconds& begin,
Expand All @@ -26,12 +26,13 @@ struct Timestamps {
Timestamps(std::size_t lists, std::size_t samples) : lists_{lists, List(samples, Initial)} {}
List& operator[](std::size_t i) { return lists_.at(i); }

Timestamps::List delays(const std::size_t master = 0) const {
Timestamps::List delays(double skipFirst = 0.0, const std::size_t master = 0) const {
if (lists_.size() <= 1) return {};

const auto subscribers = lists_.size() - 1; // - master
const auto parallel = lists_[0].size() > 100'000;
Timestamps::List deltas(subscribers * lists_[0].size(), Initial);
const auto skip = static_cast<std::size_t>(double(lists_[0].size()) * (skipFirst / 100.0));
Timestamps::List deltas(subscribers * (lists_[0].size() - skip), Initial);
auto dst = std::begin(deltas);

std::vector<std::future<void>> handles;
Expand All @@ -41,15 +42,15 @@ struct Timestamps {
for (std::size_t s = 0; s < lists_.size(); ++s) {
if (s == master) continue;
const auto& sub = lists_[s]; // end samples
auto i1 = std::cbegin(pub);
auto i1 = std::cbegin(pub) + static_cast<std::ptrdiff_t>(skip);
auto i2 = std::cend(pub);
auto i3 = std::cbegin(sub);
auto i3 = std::cbegin(sub) + static_cast<std::ptrdiff_t>(skip);
if (parallel) {
handles.emplace_back(std::async(std::launch::async, [=]() { std::transform(i1, i2, i3, dst, delta); }));
} else {
std::transform(i1, i2, i3, dst, delta);
}
dst += static_cast<long>(pub.size());
dst += i2 - i1;
}
handles.clear();
return deltas;
Expand All @@ -61,7 +62,9 @@ struct Timestamps {
};

// Calculate percentiles of delays for all samples
std::vector<Percentile> percentiles(const std::size_t master = 0) const { return percentiles(delays(master)); }
std::vector<Percentile> percentiles(double skipFirst = 0.0, std::size_t master = 0) const {
return percentiles(delays(skipFirst, master));
}

static std::vector<Percentile> percentiles(List deltas) {
if (deltas.empty()) return {};
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/TestSignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(Signal, Type) {

EXPECT_NO_THROW(dlsm::Signal::send(dlsm::Signal::NONE););

EXPECT_THAT([] { dlsm::Signal::send(static_cast<dlsm::Signal::Type>(-1)); },
EXPECT_THAT([] { dlsm::Signal::send(static_cast<dlsm::Signal::Type>(-1)); }, // NOLINT
ThrowsMessage<std::runtime_error>(StartsWith("Signal::send(-1) failed: Invalid argument")));
}

Expand Down

0 comments on commit a40c575

Please sign in to comment.