Skip to content

Commit 5684fa9

Browse files
art049claude
andcommitted
fix(callgrind/tests): use write() instead of vprintf to avoid stdio inlining
Replace vprintf-based my_printf with write()-based my_output to completely avoid any stdio-related inlining issues. This prevents vprintf from causing additional inline markers to appear in the callgrind output. Updated filter_inline to skip my_output function calls. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0e29fdf commit 5684fa9

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

callgrind/tests/filter_inline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ in_main {
3333
else if (/^cfn=0x/) {
3434
# Skip
3535
}
36-
# Skip my_printf wrapper function calls
37-
else if (/^cfn=my_printf/) {
36+
# Skip my_output wrapper function calls
37+
else if (/^cfn=my_output/) {
3838
# Skip
3939
}
4040
else {

callgrind/tests/inline-crossfile.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include <stdio.h>
2-
#include <stdarg.h>
2+
#include <string.h>
3+
#include <unistd.h>
34
#include "inline-crossfile-helper1.h"
45
#include "inline-crossfile-helper2.h"
56

6-
// Non-inlinable printf wrapper to prevent glibc from inlining printf
7+
// Non-inlinable output function to prevent any stdio inlining issues
78
__attribute__((noinline))
8-
static void my_printf(const char *fmt, ...) {
9-
va_list args;
10-
va_start(args, fmt);
11-
vprintf(fmt, args);
12-
va_end(args);
9+
static void my_output(int sum, int prod) {
10+
char buf[100];
11+
int len = snprintf(buf, sizeof(buf), "sum=%d, product=%d\n", sum, prod);
12+
write(STDOUT_FILENO, buf, len);
1313
}
1414

1515
int main(int argc, char **argv) {
@@ -21,7 +21,7 @@ int main(int argc, char **argv) {
2121
// Call second inline function from helper2.h
2222
int prod = compute_product(n);
2323

24-
my_printf("sum=%d, product=%d\n", sum, prod);
24+
my_output(sum, prod);
2525

2626
return 0;
2727
}

callgrind/tests/inline-samefile.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <stdio.h>
2-
#include <stdarg.h>
2+
#include <string.h>
3+
#include <unistd.h>
34

4-
// Non-inlinable printf wrapper to prevent glibc from inlining printf
5+
// Non-inlinable output function to prevent any stdio inlining issues
56
__attribute__((noinline))
6-
static void my_printf(const char *fmt, ...) {
7-
va_list args;
8-
va_start(args, fmt);
9-
vprintf(fmt, args);
10-
va_end(args);
7+
static void my_output(int n, int fib_iter, int fib_rec) {
8+
char buf[100];
9+
int len = snprintf(buf, sizeof(buf), "Iterative fib(%d): %d, Recursive fib(10): %d\n", n, fib_iter, fib_rec);
10+
write(STDOUT_FILENO, buf, len);
1111
}
1212

1313
// Function 1: Iterative fibonacci - WILL be inlined
@@ -44,7 +44,7 @@ int main(int argc, char **argv) {
4444
// Call the recursive fibonacci (should NOT be inlined)
4545
int fib_rec = fibonacci_recursive(10);
4646

47-
my_printf("Iterative fib(%d): %d, Recursive fib(10): %d\n", n, fib_iter, fib_rec);
47+
my_output(n, fib_iter, fib_rec);
4848

4949
return 0;
5050
}

0 commit comments

Comments
 (0)