2 * Copyright 2016 - Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
30 #define PRINT_ERR_STREAM ctf_fs->error_fp
31 #define PRINT_PREFIX "ctf-fs"
35 #include "ctf-fs-file.h"
36 #include "ctf-fs-metadata.h"
37 #include "ctf-fs-data-stream.h"
39 bool ctf_fs_debug
= false;
41 static void ctf_fs_destroy(struct ctf_fs
*ctf_fs
)
47 if (ctf_fs
->trace_path
) {
48 g_string_free(ctf_fs
->trace_path
, TRUE
);
51 ctf_fs_metadata_deinit(&ctf_fs
->metadata
);
52 ctf_fs_data_stream_deinit(&ctf_fs
->data_stream
);
56 static struct ctf_fs
*ctf_fs_create(const char *trace_path
)
58 struct ctf_fs
*ctf_fs
= g_new0(struct ctf_fs
, 1);
64 ctf_fs
->trace_path
= g_string_new(trace_path
);
65 if (!ctf_fs
->trace_path
) {
69 ctf_fs
->error_fp
= stderr
;
70 ctf_fs
->page_size
= getpagesize();
72 if (ctf_fs_metadata_init(&ctf_fs
->metadata
)) {
73 PERR("Cannot initialize metadata structure\n");
77 if (ctf_fs_data_stream_init(ctf_fs
, &ctf_fs
->data_stream
)) {
78 PERR("Cannot initialize data stream structure\n");
85 ctf_fs_destroy(ctf_fs
);
92 void ctf_fs_init(void)
94 if (g_strcmp0(getenv("CTF_FS_DEBUG"), "1") == 0) {
99 void ctf_fs_test(const char *trace_path
)
103 struct ctf_fs
*ctf_fs
= ctf_fs_create(trace_path
);
104 struct bt_ctf_notif_iter_notif
*notification
;
110 /* Set trace from metadata file */
111 ctf_fs_metadata_set_trace(ctf_fs
);
112 ctf_fs_data_stream_open_streams(ctf_fs
);
115 int ret
= ctf_fs_data_stream_get_next_notification(ctf_fs
, ¬ification
);
122 switch (notification
->type
) {
123 case BT_CTF_NOTIF_ITER_NOTIF_NEW_PACKET
:
125 struct bt_ctf_notif_iter_notif_new_packet
*notif
=
126 (struct bt_ctf_notif_iter_notif_new_packet
*) notification
;
129 case BT_CTF_NOTIF_ITER_NOTIF_EVENT
:
131 struct bt_ctf_notif_iter_notif_event
*notif
=
132 (struct bt_ctf_notif_iter_notif_event
*) notification
;
135 case BT_CTF_NOTIF_ITER_NOTIF_END_OF_PACKET
:
137 struct bt_ctf_notif_iter_notif_end_of_packet
*notif
=
138 (struct bt_ctf_notif_iter_notif_end_of_packet
*) notification
;
145 bt_ctf_notif_iter_notif_destroy(notification
);
149 ctf_fs_destroy(ctf_fs
);