Skip to content

Commit 88e9a84

Browse files
authored
[continuous-profiling] adjust for frameinfo value in DoStackSnapshot callbacks (#4635)
1 parent 1b97c72 commit 88e9a84

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/OpenTelemetry.AutoInstrumentation.Native/continuous_profiler.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,13 @@ trace::WSTRING* NamingHelper::Lookup(const FunctionIdentifier& function_identifi
767767

768768
FunctionIdentifier NamingHelper::Lookup(const FunctionID functionId, const COR_PRF_FRAME_INFO frameInfo)
769769
{
770-
const FunctionIdentifierResolveArgs cacheKey = {functionId, frameInfo};
770+
const FunctionIdentifierResolveArgs cacheKey = {functionId};
771771
const auto cachedIdentifier = function_identifier_cache_.Get(cacheKey);
772772
if (cachedIdentifier.is_valid)
773773
{
774774
return cachedIdentifier;
775775
}
776-
const auto resolvedIdentifier = this->GetFunctionIdentifier(cacheKey.function_id, cacheKey.frame_info);
776+
const auto resolvedIdentifier = this->GetFunctionIdentifier(cacheKey.function_id, frameInfo);
777777
function_identifier_cache_.Put(cacheKey, resolvedIdentifier);
778778
return resolvedIdentifier;
779779
}
@@ -799,7 +799,15 @@ static HRESULT __stdcall FrameCallback(_In_ FunctionID func_id,
799799
const auto params = static_cast<DoStackSnapshotParams*>(client_data);
800800
params->prof->stats_.total_frames++;
801801

802-
const auto identifier = params->prof->helper.Lookup(func_id, frame_info);
802+
// Use '0' as a frame_info value.
803+
// It is documented to be equivalent to using value provided in frame_info parameter.
804+
// See
805+
// https://github.com/dotnet/runtime/blob/988296b080776c885ee0725b481db4ae4d4360ed/src/coreclr/inc/corprof.idl#L3167-L3172
806+
// and
807+
// https://github.com/dotnet/runtime/blob/bda571bfc728369cc2bbd33f2c161ea73c762b8d/docs/design/coreclr/profiling/davbr-blog-archive/Generics%20and%20Your%20Profiler.md?plain=1#L82-L101
808+
// for details.
809+
810+
const auto identifier = params->prof->helper.Lookup(func_id, 0);
803811
params->buffer->push_back(identifier);
804812

805813
return S_OK;

src/OpenTelemetry.AutoInstrumentation.Native/continuous_profiler.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,19 @@ struct FunctionIdentifier
5454
struct FunctionIdentifierResolveArgs
5555
{
5656
FunctionID function_id;
57-
COR_PRF_FRAME_INFO frame_info;
5857

5958
FunctionIdentifierResolveArgs() = delete;
60-
FunctionIdentifierResolveArgs(const FunctionID func_id, const COR_PRF_FRAME_INFO frame_info)
59+
FunctionIdentifierResolveArgs(const FunctionID func_id)
6160
: function_id(func_id)
62-
, frame_info(frame_info)
6361
{
6462
}
6563
bool operator==(const FunctionIdentifierResolveArgs& p) const
6664
{
67-
return function_id == p.function_id && frame_info == p.frame_info;
65+
return function_id == p.function_id;
66+
}
67+
bool operator!=(const FunctionIdentifierResolveArgs& p) const
68+
{
69+
return !(*this == p);
6870
}
6971
};
7072

@@ -86,6 +88,10 @@ struct trace_context
8688
{
8789
return trace_id_low_ == p.trace_id_low_ && trace_id_high_ == p.trace_id_high_;
8890
}
91+
bool operator!=(const trace_context& p) const
92+
{
93+
return !(*this == p);
94+
}
8995
[[nodiscard]] bool IsDefault() const;
9096
};
9197

@@ -138,7 +144,7 @@ struct std::hash<continuous_profiler::FunctionIdentifierResolveArgs>
138144
{
139145
std::size_t operator()(const continuous_profiler::FunctionIdentifierResolveArgs& k) const noexcept
140146
{
141-
return hash_combine(k.function_id, k.frame_info);
147+
return hash_combine(k.function_id);
142148
}
143149
};
144150

0 commit comments

Comments
 (0)