From 576abdf377996e9dcd99c7f12d538d39d8779638 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Feb 2026 20:21:52 +0000 Subject: [PATCH 1/2] Initial plan From 08d0b01456f6468b2e9c224010e480588e9ca36f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Feb 2026 20:25:09 +0000 Subject: [PATCH 2/2] Add thread info API: dmosi_thread_state_t, dmosi_thread_info_t, dmosi_thread_get_info Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- include/dmosi.h | 39 +++++++++++++++++++++++++++++++++++++++ src/dmosi.c | 15 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/dmosi.h b/include/dmosi.h index 6f3fc91..a900f82 100644 --- a/include/dmosi.h +++ b/include/dmosi.h @@ -345,6 +345,33 @@ DMOD_BUILTIN_API( dmosi, 1.0, dmosi_process_t, _process_get_parent, (dmosi_proce */ typedef void (*dmosi_thread_entry_t)(void* arg); +/** + * @brief Thread state enumeration + */ +typedef enum { + DMOSI_THREAD_STATE_CREATED, /**< Thread created but not started */ + DMOSI_THREAD_STATE_READY, /**< Thread is ready to run */ + DMOSI_THREAD_STATE_RUNNING, /**< Thread is currently running */ + DMOSI_THREAD_STATE_BLOCKED, /**< Thread is blocked (waiting for resource) */ + DMOSI_THREAD_STATE_SUSPENDED, /**< Thread is suspended */ + DMOSI_THREAD_STATE_TERMINATED /**< Thread has terminated */ +} dmosi_thread_state_t; + +/** + * @brief Thread information structure + * + * This structure holds auxiliary information about a thread, including + * stack usage statistics, state, CPU usage, and runtime. + */ +typedef struct { + size_t stack_total; /**< Total stack size in bytes */ + size_t stack_current; /**< Current stack usage in bytes */ + size_t stack_peak; /**< Peak stack usage in bytes */ + dmosi_thread_state_t state; /**< Current thread state */ + float cpu_usage; /**< CPU usage as a percentage (0.0 - 100.0) */ + uint64_t runtime_ms; /**< Thread runtime in milliseconds */ +} dmosi_thread_info_t; + /** * @brief Create a thread * @@ -467,6 +494,18 @@ DMOD_BUILTIN_API( dmosi, 1.0, size_t, _thread_get_all, (dmosi_thread_t* threads, */ DMOD_BUILTIN_API( dmosi, 1.0, size_t, _thread_get_by_process, (dmosi_process_t process, dmosi_thread_t* threads, size_t max_count) ); +/** + * @brief Get information about a thread + * + * Fills the provided @p info structure with auxiliary information about + * @p thread, including stack usage statistics, state, CPU usage, and runtime. + * + * @param thread Thread handle (if NULL, returns info for the current thread) + * @param info Pointer to a dmosi_thread_info_t structure to fill + * @return int 0 on success, negative error code on failure + */ +DMOD_BUILTIN_API( dmosi, 1.0, int, _thread_get_info, (dmosi_thread_t thread, dmosi_thread_info_t* info) ); + /** @} */ // end of DMOSI_THREAD_API //============================================================================== diff --git a/src/dmosi.c b/src/dmosi.c index 4966ed7..7ac9b1c 100644 --- a/src/dmosi.c +++ b/src/dmosi.c @@ -149,6 +149,21 @@ DMOD_INPUT_WEAK_API_DECLARATION( dmosi, 1.0, size_t, _thread_get_by_process, (dm return 0; } +DMOD_INPUT_WEAK_API_DECLARATION( dmosi, 1.0, int, _thread_get_info, (dmosi_thread_t thread, dmosi_thread_info_t* info) ) +{ + (void)thread; + if (info == NULL) { + return -EINVAL; + } + info->stack_total = 0; + info->stack_current = 0; + info->stack_peak = 0; + info->state = DMOSI_THREAD_STATE_TERMINATED; + info->cpu_usage = 0.0f; + info->runtime_ms = 0; + return -ENOSYS; +} + //============================================================================== // Process API //==============================================================================