[go: up one dir, main page]

File: p005_srcline.py

package info (click to toggle)
uftrace 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,356 kB
  • sloc: ansic: 49,770; python: 11,181; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (36 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3

import re

from runtest import PyTestBase

class TestCase(PyTestBase):
    def __init__(self):
        PyTestBase.__init__(self, 'abc', """
# DURATION     TID     FUNCTION
            [ 28141] | __main__.<module>() { /* /home/namhyung/project/uftrace/tests/s-abc.py:1 */
            [ 28141] |   a() { /* /home/namhyung/project/uftrace/tests/s-abc.py:4 */
            [ 28141] |     b() { /* /home/namhyung/project/uftrace/tests/s-abc.py:7 */
            [ 28141] |       c() { /* /home/namhyung/project/uftrace/tests/s-abc.py:10 */
   0.753 us [ 28141] |         posix.getpid();
   1.430 us [ 28141] |       } /* c */
   1.915 us [ 28141] |     } /* b */
   2.405 us [ 28141] |   } /* a */
   3.005 us [ 28141] | } /* __main__.<module> */
""")

    def setup(self):
        self.option = '--srcline'

    def sort(self, output, ignored=True):
        result = []
        for ln in output.split('\n'):
            # ignore blank lines and comments
            if ln.strip() == '' or ln.startswith('#'):
                continue
            line = ln.split('|', 1)[-1]
            # remove directory path and check the basename only
            func = re.sub(r'{ .*/s-abc.py:', '{ /* s-abc.py:', line)
            result.append(func)

        return '\n'.join(result)