Changeset e1b6742 in mainline for uspace/app/tasks/tasks.c
- Timestamp:
- 2010-04-18T12:17:11Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e535eeb
- Parents:
- bbda5ab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tasks/tasks.c
rbbda5ab re1b6742 1 1 /* 2 2 * Copyright (c) 2010 Stanislav Kozina 3 * Copyright (c) 2010 Martin Decky 3 4 * All rights reserved. 4 5 * … … 43 44 #include <malloc.h> 44 45 #include <inttypes.h> 46 #include <bool.h> 45 47 #include <arg_parse.h> 46 48 #include "func.h" … … 53 55 #define PRINT_LOAD1(x) ((x) >> 11) 54 56 #define PRINT_LOAD2(x) (((x) & 0x7ff) / 2) 55 56 /** Thread states */57 //static const char *thread_states[] = {58 // "Invalid",59 // "Running",60 // "Sleeping",61 // "Ready",62 // "Entering",63 // "Exiting",64 // "Lingering"65 //};66 57 67 58 static void list_tasks(void) … … 90 81 91 82 printf("%8" PRIu64 "%8u %8" PRIu64"%c %12" 92 PRIu64 "%c %12" PRIu64"%c %s\n", ids[i], stats_task->threads,83 PRIu64 "%c %12" PRIu64 "%c %s\n", ids[i], stats_task->threads, 93 84 virtmem, vmsuffix, ucycles, usuffix, kcycles, ksuffix, 94 85 stats_task->name); … … 102 93 } 103 94 104 static void list_threads(task_id_t task_id) 105 { 106 /* TODO: 107 size_t thread_count = THREAD_COUNT; 108 thread_info_t *threads = malloc(thread_count * sizeof(thread_info_t)); 109 size_t result = get_task_threads(threads, sizeof(thread_info_t) * thread_count); 110 111 while (result > thread_count) { 112 thread_count *= 2; 113 threads = realloc(threads, thread_count * sizeof(thread_info_t)); 114 result = get_task_threads(threads, sizeof(thread_info_t) * thread_count); 115 } 116 117 if (result == 0) { 118 printf("No task with given pid!\n"); 119 exit(1); 120 } 121 122 size_t i; 95 static void list_threads(task_id_t task_id, bool all) 96 { 97 size_t count; 98 thread_id_t *ids = 99 (thread_id_t *) stats_get_threads(&count); 100 101 if (ids == NULL) { 102 fprintf(stderr, "%s: Unable to get threads\n", NAME); 103 return; 104 } 105 123 106 printf(" ID State CPU Prio [k]uCycles [k]kcycles Cycle fault\n"); 124 for (i = 0; i < result; ++i) { 125 if (threads[i].taskid != taskid) { 126 continue; 127 } 128 uint64_t ucycles, kcycles; 129 char usuffix, ksuffix; 130 order(threads[i].ucycles, &ucycles, &usuffix); 131 order(threads[i].kcycles, &kcycles, &ksuffix); 132 printf("%6llu %-8s %4u %6d %12llu%c %12llu%c\n", threads[i].tid, 133 thread_states[threads[i].state], threads[i].cpu, 134 threads[i].priority, ucycles, usuffix, 135 kcycles, ksuffix); 136 } 137 138 free(threads); */ 107 size_t i; 108 for (i = 0; i < count; i++) { 109 stats_thread_t *stats_thread = stats_get_thread(ids[i]); 110 if (stats_thread != NULL) { 111 if ((all) || (stats_thread->task_id == task_id)) { 112 uint64_t ucycles, kcycles; 113 char usuffix, ksuffix; 114 115 order(stats_thread->ucycles, &ucycles, &usuffix); 116 order(stats_thread->kcycles, &kcycles, &ksuffix); 117 118 if (stats_thread->on_cpu) { 119 printf("%8" PRIu64 " %-8s %4u %6d %12" 120 PRIu64"%c %12" PRIu64"%c\n", ids[i], 121 thread_get_state(stats_thread->state), 122 stats_thread->cpu, stats_thread->priority, 123 ucycles, usuffix, kcycles, ksuffix); 124 } else { 125 printf("%8" PRIu64 " %-8s ---- %6d %12" 126 PRIu64"%c %12" PRIu64"%c\n", ids[i], 127 thread_get_state(stats_thread->state), 128 stats_thread->priority, 129 ucycles, usuffix, kcycles, ksuffix); 130 } 131 } 132 133 free(stats_thread); 134 } else if (all) 135 printf("%8" PRIu64 "\n", ids[i]); 136 } 137 138 free(ids); 139 139 } 140 140 … … 190 190 { 191 191 printf( 192 "Usage: tasks [-t task_id] [- l] [-c]\n" \192 "Usage: tasks [-t task_id] [-a] [-l] [-c]\n" \ 193 193 "\n" \ 194 194 "Options:\n" \ … … 197 197 "\t\tList threads of the given task\n" \ 198 198 "\n" \ 199 "\t-a\n" \ 200 "\t--all\n" \ 201 "\t\tList all threads\n" \ 202 "\n" \ 199 203 "\t-l\n" \ 200 204 "\t--load\n" \ … … 217 221 bool toggle_tasks = true; 218 222 bool toggle_threads = false; 223 bool toggle_all = false; 219 224 bool toggle_load = false; 220 225 bool toggle_cpus = false; 221 226 222 task_id_t task_id ;227 task_id_t task_id = 0; 223 228 224 229 int i; … … 230 235 usage(); 231 236 return 0; 237 } 238 239 /* All threads */ 240 if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) { 241 toggle_tasks = false; 242 toggle_threads = true; 243 toggle_all = true; 244 continue; 232 245 } 233 246 … … 268 281 269 282 if (toggle_threads) 270 list_threads(task_id );283 list_threads(task_id, toggle_all); 271 284 272 285 if (toggle_load)
Note:
See TracChangeset
for help on using the changeset viewer.