Skip to content

Commit

Permalink
Added JITDUMP_USE_ARCH_TIMESTAMP support. (#111359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuinox authored Jan 17, 2025
1 parent 42fe08e commit a2ef22e
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/coreclr/pal/src/misc/perfjitdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include "../inc/llvm/ELF.h"

#if defined(HOST_AMD64)
#include <x86intrin.h>
#endif

SET_DEFAULT_DEBUG_CHANNEL(MISC);

namespace
Expand All @@ -37,6 +41,7 @@ namespace
{
JIT_DUMP_MAGIC = 0x4A695444,
JIT_DUMP_VERSION = 1,
JITDUMP_FLAGS_ARCH_TIMESTAMP = 1 << 0,

#if defined(HOST_X86)
ELF_MACHINE = EM_386,
Expand All @@ -61,13 +66,36 @@ namespace
JIT_CODE_LOAD = 0,
};

static bool UseArchTimeStamp()
{
static bool initialized = false;
static bool useArchTimestamp = false;

if (!initialized)
{
#if defined(HOST_AMD64)
const char* archTimestamp = getenv("JITDUMP_USE_ARCH_TIMESTAMP");
useArchTimestamp = (archTimestamp != nullptr && strcmp(archTimestamp, "1") == 0);
#endif
initialized = true;
}

return useArchTimestamp;
}

static uint64_t GetTimeStampNS()
{
#if defined(HOST_AMD64)
if (UseArchTimeStamp()) {
return static_cast<uint64_t>(__rdtsc());
}
#endif
LARGE_INTEGER result;
QueryPerformanceCounter(&result);
return result.QuadPart;
}


struct FileHeader
{
FileHeader() :
Expand All @@ -78,7 +106,7 @@ namespace
pad1(0),
pid(getpid()),
timestamp(GetTimeStampNS()),
flags(0)
flags(UseArchTimeStamp() ? JITDUMP_FLAGS_ARCH_TIMESTAMP : 0)
{}

uint32_t magic;
Expand Down

0 comments on commit a2ef22e

Please sign in to comment.