-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics for cpu and walltime profilers
- Loading branch information
Showing
18 changed files
with
331 additions
and
66 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/DiscardMetrics.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc. | ||
|
||
#pragma | ||
|
||
#include <list> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "MetricBase.h" | ||
|
||
enum class DiscardReason | ||
{ | ||
InSegvHandler = 0, | ||
InsideWrappedFunction, | ||
ExternalSignal, | ||
UnknownThread, | ||
WrongManagedThread, | ||
UnsufficientSpace, | ||
EmptyBacktrace, | ||
|
||
// This item must be the last one | ||
GuardItem | ||
}; | ||
|
||
// This pragma forces a compilation error if we forgot to add an enum item | ||
#if __clang__ | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic error "-Wswitch" | ||
#else | ||
#pragma warning(error : 4062) | ||
#endif | ||
static const char* to_string(DiscardReason type) | ||
{ | ||
switch (type) | ||
{ | ||
case DiscardReason::InSegvHandler: | ||
return "_in_sigsegv_handler"; | ||
case DiscardReason::InsideWrappedFunction: | ||
return "_inside_wrapped_function"; | ||
case DiscardReason::ExternalSignal: | ||
return "_external_signal"; | ||
case DiscardReason::UnknownThread: | ||
return "_unknown_thread"; | ||
case DiscardReason::WrongManagedThread: | ||
return "_wrong_managed_thread"; | ||
case DiscardReason::UnsufficientSpace: | ||
return "_unsufficient_space"; | ||
case DiscardReason::EmptyBacktrace: | ||
return "_empty_backtrace"; | ||
case DiscardReason::GuardItem: | ||
// pass through | ||
break; | ||
} | ||
return "unknown_discard_type"; | ||
} | ||
#if __clang__ | ||
#pragma clang diagnostic pop | ||
#else | ||
#pragma warning(default : 4062) | ||
#endif | ||
|
||
class DiscardMetrics : public MetricBase | ||
{ | ||
private: | ||
static constexpr std::size_t array_size = static_cast<std::size_t>(DiscardReason::GuardItem); | ||
|
||
public: | ||
DiscardMetrics(std::string name) : | ||
MetricBase(std::move(name)), _metrics{0} | ||
{ | ||
} | ||
|
||
template <DiscardReason TType> | ||
void Incr() | ||
{ | ||
static_assert(TType != DiscardReason::GuardItem, "You must not use DiscardReason::GuardItem"); | ||
constexpr auto offset = static_cast<int>(TType); | ||
static_assert(offset <= array_size, ""); | ||
_metrics[offset]++; | ||
} | ||
|
||
std::list<MetricBase::Metric> GetMetrics() override | ||
{ | ||
std::list<MetricBase::Metric> result; | ||
for (std::size_t idx = 0; idx < _metrics.size(); idx++) | ||
{ | ||
auto& metric = _metrics[idx]; | ||
result.emplace_back( | ||
std::make_pair(_name + to_string(static_cast<DiscardReason>(idx)), | ||
metric.exchange(0))); | ||
} | ||
return result; | ||
} | ||
|
||
private: | ||
std::array<std::atomic<std::uint64_t>, array_size> _metrics; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.