Changeset aec2ad4 in mainline for uspace/app
- Timestamp:
- 2011-02-04T11:48:33Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 103a3626
- Parents:
- ba5ab09 (diff), 3597dab (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 2 deleted
- 6 edited
-
stats/stats.c (modified) (3 diffs)
-
tasks/Makefile (deleted)
-
tasks/tasks.c (deleted)
-
top/screen.c (modified) (2 diffs)
-
usbinfo/dump.c (modified) (2 diffs)
-
usbinfo/info.c (modified) (7 diffs)
-
usbinfo/main.c (modified) (6 diffs)
-
usbinfo/usbinfo.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/stats/stats.c
rba5ab09 raec2ad4 1 1 /* 2 2 * Copyright (c) 2010 Stanislav Kozina 3 * Copyright (c) 2010 Martin Decky 3 4 * All rights reserved. 4 5 * … … 36 37 37 38 #include <stdio.h> 39 #include <task.h> 40 #include <thread.h> 38 41 #include <stats.h> 39 #include <sys/time.h> 42 #include <errno.h> 43 #include <stdlib.h> 44 #include <malloc.h> 40 45 #include <inttypes.h> 41 #include <malloc.h> 42 43 #define NAME "sysstat" 46 #include <bool.h> 47 #include <str.h> 48 #include <arg_parse.h> 49 50 #define NAME "stats" 44 51 45 52 #define DAY 86400 … … 47 54 #define MINUTE 60 48 55 49 int main(int argc, char *argv[]) 50 { 51 struct timeval time; 52 if (gettimeofday(&time, NULL) != 0) { 53 fprintf(stderr, "%s: Cannot get time of day\n", NAME); 54 return -1; 55 } 56 57 uint64_t sec = time.tv_sec; 58 printf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64, 59 (sec % DAY) / HOUR, (sec % HOUR) / MINUTE, sec % MINUTE); 60 56 static void list_tasks(void) 57 { 58 size_t count; 59 stats_task_t *stats_tasks = stats_get_tasks(&count); 60 61 if (stats_tasks == NULL) { 62 fprintf(stderr, "%s: Unable to get tasks\n", NAME); 63 return; 64 } 65 66 printf("[taskid] [thrds] [resident] [virtual] [ucycles]" 67 " [kcycles] [name\n"); 68 69 size_t i; 70 for (i = 0; i < count; i++) { 71 uint64_t resmem, virtmem, ucycles, kcycles; 72 char resmem_suffix, virtmem_suffix, usuffix, ksuffix; 73 74 order_suffix(stats_tasks[i].resmem, &resmem, &resmem_suffix); 75 order_suffix(stats_tasks[i].virtmem, &virtmem, &virtmem_suffix); 76 order_suffix(stats_tasks[i].ucycles, &ucycles, &usuffix); 77 order_suffix(stats_tasks[i].kcycles, &kcycles, &ksuffix); 78 79 printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c %8" PRIu64 "%c" 80 " %8" PRIu64 "%c %8" PRIu64 "%c %s\n", 81 stats_tasks[i].task_id, stats_tasks[i].threads, 82 resmem, resmem_suffix, virtmem, virtmem_suffix, 83 ucycles, usuffix, kcycles, ksuffix, stats_tasks[i].name); 84 } 85 86 free(stats_tasks); 87 } 88 89 static void list_threads(task_id_t task_id, bool all) 90 { 91 size_t count; 92 stats_thread_t *stats_threads = stats_get_threads(&count); 93 94 if (stats_threads == NULL) { 95 fprintf(stderr, "%s: Unable to get threads\n", NAME); 96 return; 97 } 98 99 printf("[taskid] [threadid] [state ] [prio] [cpu ] [ucycles] [kcycles]\n"); 100 101 size_t i; 102 for (i = 0; i < count; i++) { 103 if ((all) || (stats_threads[i].task_id == task_id)) { 104 uint64_t ucycles, kcycles; 105 char usuffix, ksuffix; 106 107 order_suffix(stats_threads[i].ucycles, &ucycles, &usuffix); 108 order_suffix(stats_threads[i].kcycles, &kcycles, &ksuffix); 109 110 printf("%-8" PRIu64 " %-10" PRIu64 " %-8s %6d ", 111 stats_threads[i].task_id, stats_threads[i].thread_id, 112 thread_get_state(stats_threads[i].state), 113 stats_threads[i].priority); 114 115 if (stats_threads[i].on_cpu) 116 printf("%6u ", stats_threads[i].cpu); 117 else 118 printf("(none) "); 119 120 printf("%8" PRIu64"%c %8" PRIu64"%c\n", 121 ucycles, usuffix, kcycles, ksuffix); 122 } 123 } 124 125 free(stats_threads); 126 } 127 128 static void list_cpus(void) 129 { 130 size_t count; 131 stats_cpu_t *cpus = stats_get_cpus(&count); 132 133 if (cpus == NULL) { 134 fprintf(stderr, "%s: Unable to get CPU statistics\n", NAME); 135 return; 136 } 137 138 printf("[id] [MHz ] [busy cycles] [idle cycles]\n"); 139 140 size_t i; 141 for (i = 0; i < count; i++) { 142 printf("%-4u ", cpus[i].id); 143 if (cpus[i].active) { 144 uint64_t bcycles, icycles; 145 char bsuffix, isuffix; 146 147 order_suffix(cpus[i].busy_cycles, &bcycles, &bsuffix); 148 order_suffix(cpus[i].idle_cycles, &icycles, &isuffix); 149 150 printf("%10" PRIu16 " %12" PRIu64 "%c %12" PRIu64 "%c\n", 151 cpus[i].frequency_mhz, bcycles, bsuffix, 152 icycles, isuffix); 153 } else 154 printf("inactive\n"); 155 } 156 157 free(cpus); 158 } 159 160 static void print_load(void) 161 { 162 size_t count; 163 load_t *load = stats_get_load(&count); 164 165 if (load == NULL) { 166 fprintf(stderr, "%s: Unable to get load\n", NAME); 167 return; 168 } 169 170 printf("%s: Load average: ", NAME); 171 172 size_t i; 173 for (i = 0; i < count; i++) { 174 if (i > 0) 175 printf(" "); 176 177 stats_print_load_fragment(load[i], 2); 178 } 179 180 printf("\n"); 181 182 free(load); 183 } 184 185 static void print_uptime(void) 186 { 61 187 sysarg_t uptime = stats_get_uptime(); 62 printf(" , up %" PRIun " days, %" PRIun " hours, "63 "%" PRIun " minutes, %" PRIun " seconds ",188 printf("%s: Up %" PRIun " days, %" PRIun " hours, " 189 "%" PRIun " minutes, %" PRIun " seconds\n", NAME, 64 190 uptime / DAY, (uptime % DAY) / HOUR, 65 191 (uptime % HOUR) / MINUTE, uptime % MINUTE); 66 67 size_t count; 68 load_t *load = stats_get_load(&count); 69 if (load != NULL) { 70 printf(", load average: "); 71 72 size_t i; 73 for (i = 0; i < count; i++) { 74 if (i > 0) 75 printf(" "); 76 77 stats_print_load_fragment(load[i], 2); 78 } 79 80 free(load); 81 } 82 83 printf("\n"); 192 } 193 194 static void usage(const char *name) 195 { 196 printf( 197 "Usage: %s [-t task_id] [-a] [-c] [-l] [-u]\n" \ 198 "\n" \ 199 "Options:\n" \ 200 "\t-t task_id\n" \ 201 "\t--task=task_id\n" \ 202 "\t\tList threads of the given task\n" \ 203 "\n" \ 204 "\t-a\n" \ 205 "\t--all\n" \ 206 "\t\tList all threads\n" \ 207 "\n" \ 208 "\t-c\n" \ 209 "\t--cpus\n" \ 210 "\t\tList CPUs\n" \ 211 "\n" \ 212 "\t-l\n" \ 213 "\t--load\n" \ 214 "\t\tPrint system load\n" \ 215 "\n" \ 216 "\t-u\n" \ 217 "\t--uptime\n" \ 218 "\t\tPrint system uptime\n" \ 219 "\n" \ 220 "\t-h\n" \ 221 "\t--help\n" \ 222 "\t\tPrint this usage information\n" 223 "\n" \ 224 "Without any options all tasks are listed\n", 225 name 226 ); 227 } 228 229 int main(int argc, char *argv[]) 230 { 231 bool toggle_tasks = true; 232 bool toggle_threads = false; 233 bool toggle_all = false; 234 bool toggle_cpus = false; 235 bool toggle_load = false; 236 bool toggle_uptime = false; 237 238 task_id_t task_id = 0; 239 240 int i; 241 for (i = 1; i < argc; i++) { 242 int off; 243 244 /* Usage */ 245 if ((off = arg_parse_short_long(argv[i], "-h", "--help")) != -1) { 246 usage(argv[0]); 247 return 0; 248 } 249 250 /* All threads */ 251 if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) { 252 toggle_tasks = false; 253 toggle_threads = true; 254 toggle_all = true; 255 continue; 256 } 257 258 /* CPUs */ 259 if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) { 260 toggle_tasks = false; 261 toggle_cpus = true; 262 continue; 263 } 264 265 /* Threads */ 266 if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) { 267 // TODO: Support for 64b range 268 int tmp; 269 int ret = arg_parse_int(argc, argv, &i, &tmp, off); 270 if (ret != EOK) { 271 printf("%s: Malformed task_id '%s'\n", NAME, argv[i]); 272 return -1; 273 } 274 275 task_id = tmp; 276 277 toggle_tasks = false; 278 toggle_threads = true; 279 continue; 280 } 281 282 /* Load */ 283 if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) { 284 toggle_tasks = false; 285 toggle_load = true; 286 continue; 287 } 288 289 /* Uptime */ 290 if ((off = arg_parse_short_long(argv[i], "-u", "--uptime")) != -1) { 291 toggle_tasks = false; 292 toggle_uptime = true; 293 continue; 294 } 295 } 296 297 if (toggle_tasks) 298 list_tasks(); 299 300 if (toggle_threads) 301 list_threads(task_id, toggle_all); 302 303 if (toggle_cpus) 304 list_cpus(); 305 306 if (toggle_load) 307 print_load(); 308 309 if (toggle_uptime) 310 print_uptime(); 311 84 312 return 0; 85 313 } -
uspace/app/top/screen.c
rba5ab09 raec2ad4 274 274 { 275 275 screen_style_inverted(); 276 printf("[taskid] [thr eads] [resident] [%%resi] [virtual] [%%virt]"276 printf("[taskid] [thrds] [resident] [%%resi] [virtual] [%%virt]" 277 277 " [%%user] [%%kern] [name"); 278 278 screen_newline(); … … 303 303 order_suffix(task->virtmem, &virtmem, &virtmem_suffix); 304 304 305 printf("%-8" PRIu64 " % 9zu %9" PRIu64 "%c ",305 printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c ", 306 306 task->task_id, task->threads, resmem, resmem_suffix); 307 307 print_percent(perc->resmem, 2); -
uspace/app/usbinfo/dump.c
rba5ab09 raec2ad4 27 27 */ 28 28 29 /** @addtogroup usb 29 /** @addtogroup usbinfo 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @briefUSB querying.34 * USB querying. 35 35 */ 36 36 … … 96 96 void dump_usb_descriptor(uint8_t *descriptor, size_t size) 97 97 { 98 printf("Device descriptor:\n"); 98 99 usb_dump_standard_descriptor(stdout, get_indent(0), "\n", 99 100 descriptor, size); -
uspace/app/usbinfo/info.c
rba5ab09 raec2ad4 27 27 */ 28 28 29 /** @addtogroup usb 29 /** @addtogroup usbinfo 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief34 * Dumping of generic device properties. 35 35 */ 36 36 #include <stdio.h> … … 38 38 #include <errno.h> 39 39 #include <usb/usbdrv.h> 40 #include <usb/pipes.h> 41 #include <usb/request.h> 40 42 #include "usbinfo.h" 41 43 42 int dump_device( int hc_phone, usb_address_t address)44 int dump_device(devman_handle_t hc_handle, usb_address_t address) 43 45 { 46 int rc; 47 usb_device_connection_t wire; 48 usb_endpoint_pipe_t ctrl_pipe; 49 ctrl_pipe.hc_phone = -1; 50 51 int hc_phone = devman_device_connect(hc_handle, 0); 52 if (hc_phone < 0) { 53 fprintf(stderr, 54 NAME ": failed to connect to host controller (%zu): %s.\n", 55 (size_t) hc_handle, str_error(hc_phone)); 56 return hc_phone; 57 } 58 44 59 /* 45 60 * Dump information about possible match ids. … … 47 62 match_id_list_t match_id_list; 48 63 init_match_ids(&match_id_list); 49 intrc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address);64 rc = usb_drv_create_device_match_ids(hc_phone, &match_id_list, address); 50 65 if (rc != EOK) { 51 66 fprintf(stderr, 52 67 NAME ": failed to fetch match ids of the device: %s.\n", 53 68 str_error(rc)); 54 return rc;69 goto leave; 55 70 } 56 71 dump_match_ids(&match_id_list); 72 73 /* 74 * Initialize pipes. 75 */ 76 rc = usb_device_connection_initialize(&wire, hc_handle, address); 77 if (rc != EOK) { 78 fprintf(stderr, 79 NAME ": failed to create connection to the device: %s.\n", 80 str_error(rc)); 81 goto leave; 82 } 83 rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe, &wire); 84 if (rc != EOK) { 85 fprintf(stderr, 86 NAME ": failed to create default control pipe: %s.\n", 87 str_error(rc)); 88 goto leave; 89 } 90 rc = usb_endpoint_pipe_start_session(&ctrl_pipe); 91 if (rc != EOK) { 92 fprintf(stderr, 93 NAME ": failed to start session on control pipe: %s.\n", 94 str_error(rc)); 95 goto leave; 96 } 57 97 58 98 /* … … 60 100 */ 61 101 usb_standard_device_descriptor_t device_descriptor; 62 usb_dprintf(NAME, 1, 63 "usb_drv_req_get_device_descriptor(%d, %d, %p)\n", 64 hc_phone, (int) address, &device_descriptor); 65 66 rc = usb_drv_req_get_device_descriptor(hc_phone, address, 67 &device_descriptor); 102 rc = usb_request_get_device_descriptor(&ctrl_pipe, &device_descriptor); 68 103 if (rc != EOK) { 69 104 fprintf(stderr, 70 105 NAME ": failed to fetch standard device descriptor: %s.\n", 71 106 str_error(rc)); 72 return rc;107 goto leave; 73 108 } 74 109 dump_usb_descriptor((uint8_t *)&device_descriptor, sizeof(device_descriptor)); … … 79 114 usb_standard_configuration_descriptor_t config_descriptor; 80 115 int config_index = 0; 81 usb_dprintf(NAME, 1, 82 "usb_drv_req_get_bare_configuration_descriptor(%d, %d, %d, %p)\n", 83 hc_phone, (int) address, config_index, &config_descriptor); 84 85 rc = usb_drv_req_get_bare_configuration_descriptor(hc_phone, address, 86 config_index, &config_descriptor ); 116 rc = usb_request_get_bare_configuration_descriptor(&ctrl_pipe, 117 config_index, &config_descriptor); 87 118 if (rc != EOK) { 88 119 fprintf(stderr, 89 120 NAME ": failed to fetch standard configuration descriptor: %s.\n", 90 121 str_error(rc)); 91 return rc;122 goto leave; 92 123 } 93 124 //dump_standard_configuration_descriptor(config_index, &config_descriptor); 94 125 95 126 void *full_config_descriptor = malloc(config_descriptor.total_length); 96 usb_dprintf(NAME, 1, 97 "usb_drv_req_get_full_configuration_descriptor(%d, %d, %d, %p, %zu)\n", 98 hc_phone, (int) address, config_index, 99 full_config_descriptor, config_descriptor.total_length); 100 101 rc = usb_drv_req_get_full_configuration_descriptor(hc_phone, address, 127 rc = usb_request_get_full_configuration_descriptor(&ctrl_pipe, 102 128 config_index, 103 129 full_config_descriptor, config_descriptor.total_length, NULL); … … 106 132 NAME ": failed to fetch full configuration descriptor: %s.\n", 107 133 str_error(rc)); 108 return rc;134 goto leave; 109 135 } 110 136 … … 112 138 config_descriptor.total_length); 113 139 114 return EOK; 140 rc = EOK; 141 leave: 142 /* Ignoring errors here. */ 143 ipc_hangup(hc_phone); 144 usb_endpoint_pipe_end_session(&ctrl_pipe); 145 146 return rc; 115 147 } 116 148 -
uspace/app/usbinfo/main.c
rba5ab09 raec2ad4 27 27 */ 28 28 29 /** @addtogroup usb 29 /** @addtogroup usbinfo 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @briefUSB querying.34 * USB querying. 35 35 */ 36 36 … … 77 77 } 78 78 79 static int set_new_host_controller(int *phone, const char *path) 79 static int get_host_controller_handle(const char *path, 80 devman_handle_t *hc_handle) 80 81 { 81 82 int rc; 82 int tmp_phone;83 83 84 if (path[0] != '/') { 85 int hc_class_index = (int) strtol(path, NULL, 10); 86 char *dev_path; 87 rc = asprintf(&dev_path, "class/usbhc\\%d", hc_class_index); 88 if (rc < 0) { 89 internal_error(rc); 90 return rc; 91 } 92 devmap_handle_t handle; 93 rc = devmap_device_get_handle(dev_path, &handle, 0); 94 if (rc < 0) { 95 fprintf(stderr, 96 NAME ": failed getting handle of `devman://%s'.\n", 97 dev_path); 98 free(dev_path); 99 return rc; 100 } 101 tmp_phone = devmap_device_connect(handle, 0); 102 if (tmp_phone < 0) { 103 fprintf(stderr, 104 NAME ": could not connect to `%s'.\n", 105 dev_path); 106 free(dev_path); 107 return tmp_phone; 108 } 109 free(dev_path); 110 } else { 111 devman_handle_t handle; 112 rc = devman_device_get_handle(path, &handle, 0); 113 if (rc != EOK) { 114 fprintf(stderr, 115 NAME ": failed getting handle of `devmap::/%s'.\n", 116 path); 117 return rc; 118 } 119 tmp_phone = devman_device_connect(handle, 0); 120 if (tmp_phone < 0) { 121 fprintf(stderr, 122 NAME ": could not connect to `%s'.\n", 123 path); 124 return tmp_phone; 125 } 84 devman_handle_t handle; 85 rc = devman_device_get_handle(path, &handle, 0); 86 if (rc != EOK) { 87 fprintf(stderr, 88 NAME ": failed getting handle of `devman::/%s'.\n", 89 path); 90 return rc; 126 91 } 127 128 *phone = tmp_phone; 92 *hc_handle = handle; 129 93 130 94 return EOK; 131 95 } 132 96 133 static int connect_with_address(int hc_phone, const char *str_address)97 static int get_device_address(const char *str_address, usb_address_t *address) 134 98 { 135 usb_address_t addr ess= (usb_address_t) strtol(str_address, NULL, 0);136 if ((addr ess < 0) || (address>= USB11_ADDRESS_MAX)) {99 usb_address_t addr = (usb_address_t) strtol(str_address, NULL, 0); 100 if ((addr < 0) || (addr >= USB11_ADDRESS_MAX)) { 137 101 fprintf(stderr, NAME ": USB address out of range.\n"); 138 102 return ERANGE; 139 103 } 140 104 141 if (hc_phone < 0) { 142 fprintf(stderr, NAME ": no active host controller.\n"); 143 return ENOENT; 144 } 145 146 return dump_device(hc_phone, address); 105 *address = addr; 106 return EOK; 147 107 } 148 108 … … 150 110 int main(int argc, char *argv[]) 151 111 { 152 int hc_phone = -1; 112 devman_handle_t hc_handle = (devman_handle_t) -1; 113 usb_address_t device_address = (usb_address_t) -1; 153 114 154 115 if (argc <= 1) { … … 175 136 case 'a': 176 137 case ACTION_DEVICE_ADDRESS: { 177 int rc = connect_with_address(hc_phone, optarg); 138 int rc = get_device_address(optarg, 139 &device_address); 178 140 if (rc != EOK) { 179 141 return rc; … … 184 146 case 't': 185 147 case ACTION_HOST_CONTROLLER: { 186 int rc = set_new_host_controller(&hc_phone,187 optarg);148 int rc = get_host_controller_handle(optarg, 149 &hc_handle); 188 150 if (rc != EOK) { 189 151 return rc; … … 202 164 } while (i != -1); 203 165 166 if ((hc_handle == (devman_handle_t) -1) 167 || (device_address == (usb_address_t) -1)) { 168 fprintf(stderr, NAME ": no target specified.\n"); 169 return EINVAL; 170 } 171 172 dump_device(hc_handle, device_address); 173 204 174 return 0; 205 175 } -
uspace/app/usbinfo/usbinfo.h
rba5ab09 raec2ad4 27 27 */ 28 28 29 /** @addtogroup usb 29 /** @addtogroup usbinfo 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @briefCommon header for usbinfo application.33 * Common header for usbinfo application. 34 34 */ 35 35 #ifndef USBINFO_USBINFO_H_ … … 47 47 void dump_match_ids(match_id_list_t *matches); 48 48 void dump_usb_descriptor(uint8_t *, size_t); 49 int dump_device( int, usb_address_t);49 int dump_device(devman_handle_t, usb_address_t); 50 50 void dump_descriptor_tree(uint8_t *, size_t); 51 51
Note:
See TracChangeset
for help on using the changeset viewer.
