Commit | Line | Data |
---|---|---|
e98a2d6e PP |
1 | /* |
2 | * Copyright 2016 - Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
23 | #include <stdio.h> | |
24 | #include <stdbool.h> | |
25 | #include <assert.h> | |
26 | #include <stdlib.h> | |
27 | #include <unistd.h> | |
28 | #include <glib.h> | |
29 | ||
30 | #define PRINT_ERR_STREAM ctf_fs->error_fp | |
31 | #define PRINT_PREFIX "ctf-fs" | |
32 | #include "print.h" | |
33 | ||
34 | #include "ctf-fs.h" | |
35 | #include "ctf-fs-file.h" | |
36 | #include "ctf-fs-metadata.h" | |
37 | #include "ctf-fs-data-stream.h" | |
38 | ||
39 | bool ctf_fs_debug = false; | |
40 | ||
41 | static void ctf_fs_destroy(struct ctf_fs *ctf_fs) | |
42 | { | |
43 | if (!ctf_fs) { | |
44 | return; | |
45 | } | |
46 | ||
47 | if (ctf_fs->trace_path) { | |
48 | g_string_free(ctf_fs->trace_path, TRUE); | |
49 | } | |
50 | ||
51 | ctf_fs_metadata_deinit(&ctf_fs->metadata); | |
52 | ctf_fs_data_stream_deinit(&ctf_fs->data_stream); | |
53 | g_free(ctf_fs); | |
54 | } | |
55 | ||
56 | static struct ctf_fs *ctf_fs_create(const char *trace_path) | |
57 | { | |
58 | struct ctf_fs *ctf_fs = g_new0(struct ctf_fs, 1); | |
59 | ||
60 | if (!ctf_fs) { | |
61 | goto error; | |
62 | } | |
63 | ||
64 | ctf_fs->trace_path = g_string_new(trace_path); | |
65 | if (!ctf_fs->trace_path) { | |
66 | goto error; | |
67 | } | |
68 | ||
69 | ctf_fs->error_fp = stderr; | |
70 | ctf_fs->page_size = getpagesize(); | |
71 | ||
72 | if (ctf_fs_metadata_init(&ctf_fs->metadata)) { | |
73 | PERR("Cannot initialize metadata structure\n"); | |
74 | goto error; | |
75 | } | |
76 | ||
77 | if (ctf_fs_data_stream_init(ctf_fs, &ctf_fs->data_stream)) { | |
78 | PERR("Cannot initialize data stream structure\n"); | |
79 | goto error; | |
80 | } | |
81 | ||
82 | goto end; | |
83 | ||
84 | error: | |
85 | ctf_fs_destroy(ctf_fs); | |
86 | ctf_fs = NULL; | |
87 | ||
88 | end: | |
89 | return ctf_fs; | |
90 | } | |
91 | ||
92 | void ctf_fs_init(void) | |
93 | { | |
94 | if (g_strcmp0(getenv("CTF_FS_DEBUG"), "1") == 0) { | |
95 | ctf_fs_debug = true; | |
96 | } | |
97 | } | |
98 | ||
99 | void ctf_fs_test(const char *trace_path) | |
100 | { | |
101 | ctf_fs_init(); | |
102 | ||
103 | struct ctf_fs *ctf_fs = ctf_fs_create(trace_path); | |
104 | struct bt_ctf_notif_iter_notif *notification; | |
105 | ||
106 | if (!ctf_fs) { | |
107 | return; | |
108 | } | |
109 | ||
110 | /* Set trace from metadata file */ | |
111 | ctf_fs_metadata_set_trace(ctf_fs); | |
112 | ctf_fs_data_stream_open_streams(ctf_fs); | |
113 | ||
114 | while (true) { | |
115 | int ret = ctf_fs_data_stream_get_next_notification(ctf_fs, ¬ification); | |
116 | assert(ret == 0); | |
117 | ||
118 | if (!notification) { | |
119 | goto end; | |
120 | } | |
121 | ||
122 | switch (notification->type) { | |
123 | case BT_CTF_NOTIF_ITER_NOTIF_NEW_PACKET: | |
124 | { | |
125 | struct bt_ctf_notif_iter_notif_new_packet *notif = | |
126 | (struct bt_ctf_notif_iter_notif_new_packet *) notification; | |
127 | break; | |
128 | } | |
129 | case BT_CTF_NOTIF_ITER_NOTIF_EVENT: | |
130 | { | |
131 | struct bt_ctf_notif_iter_notif_event *notif = | |
132 | (struct bt_ctf_notif_iter_notif_event *) notification; | |
133 | break; | |
134 | } | |
135 | case BT_CTF_NOTIF_ITER_NOTIF_END_OF_PACKET: | |
136 | { | |
137 | struct bt_ctf_notif_iter_notif_end_of_packet *notif = | |
138 | (struct bt_ctf_notif_iter_notif_end_of_packet *) notification; | |
139 | break; | |
140 | } | |
141 | default: | |
142 | break; | |
143 | } | |
144 | ||
145 | bt_ctf_notif_iter_notif_destroy(notification); | |
146 | } | |
147 | ||
148 | end: | |
149 | ctf_fs_destroy(ctf_fs); | |
150 | } |