xref: /spdk/module/bdev/ocf/stats.c (revision 307b8c112ffd90a26d53dd15fad67bd9038ef526)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (c) Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "ctx.h"
7 #include "stats.h"
8 
9 int
10 vbdev_ocf_stats_get(ocf_cache_t cache, char *core_name, struct vbdev_ocf_stats *stats)
11 {
12 	int status;
13 	ocf_core_t core;
14 
15 	status = ocf_core_get_by_name(cache, core_name, strlen(core_name), &core);
16 	if (status) {
17 		return status;
18 	}
19 
20 	return ocf_stats_collect_core(core, &stats->usage, &stats->reqs, &stats->blocks, &stats->errors);
21 }
22 
23 #define WJSON_STAT(w, stats, group, field, units) \
24 	spdk_json_write_named_object_begin(w, #field); \
25 	spdk_json_write_named_uint64(w, "count", stats->group.field.value); \
26 	spdk_json_write_named_string_fmt(w, "percentage", "%lu.%lu", \
27 		stats->group.field.fraction / 100, stats->group.field.fraction % 100); \
28 	spdk_json_write_named_string(w, "units", units); \
29 	spdk_json_write_object_end(w);
30 
31 void
32 vbdev_ocf_stats_write_json(struct spdk_json_write_ctx *w, struct vbdev_ocf_stats *stats)
33 {
34 	spdk_json_write_object_begin(w);
35 
36 	spdk_json_write_named_object_begin(w, "usage");
37 	WJSON_STAT(w, stats, usage, occupancy, "4KiB blocks");
38 	WJSON_STAT(w, stats, usage, free, "4KiB blocks");
39 	WJSON_STAT(w, stats, usage, clean, "4KiB blocks");
40 	WJSON_STAT(w, stats, usage, dirty, "4KiB blocks");
41 	spdk_json_write_object_end(w);
42 
43 	spdk_json_write_named_object_begin(w, "requests");
44 	WJSON_STAT(w, stats, reqs, rd_hits, "Requests");
45 	WJSON_STAT(w, stats, reqs, rd_partial_misses, "Requests");
46 	WJSON_STAT(w, stats, reqs, rd_full_misses, "Requests");
47 	WJSON_STAT(w, stats, reqs, rd_total, "Requests");
48 	WJSON_STAT(w, stats, reqs, wr_hits, "Requests");
49 	WJSON_STAT(w, stats, reqs, wr_partial_misses, "Requests");
50 	WJSON_STAT(w, stats, reqs, wr_full_misses, "Requests");
51 	WJSON_STAT(w, stats, reqs, wr_total, "Requests");
52 	WJSON_STAT(w, stats, reqs, rd_pt, "Requests");
53 	WJSON_STAT(w, stats, reqs, wr_pt, "Requests");
54 	WJSON_STAT(w, stats, reqs, serviced, "Requests");
55 	WJSON_STAT(w, stats, reqs, total, "Requests");
56 	spdk_json_write_object_end(w);
57 
58 	spdk_json_write_named_object_begin(w, "blocks");
59 	WJSON_STAT(w, stats, blocks, core_volume_rd, "4KiB blocks");
60 	WJSON_STAT(w, stats, blocks, core_volume_wr, "4KiB blocks");
61 	WJSON_STAT(w, stats, blocks, core_volume_total, "4KiB blocks");
62 	WJSON_STAT(w, stats, blocks, cache_volume_rd, "4KiB blocks");
63 	WJSON_STAT(w, stats, blocks, cache_volume_wr, "4KiB blocks");
64 	WJSON_STAT(w, stats, blocks, cache_volume_total, "4KiB blocks");
65 	WJSON_STAT(w, stats, blocks, volume_rd, "4KiB blocks");
66 	WJSON_STAT(w, stats, blocks, volume_wr, "4KiB blocks");
67 	WJSON_STAT(w, stats, blocks, volume_total, "4KiB blocks");
68 	spdk_json_write_object_end(w);
69 
70 	spdk_json_write_named_object_begin(w, "errors");
71 	WJSON_STAT(w, stats, errors, core_volume_rd, "Requests");
72 	WJSON_STAT(w, stats, errors, core_volume_wr, "Requests");
73 	WJSON_STAT(w, stats, errors, core_volume_total, "Requests");
74 	WJSON_STAT(w, stats, errors, cache_volume_rd, "Requests");
75 	WJSON_STAT(w, stats, errors, cache_volume_wr, "Requests");
76 	WJSON_STAT(w, stats, errors, cache_volume_total, "Requests");
77 	WJSON_STAT(w, stats, errors, total, "Requests");
78 	spdk_json_write_object_end(w);
79 
80 	spdk_json_write_object_end(w);
81 }
82