Skip to content

Commit 60273a5

Browse files
committed
Add JIT memory counters
1 parent e10dbd0 commit 60273a5

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src/cgmemmgr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ uint8_t *RTDyldMemoryManagerJL::allocateCodeSection(uintptr_t Size,
866866
code_allocated = true;
867867
#endif
868868
total_allocated += Size;
869+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITSize, Size);
870+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITCodeSize, Size);
869871
if (exe_alloc)
870872
return (uint8_t*)exe_alloc->alloc(Size, Alignment);
871873
return SectionMemoryManager::allocateCodeSection(Size, Alignment, SectionID,
@@ -879,6 +881,8 @@ uint8_t *RTDyldMemoryManagerJL::allocateDataSection(uintptr_t Size,
879881
bool isReadOnly)
880882
{
881883
total_allocated += Size;
884+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITSize, Size);
885+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITDataSize, Size);
882886
if (!isReadOnly)
883887
return (uint8_t*)rw_alloc.alloc(Size, Alignment);
884888
if (ro_alloc)

src/jitlayers.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,27 @@ class JLMemoryUsagePlugin : public ObjectLinkingLayer::Plugin {
851851
jitlink::PassConfiguration &Config) override {
852852
Config.PostAllocationPasses.push_back([this](jitlink::LinkGraph &G) {
853853
size_t graph_size = 0;
854+
size_t code_size = 0;
855+
size_t data_size = 0;
854856
for (auto block : G.blocks()) {
855857
graph_size += block->getSize();
856858
}
859+
for (auto &section : G.sections()) {
860+
size_t secsize = 0;
861+
for (auto block : section.blocks()) {
862+
secsize += block->getSize();
863+
}
864+
if ((section.getMemProt() & orc::MemProt::Exec) == orc::MemProt::None) {
865+
data_size += secsize;
866+
} else {
867+
code_size += secsize;
868+
}
869+
graph_size += secsize;
870+
}
857871
this->total_size.fetch_add(graph_size, std::memory_order_relaxed);
872+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITSize, graph_size);
873+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITCodeSize, code_size);
874+
jl_timing_counter_inc(JL_TIMING_COUNTER_JITDataSize, data_size);
858875
return Error::success();
859876
});
860877
}

src/timing.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ void jl_init_timing(void)
108108
// We reference these by enum indexing and then asking for the name, since that allows the compiler
109109
// to catch name mismatches.
110110
TracyCPlotConfig(jl_timing_counters[JL_TIMING_COUNTER_HeapSize].tracy_counter.name, TracyPlotFormatMemory, /* rectilinear */ 0, /* fill */ 1, /* color */ 0);
111+
TracyCPlotConfig(jl_timing_counters[JL_TIMING_COUNTER_JITSize].tracy_counter.name, TracyPlotFormatMemory, /* rectilinear */ 0, /* fill */ 1, /* color */ 0);
112+
TracyCPlotConfig(jl_timing_counters[JL_TIMING_COUNTER_JITCodeSize].tracy_counter.name, TracyPlotFormatMemory, /* rectilinear */ 0, /* fill */ 1, /* color */ 0);
113+
TracyCPlotConfig(jl_timing_counters[JL_TIMING_COUNTER_JITDataSize].tracy_counter.name, TracyPlotFormatMemory, /* rectilinear */ 0, /* fill */ 1, /* color */ 0);
111114
#endif
112115
}
113116

src/timing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ void jl_timing_puts(jl_timing_block_t *cur_block, const char *str);
194194
#define JL_TIMING_COUNTERS \
195195
X(Invalidations) \
196196
X(HeapSize) \
197+
X(JITSize) \
198+
X(JITCodeSize) \
199+
X(JITDataSize) \
197200

198201

199202
enum jl_timing_owners {

0 commit comments

Comments
 (0)