Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/procstat/procstat_vm.c
/*- | /*- | ||||
* Copyright (c) 2007 Robert N. M. Watson | * Copyright (c) 2007 Robert N. M. Watson | ||||
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org> | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
Show All 30 Lines | |||||
#include "procstat.h" | #include "procstat.h" | ||||
void | void | ||||
procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp) | procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp) | ||||
{ | { | ||||
struct kinfo_vmentry *freep, *kve; | struct kinfo_vmentry *freep, *kve; | ||||
int ptrwidth; | int ptrwidth; | ||||
int i, cnt; | int i, cnt; | ||||
const char *str; | const char *str, *lstr; | ||||
ptrwidth = 2*sizeof(void *) + 2; | ptrwidth = 2*sizeof(void *) + 2; | ||||
if (!hflag) | if (!hflag) | ||||
printf("%5s %*s %*s %3s %4s %4s %3s %3s %-4s %-2s %-s\n", | xo_emit("{T:/%5s %*s %*s %3s %4s %4s %3s %3s %-4s %-2s %-s}\n", | ||||
"PID", ptrwidth, "START", ptrwidth, "END", "PRT", "RES", | "PID", ptrwidth, "START", ptrwidth, "END", "PRT", "RES", | ||||
"PRES", "REF", "SHD", "FLAG", "TP", "PATH"); | "PRES", "REF", "SHD", "FLAG", "TP", "PATH"); | ||||
xo_emit("{ek:process_id/%d}", kipp->ki_pid); | |||||
freep = procstat_getvmmap(procstat, kipp, &cnt); | freep = procstat_getvmmap(procstat, kipp, &cnt); | ||||
if (freep == NULL) | if (freep == NULL) | ||||
return; | return; | ||||
xo_open_list("vm"); | |||||
for (i = 0; i < cnt; i++) { | for (i = 0; i < cnt; i++) { | ||||
xo_open_instance("vm"); | |||||
kve = &freep[i]; | kve = &freep[i]; | ||||
printf("%5d ", kipp->ki_pid); | xo_emit("{dk:process_id/%5d} ", kipp->ki_pid); | ||||
printf("%#*jx ", ptrwidth, (uintmax_t)kve->kve_start); | xo_emit("{d:kve_start/%#*jx} ", ptrwidth, | ||||
printf("%#*jx ", ptrwidth, (uintmax_t)kve->kve_end); | (uintmax_t)kve->kve_start); | ||||
printf("%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-"); | xo_emit("{d:kve_end/%#*jx} ", ptrwidth, | ||||
printf("%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-"); | (uintmax_t)kve->kve_end); | ||||
printf("%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-"); | xo_emit("{e:kve_start/%#jx}", (uintmax_t)kve->kve_start); | ||||
printf("%4d ", kve->kve_resident); | xo_emit("{e:kve_end/%#jx}", (uintmax_t)kve->kve_end); | ||||
printf("%4d ", kve->kve_private_resident); | xo_emit("{d:read/%s}", kve->kve_protection & KVME_PROT_READ ? | ||||
printf("%3d ", kve->kve_ref_count); | "r" : "-"); | ||||
printf("%3d ", kve->kve_shadow_count); | xo_emit("{d:write/%s}", kve->kve_protection & KVME_PROT_WRITE ? | ||||
printf("%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-"); | "w" : "-"); | ||||
printf("%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" : | xo_emit("{d:exec/%s} ", kve->kve_protection & KVME_PROT_EXEC ? | ||||
"-"); | "x" : "-"); | ||||
printf("%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-"); | xo_open_container("kve_protection"); | ||||
printf("%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" : | xo_emit("{en:read/%s}", kve->kve_protection & KVME_PROT_READ ? | ||||
kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-"); | "true" : "false"); | ||||
xo_emit("{en:write/%s}", kve->kve_protection & KVME_PROT_WRITE ? | |||||
"true" : "false"); | |||||
xo_emit("{en:exec/%s}", kve->kve_protection & KVME_PROT_EXEC ? | |||||
"true" : "false"); | |||||
xo_close_container("kve_protection"); | |||||
xo_emit("{:kve_resident/%4d/%d} ", kve->kve_resident); | |||||
xo_emit("{:kve_private_resident/%4d/%d} ", | |||||
kve->kve_private_resident); | |||||
xo_emit("{:kve_ref_count/%3d/%d} ", kve->kve_ref_count); | |||||
xo_emit("{:kve_shadow_count/%3d/%d} ", kve->kve_shadow_count); | |||||
xo_emit("{d:copy_on_write/%-1s}", kve->kve_flags & | |||||
KVME_FLAG_COW ? "C" : "-"); | |||||
xo_emit("{d:need_copy/%-1s}", kve->kve_flags & | |||||
KVME_FLAG_NEEDS_COPY ? "N" : "-"); | |||||
xo_emit("{d:super_pages/%-1s}", kve->kve_flags & | |||||
KVME_FLAG_SUPER ? "S" : "-"); | |||||
xo_emit("{d:grows_down/%-1s} ", kve->kve_flags & | |||||
KVME_FLAG_GROWS_UP ? "U" : kve->kve_flags & | |||||
KVME_FLAG_GROWS_DOWN ? "D" : "-"); | |||||
xo_open_container("kve_flags"); | |||||
xo_emit("{en:copy_on_write/%s}", kve->kve_flags & | |||||
KVME_FLAG_COW ? "true" : "false"); | |||||
xo_emit("{en:needs_copy/%s}", kve->kve_flags & | |||||
KVME_FLAG_NEEDS_COPY ? "true" : "false"); | |||||
xo_emit("{en:super_pages/%s}", kve->kve_flags & | |||||
KVME_FLAG_SUPER ? "true" : "false"); | |||||
xo_emit("{en:grows_up/%s}", kve->kve_flags & | |||||
KVME_FLAG_GROWS_UP ? "true" : "false"); | |||||
xo_emit("{en:grows_down/%s}", kve->kve_flags & | |||||
KVME_FLAG_GROWS_DOWN ? "true" : "false"); | |||||
xo_close_container("kve_flags"); | |||||
switch (kve->kve_type) { | switch (kve->kve_type) { | ||||
case KVME_TYPE_NONE: | case KVME_TYPE_NONE: | ||||
str = "--"; | str = "--"; | ||||
lstr = "none"; | |||||
break; | break; | ||||
case KVME_TYPE_DEFAULT: | case KVME_TYPE_DEFAULT: | ||||
str = "df"; | str = "df"; | ||||
lstr = "default"; | |||||
break; | break; | ||||
case KVME_TYPE_VNODE: | case KVME_TYPE_VNODE: | ||||
str = "vn"; | str = "vn"; | ||||
lstr = "vnode"; | |||||
break; | break; | ||||
case KVME_TYPE_SWAP: | case KVME_TYPE_SWAP: | ||||
str = "sw"; | str = "sw"; | ||||
lstr = "swap"; | |||||
break; | break; | ||||
case KVME_TYPE_DEVICE: | case KVME_TYPE_DEVICE: | ||||
str = "dv"; | str = "dv"; | ||||
lstr = "device"; | |||||
break; | break; | ||||
case KVME_TYPE_PHYS: | case KVME_TYPE_PHYS: | ||||
str = "ph"; | str = "ph"; | ||||
lstr = "physical"; | |||||
break; | break; | ||||
case KVME_TYPE_DEAD: | case KVME_TYPE_DEAD: | ||||
str = "dd"; | str = "dd"; | ||||
lstr = "dead"; | |||||
break; | break; | ||||
case KVME_TYPE_SG: | case KVME_TYPE_SG: | ||||
str = "sg"; | str = "sg"; | ||||
lstr = "scatter/gather"; | |||||
break; | break; | ||||
case KVME_TYPE_MGTDEVICE: | case KVME_TYPE_MGTDEVICE: | ||||
str = "md"; | str = "md"; | ||||
lstr = "managed_device"; | |||||
break; | break; | ||||
case KVME_TYPE_UNKNOWN: | case KVME_TYPE_UNKNOWN: | ||||
default: | default: | ||||
str = "??"; | str = "??"; | ||||
lstr = "unknown"; | |||||
break; | break; | ||||
} | } | ||||
printf("%-2s ", str); | xo_emit("{d:kve_type/%-2s} ", str); | ||||
printf("%-s\n", kve->kve_path); | xo_emit("{e:kve_type/%s}", lstr); | ||||
xo_emit("{:kve_path/%-s/%s}\n", kve->kve_path); | |||||
xo_close_instance("vm"); | |||||
} | } | ||||
xo_close_list("vm"); | |||||
free(freep); | free(freep); | ||||
} | } |