1
0

proj: Add perf/

This commit is contained in:
2025-08-13 12:26:10 +02:00
parent b48c5b4921
commit 4c91cf7a6e
5 changed files with 73 additions and 1 deletions

View File

@@ -1240,7 +1240,7 @@ void sym(exit)(int status) {
char msg_buf[BUFFER_SIZE];
rcv(msg_buf, sizeof(msg_buf));
if_modify_int("exit", int, status)
else if_invalid(getopt)
else if_invalid(exit)
}
__real_exit(status);
}

16
proj/perf/Makefile Normal file
View File

@@ -0,0 +1,16 @@
CC=gcc
CFLAGS=-std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809L -g
.PHONY: all clean
all: default
default: main
main.o: main.c
$(CC) -c -o $@ $^ $(CFLAGS)
main: main.o
$(CC) -o $@ $^ $(CFLAGS) -lc
clean:
rm -rf main *.o

33
proj/perf/main.c Normal file
View File

@@ -0,0 +1,33 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
int main(const int argc, const char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: main <cycles>\n");
return 1;
}
const long cycles = strtol(argv[1], NULL, 10);
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
int pipes[2];
for (int i = 0; i < cycles; i++) {
if (pipe(pipes) != 0) {
fprintf(stderr, "unable to create pipes: %s\n", strerror(errno));
exit(1);
}
close(pipes[0]);
close(pipes[1]);
}
clock_gettime(CLOCK_MONOTONIC, &end);
const long duration = end.tv_sec * 1000000000 + end.tv_nsec - start.tv_sec * 1000000000 - start.tv_nsec;
printf("start: %li.%09li\nend: %li.%09li\nduration: %li,%03li,%03li ns\n", start.tv_sec, start.tv_nsec, end.tv_sec, end.tv_nsec, duration / 1000000, duration / 1000 % 1000, duration % 1000);
}

22
proj/perf/test.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
REPEAT=30
CYCLES=50
function test() {
echo $@
for c in $(seq 1 $CYCLES); do
for i in $(seq 1 $REPEAT); do
echo "cycles: $((c * 100)) ($i/$REPEAT)"
$@ $((c * 100))
sleep 1
done
done
}
test ./main
cd ../intercept
test ./intercept -o -i - -- ../perf/main
test ./intercept -o -i stderr -- ../perf/main
test ./intercept -o -i file:out.log -- ../perf/main
#test ./intercept -o -i unix:/ -- ../perf/main