Skip to content

Commit

Permalink
Continuous profiler (open-telemetry#3196)
Browse files Browse the repository at this point in the history

Co-authored-by: John Bley <jbley@splunk.com>
Co-authored-by: Paulo Janotti <pjanotti@splunk.com>
Co-authored-by: Robert Pająk <rpajak@splunk.com>
Co-authored-by: Mateusz Łach <mateusza@splunk.com>
Co-authored-by: Dawid Szmigielski <dszmigielski@splunk.com>
  • Loading branch information
6 people authored Jan 11, 2024
1 parent 9a96610 commit 349fbb1
Show file tree
Hide file tree
Showing 32 changed files with 2,815 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/OpenTelemetry.AutoInstrumentation.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ endif()
add_library("OpenTelemetry.AutoInstrumentation.Native.static" STATIC
class_factory.cpp
clr_helpers.cpp
continuous_profiler_clr_helpers.cpp
continuous_profiler.cpp
cor_profiler_base.cpp
cor_profiler.cpp
il_rewriter_wrapper.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ EXPORTS
IsProfilerAttached
AddInstrumentations
AddDerivedInstrumentations
ConfigureContinuousProfiler
ContinuousProfilerReadThreadSamples
ContinuousProfilerReadAllocationSamples
ContinuousProfilerSetNativeContext
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
<ClInclude Include="calltarget_tokens.h" />
<ClInclude Include="class_factory.h" />
<ClInclude Include="com_ptr.h" />
<ClInclude Include="continuous_profiler_clr_helpers.h" />
<ClInclude Include="continuous_profiler.h" />
<ClInclude Include="cor_profiler.h" />
<ClInclude Include="cor_profiler_base.h" />
<ClInclude Include="environment_variables.h" />
Expand Down Expand Up @@ -220,6 +222,8 @@
<ClCompile Include="calltarget_tokens.cpp" />
<ClCompile Include="class_factory.cpp" />
<ClCompile Include="clr_helpers.cpp" />
<ClCompile Include="continuous_profiler_clr_helpers.cpp" />
<ClCompile Include="continuous_profiler.cpp" />
<ClCompile Include="cor_profiler_base.cpp" />
<ClCompile Include="cor_profiler.cpp" />
<ClCompile Include="environment_variables_util.cpp" />
Expand Down
16 changes: 16 additions & 0 deletions src/OpenTelemetry.AutoInstrumentation.Native/clr_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ WSTRING GetSigTypeTokName(PCCOR_SIGNATURE& pbCur, const ComPtr<IMetaDataImport2>
ref_flag = true;
}

bool pointer_flag = false;
if (*pbCur == ELEMENT_TYPE_PTR)
{
pbCur++;
pointer_flag = true;
}

switch (*pbCur)
{
case ELEMENT_TYPE_BOOLEAN:
Expand Down Expand Up @@ -610,6 +617,12 @@ WSTRING GetSigTypeTokName(PCCOR_SIGNATURE& pbCur, const ComPtr<IMetaDataImport2>
{
tokenName += WStr("&");
}

if (pointer_flag)
{
tokenName += WStr("*");
}

return tokenName;
}

Expand Down Expand Up @@ -856,6 +869,9 @@ bool ParseParamOrLocal(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd)
if (*pbCur == ELEMENT_TYPE_BYREF)
pbCur++;

if (*pbCur == ELEMENT_TYPE_PTR)
pbCur++;

return ParseType(pbCur, pbEnd);
}

Expand Down
22 changes: 22 additions & 0 deletions src/OpenTelemetry.AutoInstrumentation.Native/clr_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,28 @@ HRESULT GetCorLibAssemblyRef(const ComPtr<IMetaDataAssemblyEmit>& assembly_emit,

bool FindTypeDefByName(const trace::WSTRING instrumentationTargetMethodTypeName, const trace::WSTRING assemblyName,
const ComPtr<IMetaDataImport2>& metadata_import, mdTypeDef& typeDef);

// FunctionMethodSignature
bool ParseByte(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd, unsigned char* pbOut);
bool ParseNumber(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd, unsigned* pOut);
bool ParseTypeDefOrRefEncoded(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd, unsigned char* pIndexTypeOut,
unsigned* pIndexOut);

/* we don't support
PTR CustomMod* VOID
PTR CustomMod* Type
FNPTR MethodDefSig
FNPTR MethodRefSig
ARRAY Type ArrayShape
SZARRAY CustomMod+ Type (but we do support SZARRAY Type)
*/
bool ParseType(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd);
// Param ::= CustomMod* ( TYPEDBYREF | [BYREF] Type )
// CustomMod* TYPEDBYREF we don't support
bool ParseParamOrLocal(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd);
// RetType ::= CustomMod* ( VOID | TYPEDBYREF | [BYREF] Type )
// CustomMod* TYPEDBYREF we don't support
bool ParseRetType(PCCOR_SIGNATURE& pbCur, PCCOR_SIGNATURE pbEnd);
} // namespace trace

#endif // OTEL_CLR_PROFILER_CLR_HELPERS_H_
Loading

0 comments on commit 349fbb1

Please sign in to comment.