SoW-2020-0003: Trace Hit Counters
[lttng-tools.git] / tests / regression / tools / map / test_map_query.c
1 #include <stdio.h>
2 #include <stdint.h>
3
4 #include <lttng/lttng.h>
5 #include <lttng/handle.h>
6 #include <lttng/map.h>
7 #include <lttng/map-query.h>
8
9 int main() {
10 int ret;
11 enum lttng_map_query_status query_status;
12 enum lttng_error_code ret_code;
13 unsigned int map_count, list_count;
14 enum lttng_map_status map_status;
15 struct lttng_map_content *map_content = NULL;
16 struct lttng_map_list *map_list = NULL;
17 const struct lttng_map *map = NULL;
18 struct lttng_domain *domains = NULL;
19 const struct lttng_map_key_value_pair_list *kv_list;
20 const struct lttng_map_key_value_pair *kv_pair;
21 const char *key;
22 int64_t value;
23 int nb_domains;
24
25
26 nb_domains = lttng_list_domains("mysession", &domains);
27
28 struct lttng_handle *handle = lttng_create_handle("mysession", &domains[0]);
29
30 struct lttng_map_query *map_query = lttng_map_query_create(
31 LTTNG_MAP_QUERY_CONFIG_CPU_SUBSET,
32 LTTNG_MAP_QUERY_CONFIG_BUFFER_UST_UID_ALL,
33 LTTNG_MAP_QUERY_CONFIG_APP_BITNESS_ALL);
34
35 if (!map_query) {
36 printf("Error creating the map query\n");
37 ret = -1;
38 goto end;
39 }
40
41 query_status = lttng_map_query_add_cpu(map_query, 0);
42 if (query_status != LTTNG_MAP_QUERY_STATUS_OK) {
43 printf("Error setting the targeted cpu\n");
44 ret = -1;
45 goto end;
46 }
47
48 query_status = lttng_map_query_add_key_filter(map_query,
49 "total number of hits");
50 if (query_status != LTTNG_MAP_QUERY_STATUS_OK) {
51 printf("Error setting the targeted key\n");
52 ret = -1;
53 goto end;
54 }
55
56 ret_code = lttng_list_maps(handle, &map_list);
57 if (ret_code != LTTNG_OK) {
58 printf("Error getting list of all maps\n");
59 ret = -1;
60 goto end;
61 }
62
63 map_status = lttng_map_list_get_count(map_list, &map_count);
64 if (map_status != LTTNG_MAP_STATUS_OK) {
65 printf("Error getting the number of maps\n");
66 ret = -1;
67 goto end;
68 }
69
70 if (map_count < 1) {
71 printf("Error: expecting at least 1 map.\n");
72 ret = -1;
73 goto end;
74 }
75
76 map = lttng_map_list_get_at_index(map_list, 0);
77 if (!map) {
78 printf("Error getting map at index 0\n");
79 ret = -1;
80 goto end;
81 }
82
83 ret_code = lttng_list_map_content(handle, map, map_query, &map_content);
84 if (ret_code != LTTNG_OK) {
85 printf("Error executing the query on map\n");
86 ret = -1;
87 goto end;
88 }
89
90 map_status = lttng_map_content_get_count(map_content, &list_count);
91 if (map_status != LTTNG_MAP_STATUS_OK) {
92 printf("Error getting the number of key value pair list\n");
93 ret = -1;
94 goto end;
95 }
96
97 if (list_count < 1) {
98 printf("Error: expecting at least 1 list.\n");
99 ret = -1;
100 goto end;
101 }
102
103 kv_list = lttng_map_content_get_at_index(map_content, 0);
104 if (!kv_list) {
105 printf("Error getting key value pair list at index 0\n");
106 ret = -1;
107 goto end;
108 }
109
110 kv_pair = lttng_map_key_value_pair_list_get_at_index(kv_list, 0);
111 if (!kv_pair) {
112 printf("Error getting key value pair at index 0\n");
113 ret = -1;
114 goto end;
115 }
116
117 lttng_map_key_value_pair_get_key(kv_pair, &key);
118 lttng_map_key_value_pair_get_value(kv_pair, &value);
119
120 printf("Key: \"%s\", value: %"PRId64"\n", key, value);
121
122 ret = 0;
123 end:
124 return ret;
125 }
This page took 0.032212 seconds and 5 git commands to generate.