Skip to content

Commit

Permalink
netd-init tweaks for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyuanliang committed May 20, 2024
1 parent cdfecbb commit 6156ec3
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 66 deletions.
2 changes: 1 addition & 1 deletion scripts/build-toybox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -exu
# we're using it for display only so we should be good.
# Toybox sh has more TODOs in multiple areas so don't use it.
# Command mkdir is used for tests only.
toys="base64 mkdir mktemp mv route sort timeout"
toys="base64 mkdir mktemp mv nice route sort timeout"

cd /toybox-*/

Expand Down
43 changes: 37 additions & 6 deletions scripts/inotify/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@ void run_callback_internal(char** callback) {
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));

struct timespec rt;
int ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("inotify: %s exited with status %d (exit: %d)\n",
printf("[%lld.%09ld] inotify: %s exited with status %d (exit: %d)\n",
(long long)rt.tv_sec, rt.tv_nsec, // NOLINT(runtime/int)
callback[0], status, WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("inotify: %s exited with status %d (signal: %d)\n",
printf("[%lld.%09ld] inotify: %s exited with status %d (signal: %d)\n",
(long long)rt.tv_sec, rt.tv_nsec, // NOLINT(runtime/int)
callback[0], status, WTERMSIG(status));
} else {
printf("inotify: %s exited with status %d\n", callback[0], status);
printf("[%lld.%09ld] inotify: %s exited with status %d\n",
(long long)rt.tv_sec, rt.tv_nsec, // NOLINT(runtime/int)
callback[0], status);
}

if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) {
Expand All @@ -80,7 +90,14 @@ void run_callback(char** callback, struct timespec *last, bool always) {
return;
}

printf("inotify: calling %s after %dms since the last run\n",
struct timespec rt;
ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("[%lld.%09ld] inotify: calling %s after %dms since the last run\n",
(long long)rt.tv_sec, rt.tv_nsec, // NOLINT(runtime/int)
callback[0], diff_milliseconds);
}

Expand Down Expand Up @@ -128,8 +145,16 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}

struct timespec rt;
int ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("[%lld.%09ld] inotify: calling %s as initial run\n",
(long long)rt.tv_sec, rt.tv_nsec, callback[0]); // NOLINT(runtime/int)

struct timespec tp;
printf("inotify: calling %s as initial run\n", callback[0]);
run_callback(callback, &tp, true);

for (;;) {
Expand Down Expand Up @@ -183,7 +208,13 @@ int main(int argc, char* argv[]) {
continue;
}

printf("inotify: calling %s for %d matching event(s)\n",
ret = clock_gettime(CLOCK_REALTIME, &rt);
if (ret != 0) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("[%lld.%09ld] inotify: calling %s for %d matching event(s)\n",
(long long)rt.tv_sec, rt.tv_nsec, // NOLINT(runtime/int)
callback[0], matches);
run_callback(callback, &tp, true);
}
Expand Down
Loading

0 comments on commit 6156ec3

Please sign in to comment.