From 639dadd6974eaac38d258a1035b415f74e7e32d1 Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 15 Aug 2018 18:55:49 +0000 Subject: [PATCH] system_cmds-790.50.6.tar.gz --- fs_usage.tproj/fs_usage.c | 21 +- lskq.tproj/lskq.1 | 24 +- lskq.tproj/lskq.c | 10 +- zprint.tproj/zprint.c | 558 ++++++++++++++++++++------------------ 4 files changed, 332 insertions(+), 281 deletions(-) diff --git a/fs_usage.tproj/fs_usage.c b/fs_usage.tproj/fs_usage.c index f7f9bfc..7ef5728 100644 --- a/fs_usage.tproj/fs_usage.c +++ b/fs_usage.tproj/fs_usage.c @@ -795,16 +795,9 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (time_limit_ns > 0) { - if (RAW_flag) { - fprintf(stderr, "NOTE: time limit ignored when a raw file is specified\n"); - } else { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, time_limit_ns), - dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), - ^{ - ktrace_end(s, 0); - }); - } + if (time_limit_ns > 0 && RAW_flag) { + fprintf(stderr, "NOTE: time limit ignored when a raw file is specified\n"); + time_limit_ns = 0; } if (!RAW_flag) { @@ -938,6 +931,14 @@ main(int argc, char *argv[]) exit(1); } + if (time_limit_ns > 0) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, time_limit_ns), + dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), + ^{ + ktrace_end(s, 0); + }); + } + dispatch_main(); return 0; diff --git a/lskq.tproj/lskq.1 b/lskq.tproj/lskq.1 index 19ae9bc..13c9b7e 100644 --- a/lskq.tproj/lskq.1 +++ b/lskq.tproj/lskq.1 @@ -186,17 +186,31 @@ KN_DISABLED .It Sy s KN_STAYQUEUED (event is marked as always-enqueued on the active list) .Pp -.It Sy o +.It Sy d KN_DROPPING -.It Sy u +.It Sy w KN_USEWAIT .It Sy c KN_ATTACHING -.It Sy f -KN_DEFERDROP +.It Sy a +KN_ATTACHED +.Pp +.It Sy s +KN_DISPATCH +.It Sy u +KN_UDATA_SPECIFIC +.It Sy p +KN_SUPPRESSED .It Sy t -KN_TOUCH +KN_STOLENDROP +.Pp +.It Sy v +KN_REQVANISH +.It Sy n +KN_VANISHED .El +.It qos +The QoS requested for the knote. .It data Filter-specific data. .El diff --git a/lskq.tproj/lskq.c b/lskq.tproj/lskq.c index 3037fc5..5292093 100644 --- a/lskq.tproj/lskq.c +++ b/lskq.tproj/lskq.c @@ -776,17 +776,15 @@ cheatsheet(void) { fprintf(stderr, "\nFilter-independent flags:\n\n\ \033[1m\ -command pid kq kqst ident filter fdtype fflags flags evst\033[0m\n\ -\033[1m\ --------------------- ----- ------------------ ---- ------------------ --------- -------- ------- --------------- -----------------\033[0m\n\ +command pid kq kqst knid filter fdtype fflags flags evst qos\033[0m\n\033[1m\ +-------------------- ----- ------------------ ---- ------------------ --------- -------- ------- --------------- ----------------- ---\033[0m\n\ ┌ EV_UDATA_SPECIFIC\n\ EV_DISPATCH ┐ │┌ EV_FLAG0 (EV_POLL)\n\ EV_CLEAR ┐│ ││┌ EV_FLAG1 (EV_OOBAND)\n\ EV_ONESHOT ┐││ │││┌ EV_EOF\n\ EV_RECEIPT ┐│││ ││││┌ EV_ERROR\n\ - ││││ │││││\n\ -\033[1m\ -launchd 1 4 ks- netbiosd 250 PROC ------- andx r1cs upboe aqds dwca supt vn\033[0m \n\ + ││││ │││││\n\033[1m\ +launchd 1 4 ks- netbiosd 250 PROC ------- andx r1cs upboe aqds dwca supt vn IN\033[0m \n\ │ │││ ││││ ││││ ││││ ││││ ││\n\ kqueue file descriptor/dynamic ID ┘ │││ EV_ADD ┘│││ KN_ACTIVE ┘│││ ││││ ││││ ││\n\ KQ_SLEEP ┘││ EV_ENABLE ┘││ KN_QUEUED ┘││ ││││ ││││ ││\n\ diff --git a/zprint.tproj/zprint.c b/zprint.tproj/zprint.c index 34283f2..8d095d2 100644 --- a/zprint.tproj/zprint.c +++ b/zprint.tproj/zprint.c @@ -90,26 +90,22 @@ #define PRINTK(fmt, value) \ printf(fmt "K", (value) / 1024 ) /* ick */ -static void usage(void); -static void printzone(mach_zone_name_t *, task_zone_info_t *); -static void colprintzone(mach_zone_name_t *, task_zone_info_t *); -static int find_deltas(mach_zone_name_t *, task_zone_info_t *, task_zone_info_t *, char *, int, int); +static void usage(FILE *stream); +static void printzone(mach_zone_name_t *, mach_zone_info_t *); +static void colprintzone(mach_zone_name_t *, mach_zone_info_t *); +static int find_deltas(mach_zone_name_t *, mach_zone_info_t *, mach_zone_info_t *, char *, int, int); static void colprintzoneheader(void); static boolean_t substr(const char *a, size_t alen, const char *b, size_t blen); static int SortName(void * thunk, const void * left, const void * right); static int SortSize(void * thunk, const void * left, const void * right); static void PrintLarge(mach_memory_info_t *wiredInfo, unsigned int wiredInfoCnt, - task_zone_info_t *zoneInfo, mach_zone_name_t *zoneNames, + mach_zone_info_t *zoneInfo, mach_zone_name_t *zoneNames, unsigned int zoneCnt, uint64_t zoneElements, int (*func)(void *, const void *, const void *), boolean_t column); static char *program; -static pid_t pid = 0; -static task_t task = TASK_NULL; -static boolean_t ShowPid = FALSE; - static boolean_t ShowDeltas = FALSE; static boolean_t ShowWasted = FALSE; static boolean_t ShowTotal = FALSE; @@ -121,13 +117,63 @@ static boolean_t PrintHeader = TRUE; static unsigned long long totalsize = 0; static unsigned long long totalused = 0; static unsigned long long totalsum = 0; -static unsigned long long pidsum = 0; +static unsigned long long totalfragmented = 0; +static unsigned long long totalcollectable = 0; static int last_time = 0; static char *zname = NULL; static size_t znamelen = 0; +#define LEFTALIGN -1 +#define RIGHTALIGN 1 + +typedef struct { + char *line1; + char *line2; + int colwidth; + int alignment; + bool visible; +} column_format; + +enum { + COL_ZONE_NAME, + COL_ELEM_SIZE, + COL_CUR_SIZE, + COL_MAX_SIZE, + COL_CUR_ELTS, + COL_MAX_ELTS, + COL_CUR_INUSE, + COL_ALLOC_SIZE, + COL_ALLOC_COUNT, + COL_ZONE_FLAGS, + COL_FRAG_SIZE, + COL_FREE_SIZE, + COL_TOTAL_ALLOCS, + COL_MAX +}; + +/* + * The order in which the columns appear below should match + * the order in which the values are printed in colprintzone(). + */ +static column_format columns[] = { + [COL_ZONE_NAME] = { "", "zone name", 25, LEFTALIGN, true }, + [COL_ELEM_SIZE] = { "elem", "size", 6, RIGHTALIGN, true }, + [COL_CUR_SIZE] = { "cur", "size", 11, RIGHTALIGN, true }, + [COL_MAX_SIZE] = { "max", "size", 11, RIGHTALIGN, true }, + [COL_CUR_ELTS] = { "cur", "#elts", 10, RIGHTALIGN, true }, + [COL_MAX_ELTS] = { "max", "#elts", 11, RIGHTALIGN, true }, + [COL_CUR_INUSE] = { "cur", "inuse", 11, RIGHTALIGN, true }, + [COL_ALLOC_SIZE] = { "alloc", "size", 6, RIGHTALIGN, true }, + [COL_ALLOC_COUNT] = { "alloc", "count", 6, RIGHTALIGN, true }, + [COL_ZONE_FLAGS] = { "", "", 2, RIGHTALIGN, true }, + /* additional columns for special flags, not visible by default */ + [COL_FRAG_SIZE] = { "frag", "size", 9, RIGHTALIGN, false }, + [COL_FREE_SIZE] = { "free", "size", 9, RIGHTALIGN, false }, + [COL_TOTAL_ALLOCS] = { "total", "allocs", 17, RIGHTALIGN, false } +}; + static void sigintr(__unused int signum) { @@ -135,10 +181,20 @@ sigintr(__unused int signum) } static void -usage(void) +usage(FILE *stream) { - fprintf(stderr, "usage: %s [-w] [-s] [-c] [-h] [-t] [-d] [-l] [-L] [-p ] [name]\n", program); - exit(1); + fprintf(stream, "usage: %s [-w] [-s] [-c] [-h] [-H] [-t] [-d] [-l] [-L] [name]\n\n", program); + fprintf(stream, "\t-w\tshow wasted memory for each zone\n"); + fprintf(stream, "\t-s\tsort zones by wasted memory\n"); + fprintf(stream, "\t-c\t(default) display output formatted in columns\n"); + fprintf(stream, "\t-h\tdisplay this help message\n"); + fprintf(stream, "\t-H\thide column names\n"); + fprintf(stream, "\t-t\tdisplay the total size of allocations over the life of the zone\n"); + fprintf(stream, "\t-d\tdisplay deltas over time\n"); + fprintf(stream, "\t-l\t(default) display wired memory info after zone info\n"); + fprintf(stream, "\t-L\tdo not show wired memory info, only show zone info\n"); + fprintf(stream, "\nAny option (including default options) can be overridden by specifying the option in upper-case.\n\n"); + exit(stream != stdout); } int @@ -146,18 +202,18 @@ main(int argc, char **argv) { mach_zone_name_t *name = NULL; unsigned int nameCnt = 0; - task_zone_info_t *info = NULL; + mach_zone_info_t *info = NULL; unsigned int infoCnt = 0; mach_memory_info_t *wiredInfo = NULL; unsigned int wiredInfoCnt = 0; - task_zone_info_t *max_info = NULL; + mach_zone_info_t *max_info = NULL; char *deltas = NULL; uint64_t zoneElements; kern_return_t kr; int i, j; int first_time = 1; - int must_print = 1; + int must_print = 1; int interval = 1; signal(SIGINT, sigintr); @@ -191,20 +247,15 @@ main(int argc, char **argv) ColFormat = TRUE; else if (streql(argv[i], "-C")) ColFormat = FALSE; + else if (streql(argv[i], "-h")) + usage(stdout); else if (streql(argv[i], "-H")) PrintHeader = FALSE; - else if (streql(argv[i], "-p")) { - ShowPid = TRUE; - if (i < argc - 1) { - pid = atoi(argv[i+1]); - i++; - } else - usage(); - } else if (streql(argv[i], "--")) { + else if (streql(argv[i], "--")) { i++; break; } else if (argv[i][0] == '-') - usage(); + usage(stderr); else break; } @@ -221,7 +272,7 @@ main(int argc, char **argv) break; default: - usage(); + usage(stderr); } if (ShowDeltas) { @@ -230,166 +281,139 @@ main(int argc, char **argv) PrintHeader = TRUE; } - if (ShowPid) { - kr = task_for_pid(mach_task_self(), pid, &task); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: task_for_pid(%d) failed: %s (try running as root)\n", - program, pid, mach_error_string(kr)); - exit(1); - } + if (ShowWasted) { + columns[COL_FRAG_SIZE].visible = true; + columns[COL_FREE_SIZE].visible = true; + } + if (ShowTotal) { + columns[COL_TOTAL_ALLOCS].visible = true; } - for (;;) { - if (ShowPid) { - kr = task_zone_info(task, &name, &nameCnt, &info, &infoCnt); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: task_zone_info: %s\n", - program, mach_error_string(kr)); - exit(1); - } - } else { - mach_zone_info_t *zinfo = NULL; - - kr = mach_memory_info(mach_host_self(), - &name, &nameCnt, &zinfo, &infoCnt, + for (;;) { + kr = mach_memory_info(mach_host_self(), + &name, &nameCnt, &info, &infoCnt, &wiredInfo, &wiredInfoCnt); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: mach_zone_info: %s\n", - program, mach_error_string(kr)); - exit(1); - } - - kr = vm_allocate(mach_task_self(), (vm_address_t *)&info, - infoCnt * sizeof *info, VM_FLAGS_ANYWHERE); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s vm_allocate: %s\n", - program, mach_error_string(kr)); - exit(1); - } - for (i = 0; i < infoCnt; i++) { - *(mach_zone_info_t *)(info + i) = zinfo[i]; - info[i].tzi_caller_acct = 0; - info[i].tzi_task_alloc = 0; - info[i].tzi_task_free = 0; - } - kr = vm_deallocate(mach_task_self(), (vm_address_t) zinfo, - (vm_size_t) (infoCnt * sizeof *zinfo)); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: vm_deallocate: %s\n", - program, mach_error_string(kr)); - exit(1); - } - } + if (kr != KERN_SUCCESS) { + fprintf(stderr, "%s: mach_zone_info: %s\n", + program, mach_error_string(kr)); + exit(1); + } - if (nameCnt != infoCnt) { - fprintf(stderr, "%s: mach/task_zone_info: counts not equal?\n", - program); - exit(1); - } + if (nameCnt != infoCnt) { + fprintf(stderr, "%s: mach_zone_name/ mach_zone_info: counts not equal?\n", + program); + exit(1); + } - if (first_time) { - deltas = (char *)malloc(infoCnt); - max_info = (task_zone_info_t *)malloc((infoCnt * sizeof *info)); - } + if (first_time) { + deltas = (char *)malloc(infoCnt); + max_info = (mach_zone_info_t *)malloc((infoCnt * sizeof *info)); + } - if (SortZones) { - for (i = 0; i < nameCnt-1; i++) - for (j = i+1; j < nameCnt; j++) { - unsigned long long wastei, wastej; - - wastei = (info[i].tzi_cur_size - - (info[i].tzi_elem_size * - info[i].tzi_count)); - wastej = (info[j].tzi_cur_size - - (info[j].tzi_elem_size * - info[j].tzi_count)); - - if (wastej > wastei) { - task_zone_info_t tinfo; - mach_zone_name_t tname; - - tinfo = info[i]; - info[i] = info[j]; - info[j] = tinfo; - - tname = name[i]; - name[i] = name[j]; - name[j] = tname; + if (SortZones) { + for (i = 0; i < nameCnt-1; i++) { + for (j = i+1; j < nameCnt; j++) { + unsigned long long wastei, wastej; + + wastei = (info[i].mzi_cur_size - + (info[i].mzi_elem_size * + info[i].mzi_count)); + wastej = (info[j].mzi_cur_size - + (info[j].mzi_elem_size * + info[j].mzi_count)); + + if (wastej > wastei) { + mach_zone_info_t tinfo; + mach_zone_name_t tname; + + tinfo = info[i]; + info[i] = info[j]; + info[j] = tinfo; + + tname = name[i]; + name[i] = name[j]; + name[j] = tname; + } } } - } - - must_print = find_deltas(name, info, max_info, deltas, infoCnt, first_time); - zoneElements = 0; - if (must_print) { - if (ColFormat) { - if (!first_time) - printf("\n"); - colprintzoneheader(); } - for (i = 0; i < nameCnt; i++) { - if (deltas[i]) { - if (ColFormat) - colprintzone(&name[i], &info[i]); - else - printzone(&name[i], &info[i]); - zoneElements += info[i].tzi_count; + + must_print = find_deltas(name, info, max_info, deltas, infoCnt, first_time); + zoneElements = 0; + if (must_print) { + if (ColFormat) { + if (!first_time) + printf("\n"); + colprintzoneheader(); + } + for (i = 0; i < nameCnt; i++) { + if (deltas[i]) { + if (ColFormat) + colprintzone(&name[i], &info[i]); + else + printzone(&name[i], &info[i]); + zoneElements += info[i].mzi_count; + } } } - } - if (ShowLarge && first_time) { - PrintLarge(wiredInfo, wiredInfoCnt, &info[0], &name[0], - nameCnt, zoneElements, - SortZones ? &SortSize : &SortName, ColFormat); - } + if (ShowLarge && first_time) { + PrintLarge(wiredInfo, wiredInfoCnt, &info[0], &name[0], + nameCnt, zoneElements, + SortZones ? &SortSize : &SortName, ColFormat); + } - first_time = 0; + first_time = 0; - if ((name != NULL) && (nameCnt != 0)) { - kr = vm_deallocate(mach_task_self(), (vm_address_t) name, - (vm_size_t) (nameCnt * sizeof *name)); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: vm_deallocate: %s\n", - program, mach_error_string(kr)); - exit(1); + if ((name != NULL) && (nameCnt != 0)) { + kr = vm_deallocate(mach_task_self(), (vm_address_t) name, + (vm_size_t) (nameCnt * sizeof *name)); + if (kr != KERN_SUCCESS) { + fprintf(stderr, "%s: vm_deallocate: %s\n", + program, mach_error_string(kr)); + exit(1); + } } - } - if ((info != NULL) && (infoCnt != 0)) { - kr = vm_deallocate(mach_task_self(), (vm_address_t) info, - (vm_size_t) (infoCnt * sizeof *info)); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: vm_deallocate: %s\n", - program, mach_error_string(kr)); - exit(1); + if ((info != NULL) && (infoCnt != 0)) { + kr = vm_deallocate(mach_task_self(), (vm_address_t) info, + (vm_size_t) (infoCnt * sizeof *info)); + if (kr != KERN_SUCCESS) { + fprintf(stderr, "%s: vm_deallocate: %s\n", + program, mach_error_string(kr)); + exit(1); + } } - } - if ((wiredInfo != NULL) && (wiredInfoCnt != 0)) { - kr = vm_deallocate(mach_task_self(), (vm_address_t) wiredInfo, - (vm_size_t) (wiredInfoCnt * sizeof *wiredInfo)); - if (kr != KERN_SUCCESS) { - fprintf(stderr, "%s: vm_deallocate: %s\n", - program, mach_error_string(kr)); - exit(1); + if ((wiredInfo != NULL) && (wiredInfoCnt != 0)) { + kr = vm_deallocate(mach_task_self(), (vm_address_t) wiredInfo, + (vm_size_t) (wiredInfoCnt * sizeof *wiredInfo)); + if (kr != KERN_SUCCESS) { + fprintf(stderr, "%s: vm_deallocate: %s\n", + program, mach_error_string(kr)); + exit(1); + } } - } - if ((ShowWasted||ShowTotal) && PrintHeader && !ShowDeltas) { - printf("TOTAL SIZE = %llu\n", totalsize); - printf("TOTAL USED = %llu\n", totalused); - if (ShowWasted) - printf("TOTAL WASTED = %llu\n", totalsize - totalused); - if (ShowTotal) - printf("TOTAL ALLOCS = %llu\n", totalsum); - } + if ((ShowWasted||ShowTotal) && PrintHeader && !ShowDeltas) { + printf("\nZONE TOTALS\n"); + printf("---------------------------------------------\n"); + printf("TOTAL SIZE = %llu\n", totalsize); + printf("TOTAL USED = %llu\n", totalused); + if (ShowWasted) { + printf("TOTAL WASTED = %llu\n", totalsize - totalused); + printf("TOTAL FRAGMENTED = %llu\n", totalfragmented); + printf("TOTAL COLLECTABLE = %llu\n", totalcollectable); + } + if (ShowTotal) + printf("TOTAL ALLOCS = %llu\n", totalsum); + } - if (ShowDeltas == FALSE || last_time) - break; + if (ShowDeltas == FALSE || last_time) + break; - sleep(interval); - } + sleep(interval); + } exit(0); } @@ -408,64 +432,55 @@ substr(const char *a, size_t alen, const char *b, size_t blen) } static void -printzone(mach_zone_name_t *name, task_zone_info_t *info) +printzone(mach_zone_name_t *name, mach_zone_info_t *info) { - unsigned long long used, size; + unsigned long long used, size, fragmented, collectable; printf("%.*s zone:\n", (int)sizeof name->mzn_name, name->mzn_name); printf("\tcur_size: %lluK bytes (%llu elements)\n", - info->tzi_cur_size/1024, - (info->tzi_elem_size == 0) ? 0 : - info->tzi_cur_size/info->tzi_elem_size); + info->mzi_cur_size/1024, + (info->mzi_elem_size == 0) ? 0 : + info->mzi_cur_size/info->mzi_elem_size); printf("\tmax_size: %lluK bytes (%llu elements)\n", - info->tzi_max_size/1024, - (info->tzi_elem_size == 0) ? 0 : - info->tzi_max_size/info->tzi_elem_size); + info->mzi_max_size/1024, + (info->mzi_elem_size == 0) ? 0 : + info->mzi_max_size/info->mzi_elem_size); printf("\telem_size: %llu bytes\n", - info->tzi_elem_size); + info->mzi_elem_size); printf("\t# of elems: %llu\n", - info->tzi_count); + info->mzi_count); printf("\talloc_size: %lluK bytes (%llu elements)\n", - info->tzi_alloc_size/1024, - (info->tzi_elem_size == 0) ? 0 : - info->tzi_alloc_size/info->tzi_elem_size); - if (info->tzi_exhaustible) + info->mzi_alloc_size/1024, + (info->mzi_elem_size == 0) ? 0 : + info->mzi_alloc_size/info->mzi_elem_size); + if (info->mzi_exhaustible) printf("\tEXHAUSTIBLE\n"); - if (info->tzi_collectable) + if (GET_MZI_COLLECTABLE_FLAG(info->mzi_collectable)) printf("\tCOLLECTABLE\n"); - if (ShowPid && info->tzi_caller_acct) - printf("\tCALLER ACCOUNTED\n"); - if (ShowPid) { - pidsum += info->tzi_task_alloc - info->tzi_task_free; - printf("\tproc_alloc_size: %8dK bytes (%llu elements)\n", - (int)((info->tzi_task_alloc - info->tzi_task_free)/1024), - (info->tzi_elem_size == 0) ? 0 : - (info->tzi_task_alloc - info->tzi_task_free)/info->tzi_elem_size); - } if (ShowWasted) { - totalused += used = info->tzi_elem_size * info->tzi_count; - totalsize += size = info->tzi_cur_size; + totalused += used = info->mzi_elem_size * info->mzi_count; + totalsize += size = info->mzi_cur_size; + totalcollectable += collectable = GET_MZI_COLLECTABLE_BYTES(info->mzi_collectable); + totalfragmented += fragmented = size - used - collectable; printf("\t\t\t\t\tWASTED: %llu\n", size - used); + printf("\t\t\t\t\tFRAGMENTED: %llu\n", fragmented); + printf("\t\t\t\t\tCOLLECTABLE: %llu\n", collectable); } if (ShowTotal) { - totalsum += info->tzi_sum_size; + totalsum += info->mzi_sum_size; printf("\t\t\t\t\tTOTAL: %llu\n", totalsum); - if (ShowPid) - printf("\t\t\t\t\tPID TOTAL: %llu\n", pidsum); } } static void -colprintzone(mach_zone_name_t *zone_name, task_zone_info_t *info) +colprintzone(mach_zone_name_t *zone_name, mach_zone_info_t *info) { char *name = zone_name->mzn_name; int j, namewidth; - unsigned long long used, size; + unsigned long long used, size, fragmented, collectable; + + namewidth = columns[COL_ZONE_NAME].colwidth; - namewidth = 25; - if (ShowWasted || ShowTotal) { - namewidth -= 7; - } for (j = 0; j < namewidth - 1 && name[j]; j++) { if (name[j] == ' ') { putchar('.'); @@ -484,79 +499,101 @@ colprintzone(mach_zone_name_t *zone_name, task_zone_info_t *info) putchar(' '); } } - printf(" %6llu", info->tzi_elem_size); - PRINTK(" %10llu", info->tzi_cur_size); - if (info->tzi_max_size / 1024 > 9999999) { - printf(" --------"); - } else { - PRINTK(" %10llu", info->tzi_max_size); + + +#define PRINTCOL(value, index) \ + if (columns[(index)].visible) { \ + printf(" %*llu", columns[(index)].colwidth * columns[(index)].alignment, (value)); \ } - printf(" %10llu", info->tzi_cur_size / info->tzi_elem_size); - if (info->tzi_max_size / 1024 >= 999999999) { - printf(" ----------"); - } else { - printf(" %11llu", info->tzi_max_size / info->tzi_elem_size); +#define PRINTCOLSTR(value, index) \ + if (columns[(index)].visible) { \ + printf(" %*s", columns[(index)].colwidth * columns[(index)].alignment, (value)); \ } - printf(" %11llu", info->tzi_count); - PRINTK(" %5llu", info->tzi_alloc_size); - printf(" %6llu", info->tzi_alloc_size / info->tzi_elem_size); - - totalused += used = info->tzi_elem_size * info->tzi_count; - totalsize += size = info->tzi_cur_size; - totalsum += info->tzi_sum_size; - - printf(" %c%c%c", - (info->tzi_exhaustible ? 'X' : ' '), - (info->tzi_caller_acct ? 'A' : ' '), - (info->tzi_collectable ? 'C' : ' ')); - if (ShowWasted) { - PRINTK(" %8llu", size - used); +#define PRINTCOLK(value, index) \ + if (columns[(index)].visible) { \ + printf(" %*lluK", (columns[(index)].colwidth - 1) * columns[(index)].alignment, (value) / 1024 ); \ } - if (ShowPid) { - printf("%8dK", (int)((info->tzi_task_alloc - info->tzi_task_free)/1024)); +#define PRINTCOLSZ(value, index) \ + if (columns[(index)].visible) { \ + if ((value) < 1024) { \ + printf(" %*lluB", (columns[(index)].colwidth - 1) * columns[(index)].alignment, (value)); \ + } else { \ + PRINTCOLK(value, index) \ + } \ } - if (ShowTotal) { - if (info->tzi_sum_size < 1024) - printf(" %16lluB", info->tzi_sum_size); - else - PRINTK(" %16llu", info->tzi_sum_size); + + + PRINTCOL(info->mzi_elem_size, COL_ELEM_SIZE); + PRINTCOLK(info->mzi_cur_size, COL_CUR_SIZE); + if (info->mzi_max_size / 1024 > 9999999) { + /* + * Zones with preposterously large maximum sizes are shown with `-------' + * in the max size and max num elts fields. + */ + PRINTCOLSTR("-------", COL_MAX_SIZE); + } else { + PRINTCOLK(info->mzi_max_size, COL_MAX_SIZE); } + PRINTCOL(info->mzi_cur_size / info->mzi_elem_size, COL_CUR_ELTS); + if (info->mzi_max_size / 1024 > 9999999) { + PRINTCOLSTR("-------", COL_MAX_ELTS); + } else { + PRINTCOL(info->mzi_max_size / info->mzi_elem_size, COL_MAX_ELTS); + } + PRINTCOL(info->mzi_count, COL_CUR_INUSE); + PRINTCOLK(info->mzi_alloc_size, COL_ALLOC_SIZE); + PRINTCOL(info->mzi_alloc_size / info->mzi_elem_size, COL_ALLOC_COUNT); + + totalused += used = info->mzi_elem_size * info->mzi_count; + totalsize += size = info->mzi_cur_size; + totalsum += info->mzi_sum_size; + totalcollectable += collectable = GET_MZI_COLLECTABLE_BYTES(info->mzi_collectable); + totalfragmented += fragmented = size - used - collectable; + + printf(" %c%c", + (info->mzi_exhaustible ? 'X' : ' '), + (GET_MZI_COLLECTABLE_FLAG(info->mzi_collectable) ? 'C' : ' ')); + + PRINTCOLSZ(fragmented, COL_FRAG_SIZE); + PRINTCOLSZ(collectable, COL_FREE_SIZE); + PRINTCOLSZ(info->mzi_sum_size, COL_TOTAL_ALLOCS); + printf("\n"); } + static void colprintzoneheader(void) { + int i, totalwidth = 0; + if (! PrintHeader) { return; } - printf("%s elem cur max cur max" - " cur alloc alloc %s%s\n", - (ShowWasted||ShowTotal)? "" : " ", - (ShowWasted)? " ":"", - (ShowPid) ? " PID" : "" ); - printf("zone name%s size size size #elts #elts" - " inuse size count ", (ShowWasted||ShowTotal)? " " : " " ); - if (ShowWasted) - printf(" wasted"); - if (ShowPid) - printf(" Allocs"); - if (ShowTotal) - printf(" Total Allocs"); - printf("\n%s-------------------------------------------------------" - "-----------------------------------------------", - (ShowWasted||ShowTotal)? "" : "-------"); - if (ShowWasted) - printf("----------"); - if (ShowPid) - printf("---------"); - if (ShowTotal) - printf("------------------"); + + for (i = 0; i < COL_MAX; i++) { + if (columns[i].visible) { + printf("%*s ", columns[i].colwidth * columns[i].alignment, columns[i].line1); + } + } + printf("\n"); + + for (i = 0; i < COL_MAX; i++) { + if (columns[i].visible) { + printf("%*s ", columns[i].colwidth * columns[i].alignment, columns[i].line2); + totalwidth += (columns[i].colwidth + 1); + } + } + + printf("\n"); + for (i = 0; i < totalwidth; i++) { + printf("-"); + } printf("\n"); } int -find_deltas(mach_zone_name_t *name, task_zone_info_t *info, task_zone_info_t *max_info, +find_deltas(mach_zone_name_t *name, mach_zone_info_t *info, mach_zone_info_t *max_info, char *deltas, int cnt, int first_time) { int i; @@ -566,10 +603,10 @@ find_deltas(mach_zone_name_t *name, task_zone_info_t *info, task_zone_info_t *ma deltas[i] = 0; if (substr(zname, znamelen, name[i].mzn_name, strnlen(name[i].mzn_name, sizeof name[i].mzn_name))) { - if (first_time || info->tzi_cur_size > max_info->tzi_cur_size || - (ShowTotal && ((info->tzi_sum_size >> 1) > max_info->tzi_sum_size))) { - max_info->tzi_cur_size = info->tzi_cur_size; - max_info->tzi_sum_size = info->tzi_sum_size; + if (first_time || info->mzi_cur_size > max_info->mzi_cur_size || + (ShowTotal && ((info->mzi_sum_size >> 1) > max_info->mzi_sum_size))) { + max_info->mzi_cur_size = info->mzi_cur_size; + max_info->mzi_sum_size = info->mzi_sum_size; deltas[i] = 1; found_one = 1; } @@ -831,7 +868,7 @@ SortSize(void * thunk, const void * left, const void * right) static void PrintLarge(mach_memory_info_t *wiredInfo, unsigned int wiredInfoCnt, - task_zone_info_t *zoneInfo, mach_zone_name_t *zoneNames, + mach_zone_info_t *zoneInfo, mach_zone_name_t *zoneNames, unsigned int zoneCnt, uint64_t zoneElements, int (*func)(void *, const void *, const void *), boolean_t column) { @@ -887,7 +924,7 @@ PrintLarge(mach_memory_info_t *wiredInfo, unsigned int wiredInfoCnt, if ((VM_KERN_SITE_ZONE & gSites[site].flags) && gSites[site].zone < zoneCnt) { - elemsTagged += gSites[site].size / zoneInfo[gSites[site].zone].tzi_elem_size; + elemsTagged += gSites[site].size / zoneInfo[gSites[site].zone].mzi_elem_size; } if ((gSites[site].size < 1024) && (gSites[site].peak < 1024)) continue; @@ -970,4 +1007,5 @@ PrintLarge(mach_memory_info_t *wiredInfo, unsigned int wiredInfoCnt, printf("\n"); } + totalsize = zonetotal; } -- 2.47.2