source: mainline/uspace/app/top/ps.c@ dd6c71c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dd6c71c was dd6c71c, checked in by Stanislav Kozina <stanislav.kozina@…>, 16 years ago

top echoes counts of tasks

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2010 Stanislav Kozina
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup top
30 * @brief Task lister.
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <task.h>
39#include <thread.h>
40#include <stdlib.h>
41#include <malloc.h>
42#include <ps.h>
43#include "ps.h"
44
45#define TASK_COUNT 10
46#define THREAD_COUNT 50
47
48/** Thread states */
49const char *thread_states[] = {
50 "Invalid",
51 "Running",
52 "Sleeping",
53 "Ready",
54 "Entering",
55 "Exiting",
56 "Lingering"
57};
58
59unsigned int get_tasks(task_id_t **out_tasks)
60{
61 int task_count = TASK_COUNT;
62 task_id_t *tasks = malloc(task_count * sizeof(task_id_t));
63 int result = get_task_ids(tasks, sizeof(task_id_t) * task_count);
64
65 while (result > task_count) {
66 task_count *= 2;
67 tasks = realloc(tasks, task_count * sizeof(task_id_t));
68 result = get_task_ids(tasks, sizeof(task_id_t) * task_count);
69 }
70
71 int i;
72 for (i = 0; i < result; ++i) {
73 task_info_t taskinfo;
74 get_task_info(tasks[i], &taskinfo);
75 }
76
77 *out_tasks = tasks;
78 return result;
79}
80
81thread_info_t *get_threads(task_id_t taskid)
82{
83 int thread_count = THREAD_COUNT;
84 thread_info_t *threads = malloc(thread_count * sizeof(thread_info_t));
85 int result = get_task_threads(taskid, threads, sizeof(thread_info_t) * thread_count);
86
87 while (result > thread_count) {
88 thread_count *= 2;
89 threads = realloc(threads, thread_count * sizeof(thread_info_t));
90 result = get_task_threads(taskid, threads, sizeof(thread_info_t) * thread_count);
91 }
92
93 return threads;
94}
95
96/** @}
97 */
Note: See TracBrowser for help on using the repository browser.