Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
procstat_vm.c
Go to the documentation of this file.
1 #include <sys/user.h>
2 #include <sys/sysctl.h>
3 #include <sys/param.h>
4 #include <libprocstat.h>
5 # ifndef KVME_TYPE_MGTDEVICE
6 # define KVME_TYPE_MGTDEVICE 8
7 # endif
8 void
9 procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
10 {
11  struct kinfo_vmentry *freep, *kve;
12  int ptrwidth;
13  unsigned int i, cnt;
14  const char *str;
15 #ifdef __x86_64__
16  ptrwidth = 14;
17 #else
18  ptrwidth = 2*sizeof(void *) + 2;
19 #endif
20  fprintf(stderr, "%*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n",
21  ptrwidth, "START", ptrwidth, "END", "PRT", "RES",
22  "P""RES", "REF", "SHD", "FL", "TP", "PATH");
23 
24 #ifdef HAVE_PROCSTAT_GETVMMAP
25  freep = procstat_getvmmap(procstat, kipp, &cnt);
26 #else
27  freep = kinfo_getvmmap(kipp->ki_pid, &cnt);
28 #endif
29  if (freep == NULL)
30  return;
31  for (i = 0; i < cnt; i++) {
32  kve = &freep[i];
33  fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_start);
34  fprintf(stderr, "%#*jx ", ptrwidth, (uintmax_t)kve->kve_end);
35  fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-");
36  fprintf(stderr, "%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-");
37  fprintf(stderr, "%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-");
38  fprintf(stderr, "%4d ", kve->kve_resident);
39  fprintf(stderr, "%4d ", kve->kve_private_resident);
40  fprintf(stderr, "%3d ", kve->kve_ref_count);
41  fprintf(stderr, "%3d ", kve->kve_shadow_count);
42  fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
43  fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
44  "-");
45  fprintf(stderr, "%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
46  fprintf(stderr, "%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" :
47  kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-");
48  switch (kve->kve_type) {
49  case KVME_TYPE_NONE:
50  str = "--";
51  break;
52  case KVME_TYPE_DEFAULT:
53  str = "df";
54  break;
55  case KVME_TYPE_VNODE:
56  str = "vn";
57  break;
58  case KVME_TYPE_SWAP:
59  str = "sw";
60  break;
61  case KVME_TYPE_DEVICE:
62  str = "dv";
63  break;
64  case KVME_TYPE_PHYS:
65  str = "ph";
66  break;
67  case KVME_TYPE_DEAD:
68  str = "dd";
69  break;
70  case KVME_TYPE_SG:
71  str = "sg";
72  break;
74  str = "md";
75  break;
76  case KVME_TYPE_UNKNOWN:
77  default:
78  str = "??";
79  break;
80  }
81  fprintf(stderr, "%-2s ", str);
82  fprintf(stderr, "%-s\n", kve->kve_path);
83  }
84  free(freep);
85 }
i
uint32_t i
Definition: rb_mjit_min_header-2.7.1.h:5464
uintmax_t
__uintmax_t uintmax_t
Definition: rb_mjit_min_header-2.7.1.h:1187
KVME_TYPE_MGTDEVICE
#define KVME_TYPE_MGTDEVICE
Definition: procstat_vm.c:6
NULL
#define NULL
Definition: _sdbm.c:101
procstat_vm
void procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
Definition: procstat_vm.c:9
cnt
rb_atomic_t cnt[RUBY_NSIG]
Definition: signal.c:503
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
free
#define free(x)
Definition: dln.c:52
stderr
#define stderr
Definition: rb_mjit_min_header-2.7.1.h:1485
fprintf
int fprintf(FILE *__restrict, const char *__restrict,...) __attribute__((__format__(__printf__