Changeset a6302ae in mainline for uspace/app/stats/stats.c


Ignore:
Timestamp:
2019-12-11T10:49:48Z (4 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fe7bcf1
Parents:
ad211c8
Message:

add basic support for IPC statistics

Dumping of phone connections is supported right now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/stats/stats.c

    rad211c8 ra6302ae  
    5252#define MINUTE  60
    5353
     54typedef enum {
     55        LIST_TASKS,
     56        LIST_THREADS,
     57        LIST_IPCCS,
     58        LIST_CPUS,
     59        LIST_LOAD,
     60        LIST_UPTIME
     61} list_toggle_t;
     62
    5463static void list_tasks(void)
    5564{
     
    6574            " [kcycles] [name\n");
    6675
    67         size_t i;
    68         for (i = 0; i < count; i++) {
     76        for (size_t i = 0; i < count; i++) {
    6977                uint64_t resmem;
    7078                uint64_t virtmem;
     
    103111        printf("[taskid] [threadid] [state ] [prio] [cpu ] [ucycles] [kcycles]\n");
    104112
    105         size_t i;
    106         for (i = 0; i < count; i++) {
     113        for (size_t i = 0; i < count; i++) {
    107114                if ((all) || (stats_threads[i].task_id == task_id)) {
    108115                        uint64_t ucycles, kcycles;
     
    130137}
    131138
     139static 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
    132161static void list_cpus(void)
    133162{
     
    142171        printf("[id] [MHz     ] [busy cycles] [idle cycles]\n");
    143172
    144         size_t i;
    145         for (i = 0; i < count; i++) {
     173        for (size_t i = 0; i < count; i++) {
    146174                printf("%-4u ", cpus[i].id);
    147175                if (cpus[i].active) {
     
    174202        printf("%s: Load average: ", NAME);
    175203
    176         size_t i;
    177         for (i = 0; i < count; i++) {
     204        for (size_t i = 0; i < count; i++) {
    178205                if (i > 0)
    179206                        printf(" ");
     
    200227{
    201228        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"
    203230            "\n"
    204231            "Options:\n"
     
    207234            "\t\tList threads of the given task\n"
    208235            "\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"
    211242            "\t\tList all threads\n"
     243            "\n"
     244            "\t-ai\n"
     245            "\t--all-ipccs\n"
     246            "\t\tList all IPC connections\n"
    212247            "\n"
    213248            "\t-c\n"
     
    233268int main(int argc, char *argv[])
    234269{
    235         bool toggle_tasks = true;
    236         bool toggle_threads = false;
     270        list_toggle_t list_toggle = LIST_TASKS;
    237271        bool toggle_all = false;
    238         bool toggle_cpus = false;
    239         bool toggle_load = false;
    240         bool toggle_uptime = false;
    241 
    242272        task_id_t task_id = 0;
    243273
    244         int i;
    245         for (i = 1; i < argc; i++) {
     274        for (int i = 1; i < argc; i++) {
    246275                int off;
    247276
     
    252281                }
    253282
     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
    254290                /* 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;
    258293                        toggle_all = true;
    259294                        continue;
    260295                }
    261296
    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 */
    270314                if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) {
    271315                        // TODO: Support for 64b range
     
    273317                        errno_t ret = arg_parse_int(argc, argv, &i, &tmp, off);
    274318                        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]);
    276320                                return -1;
    277321                        }
     
    279323                        task_id = tmp;
    280324
    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;
    283332                        continue;
    284333                }
     
    286335                /* Load */
    287336                if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) {
    288                         toggle_tasks = false;
    289                         toggle_load = true;
     337                        list_toggle = LIST_LOAD;
    290338                        continue;
    291339                }
     
    293341                /* Uptime */
    294342                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:
    302350                list_tasks();
    303 
    304         if (toggle_threads)
     351                break;
     352        case LIST_THREADS:
    305353                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:
    308359                list_cpus();
    309 
    310         if (toggle_load)
     360                break;
     361        case LIST_LOAD:
    311362                print_load();
    312 
    313         if (toggle_uptime)
     363                break;
     364        case LIST_UPTIME:
    314365                print_uptime();
     366                break;
     367        }
    315368
    316369        return 0;
Note: See TracChangeset for help on using the changeset viewer.