xref: /aosp_15_r20/external/bcc/libbpf-tools/cachestat.c (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2*387f9dfdSAndroid Build Coastguard Worker // Copyright (c) 2021 Wenbo Zhang
3*387f9dfdSAndroid Build Coastguard Worker //
4*387f9dfdSAndroid Build Coastguard Worker // Based on cachestat(8) from BCC by Brendan Gregg and Allan McAleavy.
5*387f9dfdSAndroid Build Coastguard Worker //  8-Mar-2021   Wenbo Zhang   Created this.
6*387f9dfdSAndroid Build Coastguard Worker // 30-Jan-2023   Rong Tao      Add kprobe and use fentry_can_attach() decide
7*387f9dfdSAndroid Build Coastguard Worker //                             use fentry/kprobe
8*387f9dfdSAndroid Build Coastguard Worker // 15-Feb-2023   Rong Tao      Add tracepoint writeback_dirty_{page,folio}
9*387f9dfdSAndroid Build Coastguard Worker #include <argp.h>
10*387f9dfdSAndroid Build Coastguard Worker #include <signal.h>
11*387f9dfdSAndroid Build Coastguard Worker #include <stdio.h>
12*387f9dfdSAndroid Build Coastguard Worker #include <unistd.h>
13*387f9dfdSAndroid Build Coastguard Worker #include <time.h>
14*387f9dfdSAndroid Build Coastguard Worker #include <bpf/libbpf.h>
15*387f9dfdSAndroid Build Coastguard Worker #include <bpf/bpf.h>
16*387f9dfdSAndroid Build Coastguard Worker #include "cachestat.skel.h"
17*387f9dfdSAndroid Build Coastguard Worker #include "trace_helpers.h"
18*387f9dfdSAndroid Build Coastguard Worker 
19*387f9dfdSAndroid Build Coastguard Worker static struct env {
20*387f9dfdSAndroid Build Coastguard Worker 	time_t interval;
21*387f9dfdSAndroid Build Coastguard Worker 	int times;
22*387f9dfdSAndroid Build Coastguard Worker 	bool timestamp;
23*387f9dfdSAndroid Build Coastguard Worker 	bool verbose;
24*387f9dfdSAndroid Build Coastguard Worker } env = {
25*387f9dfdSAndroid Build Coastguard Worker 	.interval = 1,
26*387f9dfdSAndroid Build Coastguard Worker 	.times = 99999999,
27*387f9dfdSAndroid Build Coastguard Worker };
28*387f9dfdSAndroid Build Coastguard Worker 
29*387f9dfdSAndroid Build Coastguard Worker static volatile bool exiting;
30*387f9dfdSAndroid Build Coastguard Worker 
31*387f9dfdSAndroid Build Coastguard Worker const char *argp_program_version = "cachestat 0.1";
32*387f9dfdSAndroid Build Coastguard Worker const char *argp_program_bug_address =
33*387f9dfdSAndroid Build Coastguard Worker 	"https://github.com/iovisor/bcc/tree/master/libbpf-tools";
34*387f9dfdSAndroid Build Coastguard Worker const char argp_program_doc[] =
35*387f9dfdSAndroid Build Coastguard Worker "Count cache kernel function calls.\n"
36*387f9dfdSAndroid Build Coastguard Worker "\n"
37*387f9dfdSAndroid Build Coastguard Worker "USAGE: cachestat [--help] [-T] [interval] [count]\n"
38*387f9dfdSAndroid Build Coastguard Worker "\n"
39*387f9dfdSAndroid Build Coastguard Worker "EXAMPLES:\n"
40*387f9dfdSAndroid Build Coastguard Worker "    cachestat          # shows hits and misses to the file system page cache\n"
41*387f9dfdSAndroid Build Coastguard Worker "    cachestat -T       # include timestamps\n"
42*387f9dfdSAndroid Build Coastguard Worker "    cachestat 1 10     # print 1 second summaries, 10 times\n";
43*387f9dfdSAndroid Build Coastguard Worker 
44*387f9dfdSAndroid Build Coastguard Worker static const struct argp_option opts[] = {
45*387f9dfdSAndroid Build Coastguard Worker 	{ "timestamp", 'T', NULL, 0, "Print timestamp" },
46*387f9dfdSAndroid Build Coastguard Worker 	{ "verbose", 'v', NULL, 0, "Verbose debug output" },
47*387f9dfdSAndroid Build Coastguard Worker 	{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" },
48*387f9dfdSAndroid Build Coastguard Worker 	{},
49*387f9dfdSAndroid Build Coastguard Worker };
50*387f9dfdSAndroid Build Coastguard Worker 
parse_arg(int key,char * arg,struct argp_state * state)51*387f9dfdSAndroid Build Coastguard Worker static error_t parse_arg(int key, char *arg, struct argp_state *state)
52*387f9dfdSAndroid Build Coastguard Worker {
53*387f9dfdSAndroid Build Coastguard Worker 	static int pos_args;
54*387f9dfdSAndroid Build Coastguard Worker 
55*387f9dfdSAndroid Build Coastguard Worker 	switch (key) {
56*387f9dfdSAndroid Build Coastguard Worker 	case 'h':
57*387f9dfdSAndroid Build Coastguard Worker 		argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
58*387f9dfdSAndroid Build Coastguard Worker 		break;
59*387f9dfdSAndroid Build Coastguard Worker 	case 'v':
60*387f9dfdSAndroid Build Coastguard Worker 		env.verbose = true;
61*387f9dfdSAndroid Build Coastguard Worker 		break;
62*387f9dfdSAndroid Build Coastguard Worker 	case 'T':
63*387f9dfdSAndroid Build Coastguard Worker 		env.timestamp = true;
64*387f9dfdSAndroid Build Coastguard Worker 		break;
65*387f9dfdSAndroid Build Coastguard Worker 	case ARGP_KEY_ARG:
66*387f9dfdSAndroid Build Coastguard Worker 		errno = 0;
67*387f9dfdSAndroid Build Coastguard Worker 		if (pos_args == 0) {
68*387f9dfdSAndroid Build Coastguard Worker 			env.interval = strtol(arg, NULL, 10);
69*387f9dfdSAndroid Build Coastguard Worker 			if (errno) {
70*387f9dfdSAndroid Build Coastguard Worker 				fprintf(stderr, "invalid internal\n");
71*387f9dfdSAndroid Build Coastguard Worker 				argp_usage(state);
72*387f9dfdSAndroid Build Coastguard Worker 			}
73*387f9dfdSAndroid Build Coastguard Worker 		} else if (pos_args == 1) {
74*387f9dfdSAndroid Build Coastguard Worker 			env.times = strtol(arg, NULL, 10);
75*387f9dfdSAndroid Build Coastguard Worker 			if (errno) {
76*387f9dfdSAndroid Build Coastguard Worker 				fprintf(stderr, "invalid times\n");
77*387f9dfdSAndroid Build Coastguard Worker 				argp_usage(state);
78*387f9dfdSAndroid Build Coastguard Worker 			}
79*387f9dfdSAndroid Build Coastguard Worker 		} else {
80*387f9dfdSAndroid Build Coastguard Worker 			fprintf(stderr,
81*387f9dfdSAndroid Build Coastguard Worker 				"unrecognized positional argument: %s\n", arg);
82*387f9dfdSAndroid Build Coastguard Worker 			argp_usage(state);
83*387f9dfdSAndroid Build Coastguard Worker 		}
84*387f9dfdSAndroid Build Coastguard Worker 		pos_args++;
85*387f9dfdSAndroid Build Coastguard Worker 		break;
86*387f9dfdSAndroid Build Coastguard Worker 	default:
87*387f9dfdSAndroid Build Coastguard Worker 		return ARGP_ERR_UNKNOWN;
88*387f9dfdSAndroid Build Coastguard Worker 	}
89*387f9dfdSAndroid Build Coastguard Worker 	return 0;
90*387f9dfdSAndroid Build Coastguard Worker }
91*387f9dfdSAndroid Build Coastguard Worker 
libbpf_print_fn(enum libbpf_print_level level,const char * format,va_list args)92*387f9dfdSAndroid Build Coastguard Worker static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)
93*387f9dfdSAndroid Build Coastguard Worker {
94*387f9dfdSAndroid Build Coastguard Worker 	if (level == LIBBPF_DEBUG && !env.verbose)
95*387f9dfdSAndroid Build Coastguard Worker 		return 0;
96*387f9dfdSAndroid Build Coastguard Worker 	return vfprintf(stderr, format, args);
97*387f9dfdSAndroid Build Coastguard Worker }
98*387f9dfdSAndroid Build Coastguard Worker 
sig_handler(int sig)99*387f9dfdSAndroid Build Coastguard Worker static void sig_handler(int sig)
100*387f9dfdSAndroid Build Coastguard Worker {
101*387f9dfdSAndroid Build Coastguard Worker 	exiting = true;
102*387f9dfdSAndroid Build Coastguard Worker }
103*387f9dfdSAndroid Build Coastguard Worker 
get_meminfo(__u64 * buffers,__u64 * cached)104*387f9dfdSAndroid Build Coastguard Worker static int get_meminfo(__u64 *buffers, __u64 *cached)
105*387f9dfdSAndroid Build Coastguard Worker {
106*387f9dfdSAndroid Build Coastguard Worker 	FILE *f;
107*387f9dfdSAndroid Build Coastguard Worker 
108*387f9dfdSAndroid Build Coastguard Worker 	f = fopen("/proc/meminfo", "r");
109*387f9dfdSAndroid Build Coastguard Worker 	if (!f)
110*387f9dfdSAndroid Build Coastguard Worker 		return -1;
111*387f9dfdSAndroid Build Coastguard Worker 	if (fscanf(f,
112*387f9dfdSAndroid Build Coastguard Worker 		   "MemTotal: %*u kB\n"
113*387f9dfdSAndroid Build Coastguard Worker 		   "MemFree: %*u kB\n"
114*387f9dfdSAndroid Build Coastguard Worker 		   "MemAvailable: %*u kB\n"
115*387f9dfdSAndroid Build Coastguard Worker 		   "Buffers: %llu kB\n"
116*387f9dfdSAndroid Build Coastguard Worker 		   "Cached: %llu kB\n",
117*387f9dfdSAndroid Build Coastguard Worker 		   buffers, cached) != 2) {
118*387f9dfdSAndroid Build Coastguard Worker 		fclose(f);
119*387f9dfdSAndroid Build Coastguard Worker 		return -1;
120*387f9dfdSAndroid Build Coastguard Worker 	}
121*387f9dfdSAndroid Build Coastguard Worker 	fclose(f);
122*387f9dfdSAndroid Build Coastguard Worker 	return 0;
123*387f9dfdSAndroid Build Coastguard Worker }
124*387f9dfdSAndroid Build Coastguard Worker 
main(int argc,char ** argv)125*387f9dfdSAndroid Build Coastguard Worker int main(int argc, char **argv)
126*387f9dfdSAndroid Build Coastguard Worker {
127*387f9dfdSAndroid Build Coastguard Worker 	static const struct argp argp = {
128*387f9dfdSAndroid Build Coastguard Worker 		.options = opts,
129*387f9dfdSAndroid Build Coastguard Worker 		.parser = parse_arg,
130*387f9dfdSAndroid Build Coastguard Worker 		.doc = argp_program_doc,
131*387f9dfdSAndroid Build Coastguard Worker 	};
132*387f9dfdSAndroid Build Coastguard Worker 	__u64 buffers, cached, mbd;
133*387f9dfdSAndroid Build Coastguard Worker 	struct cachestat_bpf *obj;
134*387f9dfdSAndroid Build Coastguard Worker 	__s64 total, misses, hits;
135*387f9dfdSAndroid Build Coastguard Worker 	struct tm *tm;
136*387f9dfdSAndroid Build Coastguard Worker 	float ratio;
137*387f9dfdSAndroid Build Coastguard Worker 	char ts[32];
138*387f9dfdSAndroid Build Coastguard Worker 	time_t t;
139*387f9dfdSAndroid Build Coastguard Worker 	int err;
140*387f9dfdSAndroid Build Coastguard Worker 
141*387f9dfdSAndroid Build Coastguard Worker 	err = argp_parse(&argp, argc, argv, 0, NULL, NULL);
142*387f9dfdSAndroid Build Coastguard Worker 	if (err)
143*387f9dfdSAndroid Build Coastguard Worker 		return err;
144*387f9dfdSAndroid Build Coastguard Worker 
145*387f9dfdSAndroid Build Coastguard Worker 	libbpf_set_print(libbpf_print_fn);
146*387f9dfdSAndroid Build Coastguard Worker 
147*387f9dfdSAndroid Build Coastguard Worker 	obj = cachestat_bpf__open();
148*387f9dfdSAndroid Build Coastguard Worker 	if (!obj) {
149*387f9dfdSAndroid Build Coastguard Worker 		fprintf(stderr, "failed to open BPF object\n");
150*387f9dfdSAndroid Build Coastguard Worker 		return 1;
151*387f9dfdSAndroid Build Coastguard Worker 	}
152*387f9dfdSAndroid Build Coastguard Worker 
153*387f9dfdSAndroid Build Coastguard Worker 	/**
154*387f9dfdSAndroid Build Coastguard Worker 	 * account_page_dirtied was renamed to folio_account_dirtied
155*387f9dfdSAndroid Build Coastguard Worker 	 * in kernel commit 203a31516616 ("mm/writeback: Add __folio_mark_dirty()")
156*387f9dfdSAndroid Build Coastguard Worker 	 */
157*387f9dfdSAndroid Build Coastguard Worker 	if (fentry_can_attach("folio_account_dirtied", NULL)) {
158*387f9dfdSAndroid Build Coastguard Worker 		err = bpf_program__set_attach_target(obj->progs.fentry_account_page_dirtied, 0,
159*387f9dfdSAndroid Build Coastguard Worker 						     "folio_account_dirtied");
160*387f9dfdSAndroid Build Coastguard Worker 		if (err) {
161*387f9dfdSAndroid Build Coastguard Worker 			fprintf(stderr, "failed to set attach target\n");
162*387f9dfdSAndroid Build Coastguard Worker 			goto cleanup;
163*387f9dfdSAndroid Build Coastguard Worker 		}
164*387f9dfdSAndroid Build Coastguard Worker 	}
165*387f9dfdSAndroid Build Coastguard Worker 	if (kprobe_exists("folio_account_dirtied")) {
166*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_account_page_dirtied, false);
167*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.tracepoint__writeback_dirty_folio, false);
168*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.tracepoint__writeback_dirty_page, false);
169*387f9dfdSAndroid Build Coastguard Worker 	} else if (kprobe_exists("account_page_dirtied")) {
170*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_folio_account_dirtied, false);
171*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.tracepoint__writeback_dirty_folio, false);
172*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.tracepoint__writeback_dirty_page, false);
173*387f9dfdSAndroid Build Coastguard Worker 	} else if (tracepoint_exists("writeback", "writeback_dirty_folio")) {
174*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_account_page_dirtied, false);
175*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_folio_account_dirtied, false);
176*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.tracepoint__writeback_dirty_page, false);
177*387f9dfdSAndroid Build Coastguard Worker 	} else if (tracepoint_exists("writeback", "writeback_dirty_page")) {
178*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_account_page_dirtied, false);
179*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_folio_account_dirtied, false);
180*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.tracepoint__writeback_dirty_folio, false);
181*387f9dfdSAndroid Build Coastguard Worker 	}
182*387f9dfdSAndroid Build Coastguard Worker 
183*387f9dfdSAndroid Build Coastguard Worker 	/* It fallbacks to kprobes when kernel does not support fentry. */
184*387f9dfdSAndroid Build Coastguard Worker 	if (fentry_can_attach("folio_account_dirtied", NULL)
185*387f9dfdSAndroid Build Coastguard Worker 		|| fentry_can_attach("account_page_dirtied", NULL)) {
186*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_account_page_dirtied, false);
187*387f9dfdSAndroid Build Coastguard Worker 	} else {
188*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.fentry_account_page_dirtied, false);
189*387f9dfdSAndroid Build Coastguard Worker 	}
190*387f9dfdSAndroid Build Coastguard Worker 
191*387f9dfdSAndroid Build Coastguard Worker 	if (fentry_can_attach("add_to_page_cache_lru", NULL)) {
192*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_add_to_page_cache_lru, false);
193*387f9dfdSAndroid Build Coastguard Worker 	} else {
194*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.fentry_add_to_page_cache_lru, false);
195*387f9dfdSAndroid Build Coastguard Worker 	}
196*387f9dfdSAndroid Build Coastguard Worker 
197*387f9dfdSAndroid Build Coastguard Worker 	if (fentry_can_attach("mark_page_accessed", NULL)) {
198*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_mark_page_accessed, false);
199*387f9dfdSAndroid Build Coastguard Worker 	} else {
200*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.fentry_mark_page_accessed, false);
201*387f9dfdSAndroid Build Coastguard Worker 	}
202*387f9dfdSAndroid Build Coastguard Worker 
203*387f9dfdSAndroid Build Coastguard Worker 	if (fentry_can_attach("mark_buffer_dirty", NULL)) {
204*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.kprobe_mark_buffer_dirty, false);
205*387f9dfdSAndroid Build Coastguard Worker 	} else {
206*387f9dfdSAndroid Build Coastguard Worker 		bpf_program__set_autoload(obj->progs.fentry_mark_buffer_dirty, false);
207*387f9dfdSAndroid Build Coastguard Worker 	}
208*387f9dfdSAndroid Build Coastguard Worker 
209*387f9dfdSAndroid Build Coastguard Worker 	err = cachestat_bpf__load(obj);
210*387f9dfdSAndroid Build Coastguard Worker 	if (err) {
211*387f9dfdSAndroid Build Coastguard Worker 		fprintf(stderr, "failed to load BPF object\n");
212*387f9dfdSAndroid Build Coastguard Worker 		goto cleanup;
213*387f9dfdSAndroid Build Coastguard Worker 	}
214*387f9dfdSAndroid Build Coastguard Worker 
215*387f9dfdSAndroid Build Coastguard Worker 	if (!obj->bss) {
216*387f9dfdSAndroid Build Coastguard Worker 		fprintf(stderr, "Memory-mapping BPF maps is supported starting from Linux 5.7, please upgrade.\n");
217*387f9dfdSAndroid Build Coastguard Worker 		goto cleanup;
218*387f9dfdSAndroid Build Coastguard Worker 	}
219*387f9dfdSAndroid Build Coastguard Worker 
220*387f9dfdSAndroid Build Coastguard Worker 	err = cachestat_bpf__attach(obj);
221*387f9dfdSAndroid Build Coastguard Worker 	if (err) {
222*387f9dfdSAndroid Build Coastguard Worker 		fprintf(stderr, "failed to attach BPF programs\n");
223*387f9dfdSAndroid Build Coastguard Worker 		goto cleanup;
224*387f9dfdSAndroid Build Coastguard Worker 	}
225*387f9dfdSAndroid Build Coastguard Worker 
226*387f9dfdSAndroid Build Coastguard Worker 	signal(SIGINT, sig_handler);
227*387f9dfdSAndroid Build Coastguard Worker 
228*387f9dfdSAndroid Build Coastguard Worker 	if (env.timestamp)
229*387f9dfdSAndroid Build Coastguard Worker 		printf("%-8s ", "TIME");
230*387f9dfdSAndroid Build Coastguard Worker 	printf("%8s %8s %8s %8s %12s %10s\n", "HITS", "MISSES", "DIRTIES",
231*387f9dfdSAndroid Build Coastguard Worker 		"HITRATIO", "BUFFERS_MB", "CACHED_MB");
232*387f9dfdSAndroid Build Coastguard Worker 
233*387f9dfdSAndroid Build Coastguard Worker 	while (1) {
234*387f9dfdSAndroid Build Coastguard Worker 		sleep(env.interval);
235*387f9dfdSAndroid Build Coastguard Worker 
236*387f9dfdSAndroid Build Coastguard Worker 		/* total = total cache accesses without counting dirties */
237*387f9dfdSAndroid Build Coastguard Worker 		total = __atomic_exchange_n(&obj->bss->total, 0, __ATOMIC_RELAXED);
238*387f9dfdSAndroid Build Coastguard Worker 		/* misses = total of add to lru because of read misses */
239*387f9dfdSAndroid Build Coastguard Worker 		misses = __atomic_exchange_n(&obj->bss->misses, 0, __ATOMIC_RELAXED);
240*387f9dfdSAndroid Build Coastguard Worker 		/* mbd = total of mark_buffer_dirty events */
241*387f9dfdSAndroid Build Coastguard Worker 		mbd = __atomic_exchange_n(&obj->bss->mbd, 0, __ATOMIC_RELAXED);
242*387f9dfdSAndroid Build Coastguard Worker 
243*387f9dfdSAndroid Build Coastguard Worker 		if (total < 0)
244*387f9dfdSAndroid Build Coastguard Worker 			total = 0;
245*387f9dfdSAndroid Build Coastguard Worker 		if (misses < 0)
246*387f9dfdSAndroid Build Coastguard Worker 			misses = 0;
247*387f9dfdSAndroid Build Coastguard Worker 		hits = total - misses;
248*387f9dfdSAndroid Build Coastguard Worker 		/*
249*387f9dfdSAndroid Build Coastguard Worker 		 * If hits are < 0, then its possible misses are overestimated
250*387f9dfdSAndroid Build Coastguard Worker 		 * due to possibly page cache read ahead adding more pages than
251*387f9dfdSAndroid Build Coastguard Worker 		 * needed. In this case just assume misses as total and reset
252*387f9dfdSAndroid Build Coastguard Worker 		 * hits.
253*387f9dfdSAndroid Build Coastguard Worker 		 */
254*387f9dfdSAndroid Build Coastguard Worker 		if (hits < 0) {
255*387f9dfdSAndroid Build Coastguard Worker 			misses = total;
256*387f9dfdSAndroid Build Coastguard Worker 			hits = 0;
257*387f9dfdSAndroid Build Coastguard Worker 		}
258*387f9dfdSAndroid Build Coastguard Worker 		ratio = total > 0 ? hits * 1.0 / total : 0.0;
259*387f9dfdSAndroid Build Coastguard Worker 		err = get_meminfo(&buffers, &cached);
260*387f9dfdSAndroid Build Coastguard Worker 		if (err) {
261*387f9dfdSAndroid Build Coastguard Worker 			fprintf(stderr, "failed to get meminfo: %d\n", err);
262*387f9dfdSAndroid Build Coastguard Worker 			goto cleanup;
263*387f9dfdSAndroid Build Coastguard Worker 		}
264*387f9dfdSAndroid Build Coastguard Worker 		if (env.timestamp) {
265*387f9dfdSAndroid Build Coastguard Worker 			time(&t);
266*387f9dfdSAndroid Build Coastguard Worker 			tm = localtime(&t);
267*387f9dfdSAndroid Build Coastguard Worker 			strftime(ts, sizeof(ts), "%H:%M:%S", tm);
268*387f9dfdSAndroid Build Coastguard Worker 			printf("%-8s ", ts);
269*387f9dfdSAndroid Build Coastguard Worker 		}
270*387f9dfdSAndroid Build Coastguard Worker 		printf("%8lld %8lld %8llu %7.2f%% %12llu %10llu\n",
271*387f9dfdSAndroid Build Coastguard Worker 			hits, misses, mbd, 100 * ratio,
272*387f9dfdSAndroid Build Coastguard Worker 			buffers / 1024, cached / 1024);
273*387f9dfdSAndroid Build Coastguard Worker 
274*387f9dfdSAndroid Build Coastguard Worker 		if (exiting || --env.times == 0)
275*387f9dfdSAndroid Build Coastguard Worker 			break;
276*387f9dfdSAndroid Build Coastguard Worker 	}
277*387f9dfdSAndroid Build Coastguard Worker 
278*387f9dfdSAndroid Build Coastguard Worker cleanup:
279*387f9dfdSAndroid Build Coastguard Worker 	cachestat_bpf__destroy(obj);
280*387f9dfdSAndroid Build Coastguard Worker 	return err != 0;
281*387f9dfdSAndroid Build Coastguard Worker }
282