- 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
- Location:
- uspace
- Files:
-
- 3 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) -
uspace/lib/c/generic/stats.c
rbbda5ab re1b6742 43 43 #define SYSINFO_STATS_MAX_PATH 64 44 44 45 /** Thread states 46 * 47 */ 48 static const char *thread_states[] = { 49 "Invalid", 50 "Running", 51 "Sleeping", 52 "Ready", 53 "Entering", 54 "Exiting", 55 "Lingering" 56 }; 57 45 58 /** Get CPUs statistics 46 59 * … … 125 138 126 139 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 */ 151 thread_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 */ 172 stats_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; 127 184 } 128 185 … … 188 245 } 189 246 247 const 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 190 255 /** @} 191 256 */ -
uspace/lib/c/include/stats.h
rbbda5ab re1b6742 37 37 38 38 #include <task.h> 39 #include <thread.h> 40 #include <stdint.h> 41 #include <bool.h> 39 42 #include <kernel/sysinfo/abi.h> 40 43 41 44 extern stats_cpu_t *stats_get_cpus(size_t *); 42 45 extern stats_physmem_t *stats_get_physmem(void); 43 extern task_id_t *stats_get_tasks(size_t *);44 extern stats_task_t *stats_get_task(task_id_t);45 46 extern load_t *stats_get_load(size_t *); 46 47 extern sysarg_t stats_get_uptime(void); 47 48 49 extern task_id_t *stats_get_tasks(size_t *); 50 extern stats_task_t *stats_get_task(task_id_t); 51 52 extern thread_id_t *stats_get_threads(size_t *); 53 extern stats_thread_t *stats_get_thread(thread_id_t); 54 48 55 extern void stats_print_load_fragment(load_t, unsigned int); 56 extern const char *thread_get_state(state_t); 49 57 50 58 #endif
Note:
See TracChangeset
for help on using the changeset viewer.