Changeset a6302ae in mainline for uspace/app/stats/stats.c
- Timestamp:
- 2019-12-11T10:49:48Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fe7bcf1
- Parents:
- ad211c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/stats/stats.c
rad211c8 ra6302ae 52 52 #define MINUTE 60 53 53 54 typedef enum { 55 LIST_TASKS, 56 LIST_THREADS, 57 LIST_IPCCS, 58 LIST_CPUS, 59 LIST_LOAD, 60 LIST_UPTIME 61 } list_toggle_t; 62 54 63 static void list_tasks(void) 55 64 { … … 65 74 " [kcycles] [name\n"); 66 75 67 size_t i; 68 for (i = 0; i < count; i++) { 76 for (size_t i = 0; i < count; i++) { 69 77 uint64_t resmem; 70 78 uint64_t virtmem; … … 103 111 printf("[taskid] [threadid] [state ] [prio] [cpu ] [ucycles] [kcycles]\n"); 104 112 105 size_t i; 106 for (i = 0; i < count; i++) { 113 for (size_t i = 0; i < count; i++) { 107 114 if ((all) || (stats_threads[i].task_id == task_id)) { 108 115 uint64_t ucycles, kcycles; … … 130 137 } 131 138 139 static void list_ipccs(task_id_t task_id, bool all) 140 { 141 size_t count; 142 stats_ipcc_t *stats_ipccs = stats_get_ipccs(&count); 143 144 if (stats_ipccs == NULL) { 145 fprintf(stderr, "%s: Unable to get IPC connections\n", NAME); 146 return; 147 } 148 149 printf("[caller] [callee]\n"); 150 151 for (size_t i = 0; i < count; i++) { 152 if ((all) || (stats_ipccs[i].caller == task_id)) { 153 printf("%-8" PRIu64 " %-8" PRIu64 "\n", 154 stats_ipccs[i].caller, stats_ipccs[i].callee); 155 } 156 } 157 158 free(stats_ipccs); 159 } 160 132 161 static void list_cpus(void) 133 162 { … … 142 171 printf("[id] [MHz ] [busy cycles] [idle cycles]\n"); 143 172 144 size_t i; 145 for (i = 0; i < count; i++) { 173 for (size_t i = 0; i < count; i++) { 146 174 printf("%-4u ", cpus[i].id); 147 175 if (cpus[i].active) { … … 174 202 printf("%s: Load average: ", NAME); 175 203 176 size_t i; 177 for (i = 0; i < count; i++) { 204 for (size_t i = 0; i < count; i++) { 178 205 if (i > 0) 179 206 printf(" "); … … 200 227 { 201 228 printf( 202 "Usage: %s [-t task_id] [- a] [-c] [-l] [-u]\n"229 "Usage: %s [-t task_id] [-i task_id] [-at] [-ai] [-c] [-l] [-u]\n" 203 230 "\n" 204 231 "Options:\n" … … 207 234 "\t\tList threads of the given task\n" 208 235 "\n" 209 "\t-a\n" 210 "\t--all\n" 236 "\t-i task_id\n" 237 "\t--ipcc=task_id\n" 238 "\t\tList IPC connections of the given task\n" 239 "\n" 240 "\t-at\n" 241 "\t--all-threads\n" 211 242 "\t\tList all threads\n" 243 "\n" 244 "\t-ai\n" 245 "\t--all-ipccs\n" 246 "\t\tList all IPC connections\n" 212 247 "\n" 213 248 "\t-c\n" … … 233 268 int main(int argc, char *argv[]) 234 269 { 235 bool toggle_tasks = true; 236 bool toggle_threads = false; 270 list_toggle_t list_toggle = LIST_TASKS; 237 271 bool toggle_all = false; 238 bool toggle_cpus = false;239 bool toggle_load = false;240 bool toggle_uptime = false;241 242 272 task_id_t task_id = 0; 243 273 244 int i; 245 for (i = 1; i < argc; i++) { 274 for (int i = 1; i < argc; i++) { 246 275 int off; 247 276 … … 252 281 } 253 282 283 /* All IPC connections */ 284 if ((off = arg_parse_short_long(argv[i], "-ai", "--all-ipccs")) != -1) { 285 list_toggle = LIST_IPCCS; 286 toggle_all = true; 287 continue; 288 } 289 254 290 /* All threads */ 255 if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) { 256 toggle_tasks = false; 257 toggle_threads = true; 291 if ((off = arg_parse_short_long(argv[i], "-at", "--all-threads")) != -1) { 292 list_toggle = LIST_THREADS; 258 293 toggle_all = true; 259 294 continue; 260 295 } 261 296 262 /* CPUs */ 263 if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) { 264 toggle_tasks = false; 265 toggle_cpus = true; 266 continue; 267 } 268 269 /* Threads */ 297 /* IPC connections */ 298 if ((off = arg_parse_short_long(argv[i], "-i", "--ipcc=")) != -1) { 299 // TODO: Support for 64b range 300 int tmp; 301 errno_t ret = arg_parse_int(argc, argv, &i, &tmp, off); 302 if (ret != EOK) { 303 printf("%s: Malformed task id '%s'\n", NAME, argv[i]); 304 return -1; 305 } 306 307 task_id = tmp; 308 309 list_toggle = LIST_IPCCS; 310 continue; 311 } 312 313 /* Tasks */ 270 314 if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) { 271 315 // TODO: Support for 64b range … … 273 317 errno_t ret = arg_parse_int(argc, argv, &i, &tmp, off); 274 318 if (ret != EOK) { 275 printf("%s: Malformed task _id '%s'\n", NAME, argv[i]);319 printf("%s: Malformed task id '%s'\n", NAME, argv[i]); 276 320 return -1; 277 321 } … … 279 323 task_id = tmp; 280 324 281 toggle_tasks = false; 282 toggle_threads = true; 325 list_toggle = LIST_THREADS; 326 continue; 327 } 328 329 /* CPUs */ 330 if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) { 331 list_toggle = LIST_CPUS; 283 332 continue; 284 333 } … … 286 335 /* Load */ 287 336 if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) { 288 toggle_tasks = false; 289 toggle_load = true; 337 list_toggle = LIST_LOAD; 290 338 continue; 291 339 } … … 293 341 /* Uptime */ 294 342 if ((off = arg_parse_short_long(argv[i], "-u", "--uptime")) != -1) { 295 toggle_tasks = false;296 toggle_uptime = true;297 continue;298 299 } 300 301 if (toggle_tasks)343 list_toggle = LIST_UPTIME; 344 continue; 345 } 346 } 347 348 switch (list_toggle) { 349 case LIST_TASKS: 302 350 list_tasks(); 303 304 if (toggle_threads)351 break; 352 case LIST_THREADS: 305 353 list_threads(task_id, toggle_all); 306 307 if (toggle_cpus) 354 break; 355 case LIST_IPCCS: 356 list_ipccs(task_id, toggle_all); 357 break; 358 case LIST_CPUS: 308 359 list_cpus(); 309 310 if (toggle_load)360 break; 361 case LIST_LOAD: 311 362 print_load(); 312 313 if (toggle_uptime)363 break; 364 case LIST_UPTIME: 314 365 print_uptime(); 366 break; 367 } 315 368 316 369 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.