Skip to content

Commit 4e65d6a

Browse files
art049claude
andcommitted
feat: replace callgraph dump with streaming CSV trace output
Replace callgrind's accumulated callgraph output with streaming CSV trace data emitted at function ENTER/EXIT boundaries. Each row contains delta counters since the last sample, enabling per-call cost attribution. Key changes: - dump.c: Replace callgraph output with CSV trace (trace_open/emit/close) - callstack.c: Hook push/pop_call_stack to emit ENTER/EXIT samples - threads.c: Add per-thread last_sample_cost for delta tracking - global.h: Add trace_output struct and per-thread sample state - main.c: Open trace at init, close at fini, update copyright Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6fd57d5 commit 4e65d6a

6 files changed

Lines changed: 294 additions & 1590 deletions

File tree

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
/autom4te.cache
1111
/bin
1212
/cachegrind.out.*
13+
/callgrind.out.*
14+
/tracegrind.out.*
1315
/compile
1416
/config.guess
1517
/config.h*
1618
/config.log
1719
/config.status
1820
/config.sub
1921
/configure
22+
/configure~
2023
/default.supp
2124
/depcomp
2225
/glibc-2.X.supp
@@ -161,6 +164,30 @@
161164
/callgrind/tests/inline-samefile
162165
/callgrind/tests/inline-crossfile
163166

167+
# /tracegrind/
168+
/tracegrind/*.so
169+
/tracegrind/.deps
170+
/tracegrind/tracegrind-*-darwin
171+
/tracegrind/tracegrind-*-linux
172+
/tracegrind/tracegrind-*-solaris
173+
/tracegrind/tracegrind-*-freebsd
174+
/tracegrind/Makefile
175+
/tracegrind/Makefile.in
176+
177+
# /tracegrind/tests/
178+
/tracegrind/tests/*.dSYM
179+
/tracegrind/tests/*.post.diff*
180+
/tracegrind/tests/*.post.out
181+
/tracegrind/tests/*.stderr.diff*
182+
/tracegrind/tests/*.stderr.out
183+
/tracegrind/tests/*.stdout.diff*
184+
/tracegrind/tests/*.stdout.out
185+
/tracegrind/tests/.deps
186+
/tracegrind/tests/Makefile
187+
/tracegrind/tests/Makefile.in
188+
/tracegrind/tests/tracegrind.out.*
189+
/tracegrind/tests/fibo
190+
164191
# /coregrind/
165192
/coregrind/*.a
166193
/coregrind/*.dSYM

tracegrind/callstack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ void TG_(push_call_stack)(BBCC* from, UInt jmp, BBCC* to, Addr sp, Bool skip)
250250

251251
TG_(current_call_stack).sp++;
252252

253+
/* Emit CSV trace sample on function entry */
254+
if (!skip && TG_(current_state).collect) {
255+
fn_node* to_fn = to->cxt->fn[0];
256+
TG_(trace_emit_sample)(TG_(current_tid), "ENTER", to_fn);
257+
}
258+
253259
/* To allow for above assertion we set context of next frame to 0 */
254260
TG_ASSERT(TG_(current_call_stack).sp < TG_(current_call_stack).size);
255261
current_entry++;
@@ -353,6 +359,11 @@ void TG_(pop_call_stack)(void)
353359
}
354360
TG_(stat).ret_counter++;
355361

362+
/* Emit CSV trace sample on function exit */
363+
if (TG_(current_state).collect) {
364+
TG_(trace_emit_sample)(TG_(current_tid), "EXIT", to_fn);
365+
}
366+
356367
/* restore context */
357368
TG_(current_state).cxt = lower_entry->cxt;
358369
TG_(current_fn_stack).top =

0 commit comments

Comments
 (0)