Changeset e1b6742 in mainline for uspace/lib/c/generic/stats.c


Ignore:
Timestamp:
2010-04-18T12:17:11Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e535eeb
Parents:
bbda5ab
Message:

export threads to user space
the "tasks" command can now print all threads or threads belonging to a task

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/stats.c

    rbbda5ab re1b6742  
    4343#define SYSINFO_STATS_MAX_PATH  64
    4444
     45/** Thread states
     46 *
     47 */
     48static const char *thread_states[] = {
     49        "Invalid",
     50        "Running",
     51        "Sleeping",
     52        "Ready",
     53        "Entering",
     54        "Exiting",
     55        "Lingering"
     56};
     57
    4558/** Get CPUs statistics
    4659 *
     
    125138       
    126139        return stats_task;
     140}
     141
     142/** Get thread IDs
     143 *
     144 * @param count Number of IDs returned.
     145 *
     146 * @return Array of IDs (thread_id_t).
     147 *         If non-NULL then it should be eventually freed
     148 *         by free().
     149 *
     150 */
     151thread_id_t *stats_get_threads(size_t *count)
     152{
     153        size_t size = 0;
     154        thread_id_t *ids =
     155            (thread_id_t *) sysinfo_get_data("system.threads", &size);
     156       
     157        assert((size % sizeof(thread_id_t)) == 0);
     158       
     159        *count = size / sizeof(thread_id_t);
     160        return ids;
     161}
     162
     163/** Get single thread statistics
     164 *
     165 * @param thread_id Thread ID we are interested in.
     166 *
     167 * @return Pointer to the stats_thread_t structure.
     168 *         If non-NULL then it should be eventually freed
     169 *         by free().
     170 *
     171 */
     172stats_thread_t *stats_get_thread(thread_id_t thread_id)
     173{
     174        char name[SYSINFO_STATS_MAX_PATH];
     175        snprintf(name, SYSINFO_STATS_MAX_PATH, "system.threads.%" PRIu64, thread_id);
     176       
     177        size_t size = 0;
     178        stats_thread_t *stats_thread =
     179            (stats_thread_t *) sysinfo_get_data(name, &size);
     180       
     181        assert((size == sizeof(stats_thread_t)) || (size == 0));
     182       
     183        return stats_thread;
    127184}
    128185
     
    188245}
    189246
     247const char *thread_get_state(state_t state)
     248{
     249        if (state <= Lingering)
     250                return thread_states[state];
     251       
     252        return thread_states[Invalid];
     253}
     254
    190255/** @}
    191256 */
Note: See TracChangeset for help on using the changeset viewer.