1 #include "compat-util.h"
3 static void mincore_stats(const char *path
)
12 static const char *fmt
= sizeof(void *) == 8 ?
13 "%s: %016lu %x\n": "%s: %08lu %x\n";
15 if ((fd
= open(path
, O_RDONLY
|O_NOATIME
)) < 0) {
16 fprintf(stderr
, "%s: open(): %s\n", path
, strerror(errno
));
20 if (fstat(fd
, &sb
) < 0) {
21 fprintf(stderr
, "%s: fstat(%d): %s\n",
22 path
, fd
, strerror(errno
));
26 vec_len
= (sb
.st_size
+ page_size() - 1) / page_size();
27 if (!(vec
= malloc(vec_len
))) {
28 fprintf(stderr
, "%s: malloc(%lu): %s\n",
29 path
, (unsigned long)vec_len
, strerror(errno
));
33 map_len
= PAGE_ALIGN(sb
.st_size
);
34 if (!(map
= mmap(NULL
, map_len
, PROT_READ
, MAP_SHARED
, fd
, 0))) {
35 fprintf(stderr
, "%s: mmap(%lu): %s\n",
36 path
, (unsigned long)vec_len
, strerror(errno
));
40 if (mincore(map
, map_len
, vec
) < 0) {
41 fprintf(stderr
, "%s: mincore(%lu): %s\n",
42 path
, (unsigned long)vec_len
, strerror(errno
));
46 for (i
= 0; i
< vec_len
; ++i
)
47 printf(fmt
, path
, (unsigned long)(page_size() * i
), vec
[i
]);
56 int main(int argc
, char * const argv
[])
60 for (i
= 1; i
< argc
; ++i
)
61 mincore_stats(argv
[i
]);