| 1 |
/* ninja-to-marks.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 "line-reader-private.h" |
| 24 |
|
| 25 |
int |
| 26 |
main (int argc, |
| 27 |
char *argv[]) |
| 28 |
{ |
| 29 |
SysprofCaptureWriter *writer; |
| 30 |
GError *error = NULL; |
| 31 |
gint64 start_time; |
| 32 |
gint64 max_end_time; |
| 33 |
|
| 34 |
sysprof_clock_init (); |
| 35 |
|
| 36 |
if (!(writer = sysprof_capture_writer_new ("ninja.log.syscap", 0))) |
| 37 |
g_error ("Failed to open syscap"); |
| 38 |
|
| 39 |
start_time = max_end_time = g_get_monotonic_time (); |
| 40 |
|
| 41 |
for (int i = 1; i < argc; i++) |
| 42 |
{ |
| 43 |
g_autofree char *contents = NULL; |
| 44 |
LineReader reader; |
| 45 |
char *line; |
| 46 |
gsize len; |
| 47 |
gsize line_len; |
| 48 |
|
| 49 |
if (!g_file_get_contents (argv[i], &contents, &len, &error)) |
| 50 |
{ |
| 51 |
g_printerr ("Error: %s\n", error->message); |
| 52 |
return 1; |
| 53 |
} |
| 54 |
|
| 55 |
line_reader_init (&reader, contents, len); |
| 56 |
while ((line = line_reader_next (&reader, &line_len))) |
| 57 |
{ |
| 58 |
g_auto(GStrv) parts = NULL; |
| 59 |
gint64 begin_time; |
| 60 |
gint64 end_time; |
| 61 |
|
| 62 |
line[line_len] = 0; |
| 63 |
|
| 64 |
if (line[0] == '#') |
| 65 |
continue; |
| 66 |
|
| 67 |
parts = g_strsplit (line, "\t", 5); |
| 68 |
if (g_strv_length (parts) != 5) |
| 69 |
continue; |
| 70 |
|
| 71 |
begin_time = g_ascii_strtoll (parts[0], NULL, 10) * (SYSPROF_NSEC_PER_SEC/1000); |
| 72 |
end_time = g_ascii_strtoll (parts[1], NULL, 10) * (SYSPROF_NSEC_PER_SEC/1000); |
| 73 |
|
| 74 |
if (end_time > max_end_time) |
| 75 |
max_end_time = end_time; |
| 76 |
|
| 77 |
sysprof_capture_writer_add_mark (writer, |
| 78 |
start_time + begin_time, |
| 79 |
-1, |
| 80 |
-1, |
| 81 |
end_time - begin_time, |
| 82 |
"ninja", parts[4], parts[3]); |
| 83 |
|
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
_sysprof_capture_writer_set_time_range (writer, |
| 88 |
start_time, |
| 89 |
start_time + max_end_time); |
| 90 |
|
| 91 |
sysprof_capture_writer_flush (writer); |
| 92 |
sysprof_capture_writer_unref (writer); |
| 93 |
|
| 94 |
return 0; |
| 95 |
} |