aboutsummaryrefslogtreecommitdiff
blob: 0b9306acddddb9da20eabcc78e9d8c93bcc58b10 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import py
from pypy.jit.metainterp.warmspot import ll_meta_interp
from pypy.rlib.jit import JitDriver, DEBUG_PROFILE
from pypy.jit.backend.llgraph import runner
from pypy.jit.metainterp.jitprof import Profiler, JITPROF_LINES
from pypy.jit.tool.jitoutput import parse_prof

def test_really_run():
    """ This test checks whether output of jitprof did not change.
    It'll explode when someone touches jitprof.py
    """
    mydriver = JitDriver(reds = ['i', 'n'], greens = [])
    def f(n):
        i = 0
        while i < n:
            mydriver.can_enter_jit(i=i, n=n)
            mydriver.jit_merge_point(i=i, n=n)
            i += 1

    cap = py.io.StdCaptureFD()
    try:
        ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype',
                       ProfilerClass=Profiler, debug_level=DEBUG_PROFILE)
    finally:
        out, err = cap.reset()
    err = "\n".join(err.splitlines()[-JITPROF_LINES:])
    print err
    assert err.count("\n") == JITPROF_LINES - 1
    info = parse_prof(err)
    # assert did not crash
    # asserts below are a bit delicate, possibly they might be deleted
    assert info.tracing_no == 1
    assert info.asm_no == 1
    assert info.blackhole_no == 1
    assert info.backend_no == 1
    assert info.ops.total == 2
    assert info.ops.calls == 0
    assert info.ops.pure_calls == 0
    assert info.recorded_ops.total == 2
    assert info.recorded_ops.calls == 0
    assert info.recorded_ops.pure_calls == 0
    assert info.guards == 1
    assert info.blackholed_ops.total == 0
    assert info.blackholed_ops.pure_calls == 0
    assert info.opt_ops == 6
    assert info.opt_guards == 1
    assert info.forcings == 0
    assert info.trace_too_long == 0
    assert info.bridge_abort == 0    

DATA = '''Tracing:         1       0.006992
Backend:        1       0.000525
Running asm:            1
Blackhole:              1
TOTAL:                  0.025532
ops:                    2
  calls:                1
  pure calls:           1
recorded ops:           6
  calls:                3
  pure calls:           2
guards:                 1
blackholed ops:         5
  pure calls:           3
opt ops:                6
opt guards:             1
forcings:               1
trace too long:         2
bridge abort:           3
'''

def test_parse():
    info = parse_prof(DATA)
    assert info.tracing_no == 1
    assert info.tracing_time == 0.006992
    assert info.asm_no == 1
    assert info.blackhole_no == 1
    assert info.backend_no == 1
    assert info.backend_time == 0.000525
    assert info.ops.total == 2
    assert info.ops.calls == 1
    assert info.ops.pure_calls == 1
    assert info.recorded_ops.total == 6
    assert info.recorded_ops.calls == 3
    assert info.recorded_ops.pure_calls == 2
    assert info.guards == 1
    assert info.blackholed_ops.total == 5
    assert info.blackholed_ops.pure_calls == 3
    assert info.opt_ops == 6
    assert info.opt_guards == 1
    assert info.forcings == 1
    assert info.trace_too_long == 2
    assert info.bridge_abort == 3