Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

std::vector<SampleValueType> AllocationsProvider::SampleTypeDefinitions(
{
{"alloc-samples", "count"},
{"alloc-size", "bytes"}
{"alloc-samples", "count", -1},
{"alloc-size", "bytes", -1}
}
);

std::vector<SampleValueType> AllocationsProvider::FrameworkSampleTypeDefinitions(
{
{"alloc-samples", "count"},
{"alloc-samples", "count", -1},
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ std::vector<uintptr_t> ContentionProvider::_emptyStack;

std::vector<SampleValueType> ContentionProvider::SampleTypeDefinitions(
{
{"lock-count", "count"},
{"lock-time", "nanoseconds"}
{"lock-count", "count", -1},
{"lock-time", "nanoseconds", -1}
});

ContentionProvider::ContentionProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

std::vector<SampleValueType> CpuTimeProvider::SampleTypeDefinitions(
{
{"cpu", "nanoseconds"},
{"cpu-samples", "count"}
}
{"cpu", "nanoseconds", -1},
{"cpu-samples", "count", -1}}
);

CpuTimeProvider::CpuTimeProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

std::vector<SampleValueType> ExceptionsProvider::SampleTypeDefinitions(
{
{"exception", "count"}
{"exception", "count", -1}
});

ExceptionsProvider::ExceptionsProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ GarbageCollectionProvider::GarbageCollectionProvider(
:
CollectorBase<RawGarbageCollectionSample>("GarbageCollectorProvider", valueTypeProvider.GetOrRegister(TimelineSampleType::Definitions), rawSampleTransformer, memoryResource)
{

_gen0CountMetric = metricsRegistry.GetOrRegister<CounterMetric>("dotnet_gc_gen0");
_gen1CountMetric = metricsRegistry.GetOrRegister<CounterMetric>("dotnet_gc_gen1");
_gen2CountMetric = metricsRegistry.GetOrRegister<CounterMetric>("dotnet_gc_gen2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

std::vector<SampleValueType> LiveObjectsProvider::SampleTypeDefinitions(
{
{"inuse-objects", "count"},
{"inuse-space", "bytes"}
{"inuse-objects", "count", -1},
{"inuse-space", "bytes", -1}
});

const uint32_t MAX_LIVE_OBJECTS = 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class LiveObjectsProvider : public ServiceBase,
bool StopImpl() override;

private:

// used to access the CLR to create weak handles
// and get object generation
ICorProfilerInfo13* _pCorProfilerInfo = nullptr;
RawSampleTransformer* _rawSampleTransformer = nullptr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class NativeThreadsCpuProviderBase : public ISamplesProvider
virtual std::vector<std::shared_ptr<IThreadInfo>> const& GetThreads() = 0;
virtual Labels GetLabels() = 0;

private:
RawSampleTransformer* _sampleTransformer;
std::chrono::milliseconds _previousTotalCpuTime;
std::vector<SampleValueTypeProvider::Offset> _valueOffsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

std::vector<SampleValueType> NetworkProvider::SampleTypeDefinitions(
{
{"request-time", "nanoseconds"}
{"request-time", "nanoseconds", -1}
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,13 @@ libdatadog::profile_unique_ptr CreateProfile(std::vector<SampleValueType> const&
std::vector<ddog_prof_ValueType> samplesTypes;
samplesTypes.reserve(valueTypes.size());

// TODO: create a vector<int32> containing the indexes of the valueTypes
std::vector<int32_t> indexes;

for (auto const& type : valueTypes)
{
samplesTypes.push_back(CreateValueType(type.Name, type.Unit));
indexes.push_back(type.Index);
}

struct ddog_prof_Slice_ValueType sample_types = {samplesTypes.data(), samplesTypes.size()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class RawCpuSample : public RawSample
{
public:
RawCpuSample() noexcept = default;
RawCpuSample() = default;

RawCpuSample(RawCpuSample&& other) noexcept
:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ struct SampleValueType
{
std::string Name;
std::string Unit;

// Samples belonging to the same provider will share the same index
// For libdatadog, it means that they will be stored in the same profile
// This value will be set when registering the SampleValueType with SampleValueTypeProvider
int32_t Index; // -1 means not set
};

typedef std::vector<int64_t> Values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ SampleValueTypeProvider::SampleValueTypeProvider()
_sampleTypeDefinitions.reserve(16);
}

std::vector<SampleValueTypeProvider::Offset> SampleValueTypeProvider::GetOrRegister(std::vector<SampleValueType> const& valueTypes)
std::vector<SampleValueTypeProvider::Offset> SampleValueTypeProvider::GetOrRegister(std::vector<SampleValueType>& valueTypes)
{
std::vector<Offset> offsets;
offsets.reserve(valueTypes.size());

for (auto const& valueType : valueTypes)
for (auto& valueType : valueTypes)
{
// set the same index for all
valueType.Index = _nextIndex;

size_t idx = GetOffset(valueType);
if (idx == -1)
{
Expand All @@ -27,6 +30,10 @@ std::vector<SampleValueTypeProvider::Offset> SampleValueTypeProvider::GetOrRegis
}
offsets.push_back(idx);
}

// the next set of SampleValueType will have a different index
_nextIndex++;

return offsets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ class SampleValueTypeProvider

SampleValueTypeProvider();

std::vector<Offset> GetOrRegister(std::vector<SampleValueType> const& valueType);
std::vector<Offset> GetOrRegister(std::vector<SampleValueType>& valueType);
std::vector<SampleValueType> const& GetValueTypes();

private:
std::int8_t GetOffset(SampleValueType const& valueType);

std::vector<SampleValueType> _sampleTypeDefinitions;

// Incremented each time a new vector of SampleValueType is registered via GetOrRegister
uint32_t _nextIndex = 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

#include "TimelineSampleType.h"

const std::vector<SampleValueType> TimelineSampleType::Definitions(
{{"timeline", "nanoseconds"}});
std::vector<SampleValueType> TimelineSampleType::Definitions(
{{"timeline", "nanoseconds", -1}});
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
class TimelineSampleType
{
public:
static const std::vector<SampleValueType> Definitions;
static std::vector<SampleValueType> Definitions;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SampleValueTypeProvider;

std::vector<SampleValueType> WallTimeProvider::SampleTypeDefinitions(
{
{"wall", "nanoseconds"}
{"wall", "nanoseconds", -1}
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"

static const SampleValueType CpuValueType = {"cpu", "nanoseconds"};
static const SampleValueType WallTimeValueType = {"walltime", "nanoseconds"};
static const SampleValueType ExceptionValueType = {"exception", "count"};
static SampleValueType CpuValueType = {"cpu", "nanoseconds", -1};
static SampleValueType WallTimeValueType = {"walltime", "nanoseconds", -1};
static SampleValueType ExceptionValueType = {"exception", "count", -1};

testing::AssertionResult AreSampleValueTypeEqual(SampleValueType const& v1, SampleValueType const& v2)
{
Expand All @@ -33,7 +33,7 @@ using ValueOffsets = std::vector<SampleValueTypeProvider::Offset>;
TEST(SampleValueTypeProvider, RegisterValueTypes)
{
SampleValueTypeProvider provider;
auto const valueTypes = std::vector<SampleValueType>{CpuValueType, WallTimeValueType};
auto valueTypes = std::vector<SampleValueType>{CpuValueType, WallTimeValueType};

auto offsets = provider.GetOrRegister(valueTypes);

Expand Down Expand Up @@ -94,4 +94,27 @@ TEST(SampleValueTypeProvider, EnsureThrowIfAddValueTypeSameNameButDifferentUnit)
auto anotherValuetype = std::vector<SampleValueType>{{"cpu", "non-sense-unit"}};

EXPECT_THROW(provider.GetOrRegister(anotherValuetype), std::runtime_error);
}

TEST(SampleValueTypeProvider, CheckSequentialIndex)
{
std::vector<SampleValueType> AllocationSampleTypeDefinitions(
{{"alloc-samples", "count", -1},
{"alloc-size", "bytes", -1}});
std::vector<SampleValueType> ExceptionSampleTypeDefinitions(
{{"exception", "count", -1}});
std::vector<SampleValueType> CpuSampleTypeDefinitions(
{{"cpu", "nanoseconds", -1},
{"cpu-samples", "count", -1}});

SampleValueTypeProvider provider;
auto allocationsOffsets = provider.GetOrRegister(AllocationSampleTypeDefinitions);
auto exceptionOffsets = provider.GetOrRegister(ExceptionSampleTypeDefinitions);
auto cpuOffsets = provider.GetOrRegister(CpuSampleTypeDefinitions);

ASSERT_EQ(AllocationSampleTypeDefinitions[0].Index, 0);
ASSERT_EQ(AllocationSampleTypeDefinitions[1].Index, 0);
ASSERT_EQ(ExceptionSampleTypeDefinitions[0].Index, 1);
ASSERT_EQ(CpuSampleTypeDefinitions[0].Index, 2);
ASSERT_EQ(CpuSampleTypeDefinitions[1].Index, 2);
}
Loading