int memstat_kvm_all(struct memory_type_list *mtlp, void *kvm_handle) { if (memstat_kvm_malloc(mtlp, kvm_handle) < 0) return (-1); if (memstat_kvm_uma(mtlp, kvm_handle) < 0) return (-1); return (0); }
static void domemstat_malloc(void) { struct memory_type_list *mtlp; struct memory_type *mtp; int error, first, i; mtlp = memstat_mtl_alloc(); if (mtlp == NULL) { warn("memstat_mtl_alloc"); return; } if (kd == NULL) { if (memstat_sysctl_malloc(mtlp, 0) < 0) { warnx("memstat_sysctl_malloc: %s", memstat_strerror(memstat_mtl_geterror(mtlp))); return; } } else { if (memstat_kvm_malloc(mtlp, kd) < 0) { error = memstat_mtl_geterror(mtlp); if (error == MEMSTAT_ERROR_KVM) warnx("memstat_kvm_malloc: %s", kvm_geterr(kd)); else warnx("memstat_kvm_malloc: %s", memstat_strerror(error)); } } printf("%13s %5s %6s %7s %8s Size(s)\n", "Type", "InUse", "MemUse", "HighUse", "Requests"); for (mtp = memstat_mtl_first(mtlp); mtp != NULL; mtp = memstat_mtl_next(mtp)) { if (memstat_get_numallocs(mtp) == 0 && memstat_get_count(mtp) == 0) continue; printf("%13s %5" PRIu64 " %5" PRIu64 "K %7s %8" PRIu64 " ", memstat_get_name(mtp), memstat_get_count(mtp), (memstat_get_bytes(mtp) + 1023) / 1024, "-", memstat_get_numallocs(mtp)); first = 1; for (i = 0; i < 32; i++) { if (memstat_get_sizemask(mtp) & (1 << i)) { if (!first) printf(","); printf("%d", 1 << (i + 4)); first = 0; } } printf("\n"); } memstat_mtl_free(mtlp); }