--- libaitsched/example/test.c 2023/02/25 15:41:45 1.14.30.3 +++ libaitsched/example/test.c 2026/05/19 15:53:56 1.16 @@ -15,6 +15,7 @@ intptr_t Kill[1]; #ifdef AIO_SUPPORT struct iovec iv[3], wiv[3], riv[3]; #endif +volatile uint64_t total; void *event(sched_task_t *arg) { @@ -158,6 +159,27 @@ void *sigt(sched_task_t *arg) taskExit(arg, NULL); } +static void* +prof(void *task, void *stage) +{ + sched_task_t *t = task; + struct timespec ts; + static volatile uint64_t ns; + + clock_gettime(CLOCK_MONOTONIC, &ts); + if (!stage) + ns = (uint64_t) ts.tv_sec * 1000000000LL + ts.tv_nsec; + else { + ns = (uint64_t) ts.tv_sec * 1000000000LL + ts.tv_nsec - ns; + printf("Task ran for %lu ns: id=%p type=%d call=%p -> #%ld\n", ns, + TASK_ID(t), TASK_TYPE(t), TASK_FUNC(t), TASK_RET(t)); + + total += ns; + } + + return NULL; +} + int main(int argc, char **argv) { @@ -202,6 +224,9 @@ main(int argc, char **argv) return 1; } + if (argc > 1) + ROOT_PROFILING(root, prof); + if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) { printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); return 4; @@ -333,5 +358,8 @@ main(int argc, char **argv) close(fd); close(f); + + if (argc > 1) + printf("Total spend of time for all tasks = %lu\n", total); return 0; }