/************************************************************************** Delete UniChar structure. **************************************************************************/ static void del_chain(struct UniChar *pChain) { int i, len = 0; if (!pChain) { return; } len = chainlen(pChain); if (len > 1) { pChain = pChain->next; for (i = 0; i < len - 1; i++) { FREESURFACE(pChain->prev->pTsurf); FC_FREE(pChain->prev); pChain = pChain->next; } } FC_FREE(pChain); }
struct xxxid_stats *create_diff(struct xxxid_stats *cs, struct xxxid_stats *ps, int *len) { int diff_size = sizeof(struct xxxid_stats) * chainlen(cs); struct xxxid_stats *diff = malloc(diff_size); struct xxxid_stats *c; int n = 0; uint64_t xxx = ~0; memset(diff, 0, diff_size); for (c = cs; c; c = c->__next, n++) { struct xxxid_stats *p = findpid(ps, c->tid); if (!p) { // new process or task memcpy(&diff[n], c, sizeof(struct xxxid_stats)); diff[n].read_bytes \ = diff[n].write_bytes \ = diff[n].swapin_delay_total \ = diff[n].blkio_delay_total \ = 0; diff[n].__next = &diff[n + 1]; continue; } memcpy(&diff[n], c, sizeof(struct xxxid_stats)); // round robin value #define RRV(to, from) {\ to = (to < from)\ ? xxx - to + from\ : to - from;\ } RRV(diff[n].read_bytes, p->read_bytes); RRV(diff[n].write_bytes, p->write_bytes); RRV(diff[n].swapin_delay_total, p->swapin_delay_total); RRV(diff[n].blkio_delay_total, p->blkio_delay_total); static double pow_ten = 0; if (!pow_ten) pow_ten = pow(10, 9); #undef RRV diff[n].blkio_val = (double) diff[n].blkio_delay_total / pow_ten / params.delay * 100; diff[n].swapin_val = (double) diff[n].swapin_delay_total / pow_ten / params.delay * 100; diff[n].read_val = (double) diff[n].read_bytes / (config.f.accumulated ? 1 : params.delay); diff[n].write_val = (double) diff[n].write_bytes / (config.f.accumulated ? 1 : params.delay); diff[n].__next = &diff[n + 1]; } // No have previous data to calculate diff if (!n) { free(diff); return NULL; } diff[n - 1].__next = NULL; *len = n; return diff; }
void sort_diff(struct xxxid_stats *d) { int len = chainlen(d); int i; for (i = 0; i < len; i++) { int k; for (k = i; k < len; k++) { int found = 0; #define CMP_FIELDS(field_name) (d[k].field_name > d[i].field_name) switch (sort_by) { case SORT_BY_PRIO: found = d[k].io_prio > d[i].io_prio; break; case SORT_BY_COMMAND: found = (strcmp(d[k].cmdline, d[i].cmdline) > 0); break; case SORT_BY_PID: found = CMP_FIELDS(tid); break; case SORT_BY_USER: found = CMP_FIELDS(euid); break; case SORT_BY_READ: found = CMP_FIELDS(read_val); break; case SORT_BY_WRITE: found = CMP_FIELDS(write_val); break; case SORT_BY_SWAPIN: found = CMP_FIELDS(swapin_val); break; case SORT_BY_IO: found = CMP_FIELDS(blkio_val); break; } #undef CMP_FIELDS if (found) { static struct xxxid_stats tmp; memcpy(&tmp, &d[i], sizeof(struct xxxid_stats)); memcpy(&d[i], &d[k], sizeof(struct xxxid_stats)); memcpy(&d[k], &tmp, sizeof(struct xxxid_stats)); } } } if (sort_order == SORT_ASC) { struct xxxid_stats *rev = malloc(sizeof(struct xxxid_stats) * len); for (i = 0; i < len; i++) memcpy(&rev[i], &d[len - i - 1], sizeof(struct xxxid_stats)); memcpy(d, rev, sizeof(struct xxxid_stats) * len); free(rev); } for (i = 0; i < len; i++) d[i].__next = &d[i + 1]; d[len - 1].__next = NULL; }