Skip to content

Commit ceff5c0

Browse files
hadrielknico
authored andcommitted
Ignore comment lines in log
1 parent c600f2a commit ceff5c0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ninjatracing

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def read_targets(log, show_all):
5555
targets = {}
5656
last_end_seen = 0
5757
for line in log:
58+
if line.startswith('#'):
59+
continue
5860
start, end, _, name, cmdhash = line.strip().split('\t') # Ignore restat.
5961
if not show_all and int(end) < last_end_seen:
6062
# An earlier time stamp means that this step is the first in a new

ninjatracing_test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,25 @@ class TestNinjaTracing(unittest.TestCase):
8686
]
8787
self.assertEqual(expected, dicts)
8888

89+
def test_comments(self):
90+
log = StringIO("# ninja log v5\n"
91+
"#\n"
92+
"100\t200\t0\tmy_output\tdeadbeef\n"
93+
"# 100\t666\t0\tignored_output\tdeadbeef\n"
94+
"50\t120\t0\tmy_first_output\t0afef\n"
95+
"# lastline")
96+
dicts = list(ninjatracing.log_to_dicts(log, 42, {'showall': True}))
97+
expected = [{
98+
'name': 'my_output', 'cat': 'targets', 'ph': 'X',
99+
'ts': 100000, 'dur': 100000, 'pid': 42, 'tid': 0,
100+
'args': {}
101+
}, {
102+
'name': 'my_first_output', 'cat': 'targets', 'ph': 'X',
103+
'ts': 50000, 'dur': 70000, 'pid': 42, 'tid': 1,
104+
'args': {}
105+
},
106+
]
107+
self.assertEqual(expected, dicts)
108+
89109
if __name__ == '__main__':
90110
unittest.main()

0 commit comments

Comments
 (0)