| 1 | from pypy.tool.memusage import log2gnumeric |
| 2 | |
| 3 | log = """ |
| 4 | [1000] ... |
| 5 | [2000] {gc-collect |
| 6 | |
| 7 | .----------- Full collection ------------------ |
| 8 | | used before collection: |
| 9 | | in ArenaCollection: 500 bytes |
| 10 | | raw_malloced: 100 bytes |
| 11 | | used after collection: |
| 12 | | in ArenaCollection: 300 bytes |
| 13 | | raw_malloced: 50 bytes |
| 14 | | number of major collects: 1 |
| 15 | `---------------------------------------------- |
| 16 | [3000] gc-collect} |
| 17 | [4000] {gc-collect |
| 18 | |
| 19 | .----------- Full collection ------------------ |
| 20 | | used before collection: |
| 21 | | in ArenaCollection: 600 bytes |
| 22 | | raw_malloced: 200 bytes |
| 23 | | used after collection: |
| 24 | | in ArenaCollection: 400 bytes |
| 25 | | raw_malloced: 100 bytes |
| 26 | | number of major collects: 1 |
| 27 | `---------------------------------------------- |
| 28 | [5000] gc-collect} |
| 29 | ... |
| 30 | ... |
| 31 | [6000] {translation-task |
| 32 | starting annotate |
| 33 | ... |
| 34 | ... |
| 35 | [7000] translation-task} |
| 36 | [8000] {translation-task |
| 37 | starting rtype_lltype |
| 38 | ... |
| 39 | ... |
| 40 | [9000] translation-task} |
| 41 | ... |
| 42 | [a000] ... |
| 43 | """ |
| 44 | |
| 45 | log = log.replace('\n', '') |
| 46 | |
| 47 | def test_get_clock_range(): |
| 48 | minclock, maxclock = log2gnumeric.get_clock_range(log) |
| 49 | assert minclock == 0x1000 |
| 50 | assert maxclock == 0xa000 |
| 51 | |
| 52 | |
| 53 | def test_gc_collect_rows(): |
| 54 | rows = list(log2gnumeric.gc_collect_rows(0x1000, log)) |
| 55 | assert len(rows) == 3 |
| 56 | assert rows[0] == ( 'clock', 'gc-before', 'gc-after') |
| 57 | assert rows[1] == (0x3000-0x1000, 500+100, 300+ 50) |
| 58 | assert rows[2] == (0x5000-0x1000, 600+200, 400+100) |
| 59 | |
| 60 | def test_tasks_rows(): |
| 61 | rows = list(log2gnumeric.tasks_rows(0x1000, log)) |
| 62 | assert len(rows) == 3 |
| 63 | assert rows[0] == ( 'clock', None, 'task') |
| 64 | assert rows[1] == (0x6000-0x1000, 1, 'annotate') |
| 65 | assert rows[2] == (0x8000-0x1000, 1, 'rtype_lltype') |
| 66 | |
| 67 | |
| 68 | def test_vmrss_rows(): |
| 69 | lines = ['100', '200', '300'] |
| 70 | rows = list(log2gnumeric.vmrss_rows_impl(lines, 2000)) |
| 71 | assert len(rows) == 4 |
| 72 | assert rows[0] == ('inferred clock', 'VmRSS') |
| 73 | assert rows[1] == (0, 100) |
| 74 | assert rows[2] == (1000, 200) |
| 75 | assert rows[3] == (2000, 300) |
| 76 | |
| 77 | def test_loops_rows(): |
| 78 | log = """\ |
| 79 | [1000] {jit-mem-looptoken-alloc |
| 80 | allocating Loop # 0 |
| 81 | [1001] jit-mem-looptoken-alloc} |
| 82 | [2000] {jit-mem-looptoken-alloc |
| 83 | allocating Loop # 1 |
| 84 | [2001] jit-mem-looptoken-alloc} |
| 85 | [3000] {jit-mem-looptoken-alloc |
| 86 | allocating Bridge # 1 of Loop # 0 |
| 87 | [3001] jit-mem-looptoken-alloc} |
| 88 | [4000] {jit-mem-looptoken-free |
| 89 | freeing Loop # 0 with 1 attached bridges |
| 90 | [4001] |
| 91 | """ |
| 92 | log = log.replace('\n', '') |
| 93 | rows = list(log2gnumeric.loops_rows(0x1000, log)) |
| 94 | assert len(rows) == 5 |
| 95 | assert rows[0] == ('clock', 'total', 'loops', 'bridges') |
| 96 | assert rows[1] == ( 0x0, 1, 1, 0) |
| 97 | assert rows[2] == ( 0x1000, 2, 2, 0) |
| 98 | assert rows[3] == ( 0x2000, 3, 2, 1) |
| 99 | assert rows[4] == ( 0x3000, 1, 1, 0) |