[riot-notifications] [RIOT-OS/RIOT] sys/ps: enable runtime_usec output for the ps command (#16470)

Francisco notifications at github.com
Fri May 28 13:38:56 CEST 2021


@fjmolinas approved this pull request.

I played a bit with making the overflow more explicit to the user but it increases code size quite a bit, I'm sure we can improve this by using `fmt` instead but maybe there is not use case is enough and the warning in `ps.c` is enough, but for future reference something like the following could be done:

```diff
diff --git a/sys/ps/ps.c b/sys/ps/ps.c
index 5fe1acf050..68d4826d31 100644
--- a/sys/ps/ps.c
+++ b/sys/ps/ps.c
@@ -52,7 +52,7 @@ void ps(void)
            "| stack  ( used) ( free) | base addr  | current     "
 #endif
 #ifdef MODULE_SCHEDSTATISTICS
-           "| runtime  | switches  | runtime_usec "
+           "| runtime  | switches  | runtime_us"
 #endif
            "\n",
 #ifdef CONFIG_THREAD_NAMES
@@ -104,7 +104,14 @@ void ps(void)
 #ifdef MODULE_SCHEDSTATISTICS
             /* multiply with 100 for percentage and to avoid floats/doubles */
             uint64_t runtime_ticks = sched_pidlist[i].runtime_ticks * 100;
-            xtimer_ticks32_t xtimer_ticks = {sched_pidlist[i].runtime_ticks};
+            xtimer_ticks64_t ticks = { sched_pidlist[i].runtime_ticks };
+            uint64_t runtime_us = xtimer_usec_from_ticks64(ticks);
+            char buf[10];
+            if (runtime_us <= UINT32_MAX) {
+                sprintf(buf, "%10"PRIu32"", (uint32_t) runtime_us);
+            } else {
+                sprintf(buf, "overflown");
+            }
             unsigned runtime_major = runtime_ticks / rt_sum;
             unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum;
             unsigned switches = sched_pidlist[i].schedules;
@@ -118,7 +125,7 @@ void ps(void)
                    " | %6i (%5i) (%5i) | %10p | %10p "
 #endif
 #ifdef MODULE_SCHEDSTATISTICS
-                   " | %2d.%03d%% |  %8u  | %10"PRIu32" "
+                   " | %2d.%03d%% |  %8u  | %s "
 #endif
                    "\n",
                    p->pid,
@@ -131,7 +138,7 @@ void ps(void)
                    (void *)p->stack_start, (void *)p->sp
 #endif
 #ifdef MODULE_SCHEDSTATISTICS
-                   , runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks)
+                   , runtime_major, runtime_minor, switches, buf
 #endif
                   );
         }
```



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16470#pullrequestreview-671209754
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210528/1acc220a/attachment-0001.htm>


More information about the notifications mailing list