xref: /spdk/test/app/histogram_perf/histogram_perf.c (revision 8afdeef3becfe9409cc9e7372bd0bc10e8b7d46d)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "spdk/stdinc.h"
7 
8 #include "spdk/env.h"
9 #include "spdk/util.h"
10 #include "spdk/histogram_data.h"
11 
12 /*
13  * This applications is a simple test app used to test the performance of
14  *  tallying datapoints with struct spdk_histogram_data.  It can be used
15  *  to measure the effect of changes to the spdk_histogram_data implementation.
16  *
17  * There are no command line parameters currently - it just tallies
18  *  datapoints for 10 seconds in a default-sized histogram structure and
19  *  then prints out the number of tallies performed.
20  */
21 
22 static void
23 usage(const char *prog)
24 {
25 	printf("usage: %s\n", prog);
26 	printf("Options:\n");
27 }
28 
29 int
30 main(int argc, char **argv)
31 {
32 	struct spdk_histogram_data *h;
33 	struct spdk_env_opts opts;
34 	uint64_t tsc[128], t, end_tsc, count;
35 	uint32_t i;
36 	int ch;
37 	int rc = 0;
38 
39 	while ((ch = getopt(argc, argv, "")) != -1) {
40 		switch (ch) {
41 		default:
42 			usage(argv[0]);
43 			return 1;
44 		}
45 	}
46 
47 	opts.opts_size = sizeof(opts);
48 	spdk_env_opts_init(&opts);
49 	if (spdk_env_init(&opts)) {
50 		printf("Err: Unable to initialize SPDK env\n");
51 		return 1;
52 	}
53 
54 	for (i = 0; i < SPDK_COUNTOF(tsc); i++) {
55 		tsc[i] = spdk_get_ticks();
56 	}
57 
58 	end_tsc = spdk_get_ticks() + (10 * spdk_get_ticks_hz());
59 	count = 0;
60 	h = spdk_histogram_data_alloc();
61 
62 	while (true) {
63 		t = spdk_get_ticks();
64 		spdk_histogram_data_tally(h, t - tsc[count % 128]);
65 		count++;
66 		if (t > end_tsc) {
67 			break;
68 		}
69 	}
70 
71 	printf("count = %ju\n", count);
72 	spdk_histogram_data_free(h);
73 
74 	spdk_env_fini();
75 	return rc;
76 }
77