Changeset be06914 in mainline for uspace/app/top/top.c


Ignore:
Timestamp:
2010-06-11T12:41:35Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b3b7e14
Parents:
48dcc69
Message:

nicer top printouts
fix typos (recieved → received)

File:
1 edited

Legend:

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

    r48dcc69 rbe06914  
    6767        target->tasks_perc = NULL;
    6868        target->threads = NULL;
     69        target->exceptions = NULL;
     70        target->exceptions_perc = NULL;
    6971        target->physmem = NULL;
    7072       
     
    115117                return "Cannot get threads";
    116118       
     119        /* Get Exceptions */
    117120        target->exceptions = stats_get_exceptions(&(target->exceptions_count));
    118121        if (target->exceptions == NULL)
    119122                return "Cannot get exceptions";
     123       
     124        target->exceptions_perc =
     125            (perc_exc_t *) calloc(target->exceptions_count, sizeof(perc_exc_t));
     126        if (target->exceptions_perc == NULL)
     127                return "Not enough memory for exception utilization";
    120128       
    121129        /* Get physical memory */
     
    137145        /* Allocate memory */
    138146       
    139         uint64_t *ucycles_diff = calloc(new_data->tasks_count, sizeof(uint64_t));
     147        uint64_t *ucycles_diff = calloc(new_data->tasks_count,
     148            sizeof(uint64_t));
    140149        if (ucycles_diff == NULL)
    141150                return "Not enough memory for user utilization";
    142151       
    143         uint64_t *kcycles_diff = calloc(new_data->tasks_count, sizeof(uint64_t));
     152        uint64_t *kcycles_diff = calloc(new_data->tasks_count,
     153            sizeof(uint64_t));
    144154        if (kcycles_diff == NULL) {
    145155                free(ucycles_diff);
    146156                return "Not enough memory for kernel utilization";
     157        }
     158       
     159        uint64_t *ecycles_diff = calloc(new_data->exceptions_count,
     160            sizeof(uint64_t));
     161        if (ecycles_diff == NULL) {
     162                free(ucycles_diff);
     163                free(kcycles_diff);
     164                return "Not enough memory for exception cycles utilization";
     165        }
     166       
     167        uint64_t *ecount_diff = calloc(new_data->exceptions_count,
     168            sizeof(uint64_t));
     169        if (ecount_diff == NULL) {
     170                free(ucycles_diff);
     171                free(kcycles_diff);
     172                free(ecycles_diff);
     173                return "Not enough memory for exception count utilization";
    147174        }
    148175       
     
    164191        /* For all tasks compute sum and differencies of all cycles */
    165192       
    166         uint64_t virtmem_total = 1;  /* Must NOT be zero */
    167         uint64_t ucycles_total = 1;  /* Must NOT be zero */
    168         uint64_t kcycles_total = 1;  /* Must NOT be zero */
     193        uint64_t virtmem_total = 0;
     194        uint64_t ucycles_total = 0;
     195        uint64_t kcycles_total = 0;
    169196       
    170197        for (i = 0; i < new_data->tasks_count; i++) {
     
    197224        }
    198225       
    199         /* For each task: Compute percential change */
     226        /* For each task compute percential change */
    200227       
    201228        for (i = 0; i < new_data->tasks_count; i++) {
     
    208235        }
    209236       
     237        /* For all exceptions compute sum and differencies of cycles */
     238       
     239        uint64_t ecycles_total = 0;
     240        uint64_t ecount_total = 0;
     241       
     242        for (i = 0; i < new_data->exceptions_count; i++) {
     243                /*
     244                 * March exception with the previous instance.
     245                 * This is quite paranoid since exceptions do not
     246                 * usually disappear, but it does not hurt.
     247                 */
     248               
     249                bool found = false;
     250                size_t j;
     251                for (j = 0; j < old_data->exceptions_count; j++) {
     252                        if (new_data->exceptions[i].id == old_data->exceptions[j].id) {
     253                                found = true;
     254                                break;
     255                        }
     256                }
     257               
     258                if (!found) {
     259                        /* This is a new exception, ignore it */
     260                        ecycles_diff[i] = 0;
     261                        ecount_diff[i] = 0;
     262                        continue;
     263                }
     264               
     265                ecycles_diff[i] =
     266                    new_data->exceptions[i].cycles - old_data->exceptions[j].cycles;
     267                ecount_diff[i] =
     268                    new_data->exceptions[i].count - old_data->exceptions[i].count;
     269               
     270                ecycles_total += ecycles_diff[i];
     271                ecount_total += ecount_diff[i];
     272        }
     273       
     274        /* For each exception compute percential change */
     275       
     276        for (i = 0; i < new_data->exceptions_count; i++) {
     277                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles,
     278                    ecycles_diff[i] * 100, ecycles_total);
     279                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].count,
     280                    ecount_diff[i] * 100, ecount_total);
     281        }
     282       
    210283        /* Cleanup */
    211284       
    212285        free(ucycles_diff);
    213286        free(kcycles_diff);
     287        free(ecycles_diff);
     288        free(ecount_diff);
    214289       
    215290        return NULL;
     
    238313        if (target->exceptions != NULL)
    239314                free(target->exceptions);
     315       
     316        if (target->exceptions_perc != NULL)
     317                free(target->exceptions_perc);
    240318       
    241319        if (target->physmem != NULL)
Note: See TracChangeset for help on using the changeset viewer.