| 1 | = Introduction = |
| 2 | |
| 3 | Callgrind's output format is very general because it's targeted by a number of different tools. This page describes Callgrind's output format as it pertains to PIR-level profiling for Parrot. |
| 4 | |
| 5 | = Terms = |
| 6 | |
| 7 | * '''Process under test''' - This is the process of the program being profiled, i.e. a PIR program of some sort. |
| 8 | * '''Profile''' - This refers to the output file containing profiling information for the process under test. |
| 9 | |
| 10 | = Format Description = |
| 11 | |
| 12 | The format consists of a header and a body. The header consists of several key value pairs which describe the purpose of the profile. KCachegrind ignores lines it doesn't know about. In the example below, this feature is used to add comments to an example profile. See the bottom of this page for information about how this example was generated. |
| 13 | |
| 14 | == Example == |
| 15 | |
| 16 | === Example C Code === |
| 17 | The following C code was used to generate a (nearly) trivial profile: |
| 18 | {{{ |
| 19 | #!c |
| 20 | #include <stdio.h> |
| 21 | #include <valgrind/callgrind.h> |
| 22 | |
| 23 | void func1(); |
| 24 | void func2(); |
| 25 | void func3(); |
| 26 | |
| 27 | int main() { |
| 28 | CALLGRIND_START_INSTRUMENTATION; |
| 29 | func1(); |
| 30 | func2(); |
| 31 | func3(); |
| 32 | CALLGRIND_STOP_INSTRUMENTATION; |
| 33 | } |
| 34 | |
| 35 | void func1() { |
| 36 | int i; |
| 37 | for (i = 0; i < 1000000; i++); |
| 38 | } |
| 39 | |
| 40 | void func2() { |
| 41 | int i; |
| 42 | for (i = 0; i < 1000000; i++); |
| 43 | func1(); |
| 44 | } |
| 45 | |
| 46 | void func3() { |
| 47 | int i; |
| 48 | for (i = 0; i < 1000000; i++); |
| 49 | func2(); |
| 50 | func1(); |
| 51 | } |
| 52 | }}} |
| 53 | |
| 54 | The program was compiled and profiled as follows: |
| 55 | {{{ |
| 56 | gcc callgrind_test.c -g -o callgrind_test |
| 57 | valgrind --tool=callgrind --compress-strings=no --compress-pos=no --instr-atstart=no ./callgrind_test |
| 58 | }}} |
| 59 | |
| 60 | === Annotated Header from the Profile of above C Code === |
| 61 | |
| 62 | The above valgrind invocation produced a profile in callgrind.out.PID, where PID is the process ID of the process under test. Below is the header of the profile, annotated with a description of the purpose of each line. |
| 63 | |
| 64 | {{{ |
| 65 | #!sh |
| 66 | # version of the Callgrind format |
| 67 | version: 1 |
| 68 | |
| 69 | # what created this profile, informational only |
| 70 | creator: 3.4.1-Debian |
| 71 | |
| 72 | # PID of the process under test |
| 73 | pid: 5751 |
| 74 | |
| 75 | # the full CLI invocation that started the process under test |
| 76 | cmd: ./callgrind_test |
| 77 | |
| 78 | # used when multiple dumps are produced, starts from 1 and increments |
| 79 | part: 1 |
| 80 | |
| 81 | # parameters used for the cache simulator; not relevant for function profiling |
| 82 | desc: I1 cache: |
| 83 | desc: D1 cache: |
| 84 | desc: L2 cache: |
| 85 | |
| 86 | # not really sure |
| 87 | desc: Timerange: Basic block 0 - 7000029 |
| 88 | |
| 89 | # Why did the process under test stop? (informational only) |
| 90 | desc: Trigger: Program termination |
| 91 | |
| 92 | # (optional) what do positions mean? |
| 93 | # "line" - (default) positions are line numbers in a file |
| 94 | # "instr" - positions are offsets in a binary representing instructions |
| 95 | positions: line |
| 96 | |
| 97 | # (required) event types logged by this file |
| 98 | # "Ir" - instruction read access |
| 99 | # "I1mr" - instruction L1 read cache miss |
| 100 | # "I2mr" - instruction L2 read cache miss |
| 101 | events: Ir |
| 102 | |
| 103 | # (recommended) the total number of events covered by this profile |
| 104 | # This is intended to allow postprocessing tools to know the total cost in advance. |
| 105 | # "totals" appears at the end of the file and has the same value. |
| 106 | summary: 21000073 |
| 107 | }}} |
| 108 | |
| 109 | === Annotated Body from the Profile of above C Code === |
| 110 | |
| 111 | This space for rent. |