2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
12 #include <system_info.h>
15 static struct option
const kLongOptions
[] = {
16 {"periodic", no_argument
, 0, 'p'},
17 {"rate", required_argument
, 0, 'r'},
18 {"help", no_argument
, 0, 'h'},
22 extern const char *__progname
;
23 static const char *kProgramName
= __progname
;
29 fprintf(stderr
, "usage: %s [-p] [-r <time>]\n"
30 " -p,--periodic\tDumps changes periodically every second.\n"
31 " -r,--rate\tDumps changes periodically every <time> milli seconds.\n",
39 main(int argc
, char** argv
)
41 bool periodically
= false;
42 bigtime_t rate
= 1000000LL;
45 while ((c
= getopt_long(argc
, argv
, "pr:h", kLongOptions
, NULL
)) != -1) {
53 rate
= atoi(optarg
) * 1000LL;
55 fprintf(stderr
, "%s: Invalid rate: %s\n",
56 kProgramName
, optarg
);
70 status_t status
= get_system_info(&info
);
72 fprintf(stderr
, "%s: cannot get system info: %s\n", kProgramName
,
77 printf("max memory:\t\t%Lu\n", info
.max_pages
* B_PAGE_SIZE
);
78 printf("free memory:\t\t%Lu\n", info
.free_memory
);
79 printf("needed memory:\t\t%Lu\n", info
.needed_memory
);
80 printf("block cache memory:\t%Lu\n", info
.block_cache_pages
* B_PAGE_SIZE
);
81 printf("max swap space:\t\t%Lu\n", info
.max_swap_pages
* B_PAGE_SIZE
);
82 printf("free swap space:\t%Lu\n", info
.free_swap_pages
* B_PAGE_SIZE
);
83 printf("page faults:\t\t%lu\n", info
.page_faults
);
86 puts("\npage faults used memory used swap block cache");
87 system_info lastInfo
= info
;
92 get_system_info(&info
);
94 int32 pageFaults
= info
.page_faults
- lastInfo
.page_faults
;
96 = (info
.max_pages
* B_PAGE_SIZE
- info
.free_memory
)
97 - (lastInfo
.max_pages
* B_PAGE_SIZE
- lastInfo
.free_memory
);
99 = ((info
.max_swap_pages
- info
.free_swap_pages
)
100 - (lastInfo
.max_swap_pages
- lastInfo
.free_swap_pages
))
103 = (info
.block_cache_pages
- lastInfo
.block_cache_pages
)
105 printf("%11" B_PRId32
" %11" B_PRId64
" %11" B_PRId64
" %11"
106 B_PRId64
"\n", pageFaults
, usedMemory
, usedSwap
, blockCache
);