[dd6c71c] | 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>
|
---|
[8b2aba5] | 43 | #include <sysinfo.h>
|
---|
[dd6c71c] | 44 | #include "ps.h"
|
---|
| 45 |
|
---|
| 46 | #define TASK_COUNT 10
|
---|
| 47 | #define THREAD_COUNT 50
|
---|
| 48 |
|
---|
| 49 | /** Thread states */
|
---|
| 50 | const char *thread_states[] = {
|
---|
| 51 | "Invalid",
|
---|
| 52 | "Running",
|
---|
| 53 | "Sleeping",
|
---|
| 54 | "Ready",
|
---|
| 55 | "Entering",
|
---|
| 56 | "Exiting",
|
---|
| 57 | "Lingering"
|
---|
| 58 | };
|
---|
| 59 |
|
---|
[638927a] | 60 | size_t get_tasks(task_info_t **out_infos)
|
---|
[dd6c71c] | 61 | {
|
---|
[638927a] | 62 | size_t task_count = TASK_COUNT;
|
---|
[dd6c71c] | 63 | task_id_t *tasks = malloc(task_count * sizeof(task_id_t));
|
---|
[638927a] | 64 | size_t result = get_task_ids(tasks, sizeof(task_id_t) * task_count);
|
---|
[dd6c71c] | 65 |
|
---|
| 66 | while (result > task_count) {
|
---|
| 67 | task_count *= 2;
|
---|
| 68 | tasks = realloc(tasks, task_count * sizeof(task_id_t));
|
---|
| 69 | result = get_task_ids(tasks, sizeof(task_id_t) * task_count);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[638927a] | 72 | size_t i;
|
---|
[452268a1] | 73 | task_info_t *taskinfos = malloc(result * sizeof(task_info_t));
|
---|
[dd6c71c] | 74 | for (i = 0; i < result; ++i) {
|
---|
[452268a1] | 75 | get_task_info(tasks[i], &taskinfos[i]);
|
---|
[dd6c71c] | 76 | }
|
---|
| 77 |
|
---|
[f0dcdc5] | 78 | free(tasks);
|
---|
| 79 |
|
---|
[452268a1] | 80 | *out_infos = taskinfos;
|
---|
[dd6c71c] | 81 | return result;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[638927a] | 84 | size_t get_threads(thread_info_t **thread_infos)
|
---|
[dd6c71c] | 85 | {
|
---|
[638927a] | 86 | size_t thread_count = THREAD_COUNT;
|
---|
[dd6c71c] | 87 | thread_info_t *threads = malloc(thread_count * sizeof(thread_info_t));
|
---|
[638927a] | 88 | size_t result = get_task_threads(threads, sizeof(thread_info_t) * thread_count);
|
---|
[dd6c71c] | 89 |
|
---|
| 90 | while (result > thread_count) {
|
---|
| 91 | thread_count *= 2;
|
---|
| 92 | threads = realloc(threads, thread_count * sizeof(thread_info_t));
|
---|
[faf38b2] | 93 | result = get_task_threads(threads, sizeof(thread_info_t) * thread_count);
|
---|
[dd6c71c] | 94 | }
|
---|
| 95 |
|
---|
[638927a] | 96 | *thread_infos = threads;
|
---|
| 97 | return result;
|
---|
[dd6c71c] | 98 | }
|
---|
| 99 |
|
---|
[8b2aba5] | 100 | unsigned int get_cpu_infos(uspace_cpu_info_t **out_infos)
|
---|
| 101 | {
|
---|
| 102 | unsigned int cpu_count = sysinfo_value("cpu.count");
|
---|
| 103 | uspace_cpu_info_t *cpus = malloc(cpu_count * sizeof(uspace_cpu_info_t));
|
---|
| 104 | get_cpu_info(cpus);
|
---|
| 105 |
|
---|
| 106 | *out_infos = cpus;
|
---|
| 107 | return cpu_count;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[dd6c71c] | 110 | /** @}
|
---|
| 111 | */
|
---|