Wed, 06 Dec 2023 00:45:03 +0100
1 files changed,
30 insertions(+),
2 deletions(-)
jump to
M
shell/ticks.c
→
shell/ticks.c
@@ -2,8 +2,36 @@ #include "cedos.h"
#include "stdio.h" #include <stdint.h> +#include "stdlib.h" +#include "string.h" + +#include "cedos.h" void main(char *args) { - int ticks = sc_time_get_ticks(); - printf("%i\n", ticks); + if (strlen(args) == 0) { + int ticks = sc_time_get_ticks(); + printf("%i\n", ticks); + } else { + int interval = atoi(args); + + if (interval <= 0) { + printf("Invalid interval value.\n"); + return; + } + + int pid = get_pid(); + + int superticks = 0; + + while (1) { + int ticks = sc_time_get_ticks(); + + if (ticks / interval != superticks) { + printf("[%i] %i ticks\n", pid, ticks); + superticks = ticks / interval; + } + + yield(); + } + } }