Skip to content

Commit

Permalink
Add earlyoom.profile Makefile target, add progress output
Browse files Browse the repository at this point in the history
  • Loading branch information
rfjakob committed Apr 9, 2024
1 parent 75767b9 commit 83d8f9b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*~
/earlyoom
/earlyoom.profile

# generated from MANPAGE.md
/earlyoom.1
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ all: earlyoom earlyoom.1 earlyoom.service
earlyoom: $(wildcard *.c *.h) Makefile
$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $(wildcard *.c)

.PHONY: earlyoom.profile
earlyoom.profile:
$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -DPROFILE_FIND_LARGEST_PROCESS -o earlyoom.profile $(wildcard *.c)

earlyoom.1: MANPAGE.md
ifdef PANDOC
pandoc MANPAGE.md -s -t man > earlyoom.1
Expand All @@ -29,7 +33,7 @@ else
endif

clean:
rm -f earlyoom earlyoom.service earlyoom.initscript earlyoom.1 earlyoom.1.gz
rm -f earlyoom earlyoom.profile earlyoom.service earlyoom.initscript earlyoom.1 earlyoom.1.gz gmon.out*

install: earlyoom.service install-bin install-default install-man
install -d $(DESTDIR)$(SYSTEMDUNITDIR)
Expand Down
Binary file added gmon.out.109708
Binary file not shown.
18 changes: 16 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,23 @@ static void startup_selftests(poll_loop_args_t* args)
}

#ifdef PROFILE_FIND_LARGEST_PROCESS
warn("PROFILE_FIND_LARGEST_PROCESS: looping forever on find_largest_process()\n");
struct timespec t0 = { 0 }, t1 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &t0);

warn("PROFILE_FIND_LARGEST_PROCESS: looping forever on find_largest_process(). Use sysprof of perf to capture profile.\n");
long i = 0;
while (1) {
find_largest_process(args, m);
find_largest_process(args);
i++;

const int avg_n = 1000;
if(i%avg_n == 0) {
clock_gettime(CLOCK_MONOTONIC, &t1);
long delta_usecs = (t1.tv_sec - t0.tv_sec) * 1000000 + (t1.tv_nsec - t0.tv_nsec) / 1000;
double avg_wall_time_ms = (double)(delta_usecs / avg_n) / 1000.0;
info("average find_largest_process() wall time: %.3lf ms\n", avg_wall_time_ms);
clock_gettime(CLOCK_MONOTONIC, &t0);
}
};
#endif
}
Expand Down

0 comments on commit 83d8f9b

Please sign in to comment.