Debian Codegraph @

src/libsysprof/tests/test-print-file.c

raw
1 /* test-print-file.c
2 *
3 * Copyright 2023 Christian Hergert <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include <sysprof.h>
22
23 #include "sysprof-document-private.h"
24
25 int
26 main (int argc,
27 char *argv[])
28 {
29 g_autoptr(SysprofDocumentLoader) loader = NULL;
30 g_autoptr(SysprofDocumentFile) file = NULL;
31 g_autoptr(SysprofDocument) document = NULL;
32 g_autoptr(GListModel) files = NULL;
33 g_autoptr(GError) error = NULL;
34 g_autoptr(GBytes) bytes = NULL;
35
36 if (argc < 3)
37 {
38 g_printerr ("usage: %s CAPTURE_FILE EMBEDDED_FILE_PATH\n", argv[0]);
39 return 1;
40 }
41
42 loader = sysprof_document_loader_new (argv[1]);
43 sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ());
44
45 if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
46 {
47 g_printerr ("Failed to open capture: %s\n", error->message);
48 return 1;
49 }
50
51 file = sysprof_document_lookup_file (document, argv[2]);
52
53 if (file == NULL)
54 {
55 g_printerr ("File \"%s\" not found.\n", argv[2]);
56 return 1;
57 }
58
59 bytes = sysprof_document_file_dup_bytes (file);
60
61 write (STDOUT_FILENO,
62 g_bytes_get_data (bytes, NULL),
63 g_bytes_get_size (bytes));
64
65 return 0;
66 }