-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics.html
181 lines (178 loc) · 14.9 KB
/
Statistics.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Firm - Statistics</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="stylesheet" type="text/css" href="pygments.css"/>
<link rel="icon" type="image/png" href="logo-simple.png"/>
</head>
<body>
<div class="layout-header">
<a href="index.html"><img src="logo.png" alt="Firm Logo" /></a>
</div>
<div class="layout-content-wrapper">
<div class="layout-content">
<div class="layout-sidebar">
<ul>
<li><a href="index.html">About</a></li>
<li><a href="Features.html">Features</a></li>
<li><a href="Download.html">Download</a></li>
<li><a href="Documentation.html">Documentation</a></li>
<li><a href="Projects.html">Projects</a></li>
<li><a href="Development.html">Development</a></li>
<li><a href="Contact.html">Contact</a></li>
</ul>
<ul class="external">
<li><a href="http://pp.info.uni-karlsruhe.de/projects/firm_publications.php">Publications</a></li>
</ul>
<div class="layout-toc">
<h2>Contents</h2>
<ul>
<li><a href="#_introduction">Introduction</a></li>
<li><a href="#_events_amp_contexts">Events & Contexts</a></li>
<li><a href="#_change_your_code_to_produce_events">Change your code to produce events</a></li>
<li><a href="#_activating_events_in_the_firm_library_compiler">Activating events in the firm library/compiler</a></li>
<li><a href="#_generating_events_manually">Generating Events Manually</a></li>
<li><a href="#_analysing_event_traces">Analysing event traces</a></li>
<li><a href="#_producing_nice_looking_latex_graphics">Producing nice looking latex Graphics</a></li>
</ul>
</div>
</div>
<div class="layout-document">
<h1>Statistics</h1>
<div class="sect1">
<h2 id="_introduction">Introduction</h2>
<div class="sectionbody">
<div class="paragraph"><p>Collecting compilation statistics like the number of instructions, basic blocks, load or store instruction, the time spent in each phase, etc. are important information for development and analysis of the compiler.
Gathering fine grained statistics, can result in a huge amount of data.
lib<span class="algo"><span class="algo">Firm</span></span> features a sophisticated statistics system which simplifies storage, retrieval and analysis of such data.
(Actually firm has several statistic systems, the recommended approach, which is described here, is using <em>ir/stat/statev.*</em>)</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_events_amp_contexts">Events & Contexts</h2>
<div class="sectionbody">
<div class="paragraph"><p>The basis of the statistics are statistic-events.
A <em>statistic-event</em> is a pair of an event name and a double value.
A compiler can throw a statistic event at any time in the compilation process.
Typical examples for an event are the number of instructions modified during a phase, or a time measurement of some algorithmic step.</p></div>
<div class="paragraph"><p>Events have to be put into some context to be useful.
You want to know which file and which function was compiled, or which compiler flags were used.
Contexts can often be thought of in an hierarchical manner:
On the upper level you have data like compiler flags or the file that is compiled.
Going down the hierarchy you find things like the function currently being compiled or the register class getting assigned some registers.
Because of this hierarchic nature contexts in this system are organized as a stack.</p></div>
<div class="paragraph"><p>To keep track of the context, a series of <em>context-push</em> and <em>context-pop</em> events is generated by the compiler.
A typical context is bemain_irg which represents the currently processed graph in the backend, or the refinement bechordal_cls which specifies the current register class during register allocation.</p></div>
<div class="paragraph"><p>A sequence of normal events, context-push and context-pop events form a <em>statistic trace</em>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_change_your_code_to_produce_events">Change your code to produce events</h2>
<div class="sectionbody">
<div class="paragraph"><p>Events can be generated by calling <code>stat_ev_dbl()</code>:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="n">stat_ev_dbl</span><span class="p">(</span><span class="s">"mymodule_event"</span><span class="p">,</span><span class="w"> </span><span class="n">event_value</span><span class="p">);</span>
</pre></div></div></div>
<div class="paragraph"><p>Contexts can be pushed and popped like this:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="n">stat_ev_ctx_push_str</span><span class="p">(</span><span class="s">"mymodule_context"</span><span class="p">,</span><span class="w"> </span><span class="n">context_value</span><span class="p">);</span>
<span class="cm">/* put normal events here */</span>
<span class="n">stat_ev_ctx_pop</span><span class="p">(</span><span class="s">"mymodule_context"</span><span class="p">);</span>
</pre></div></div></div>
<div class="paragraph"><p>It is good style to add a prefix to the event and context names which describes the module which contains the calls.
This makes it easier to filter out events from modules, we’re not interested in.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_activating_events_in_the_firm_library_compiler">Activating events in the firm library/compiler</h2>
<div class="sectionbody">
<div class="paragraph"><p>Events can be activated with the --statev cparser switch.
The compiler will then generate a file ending in .ev which contains the event trace.</p></div>
<div class="paragraph"><p>For bigger programs like the SPEC it is recommended (and necessary because of the huge amount of data) to restrict the event trace to events from some modules only.
This is done with the --filtev switch which accept a string.
Only events (which includes context-pushs and -pops) contain the filtev string will be written to the log.
A simple invocation looks like this:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span>$<span class="w"> </span>cparser<span class="w"> </span>--statev<span class="w"> </span>somefile.c
</pre></div></div></div>
</div>
</div>
<div class="sect1">
<h2 id="_generating_events_manually">Generating Events Manually</h2>
<div class="sectionbody">
<div class="paragraph"><p>We also successfully used the statev system from scripts in which case you have to produce the event stream manually.
Anyway this is quite easy. You have to generate an asciss file with the following conventions:</p></div>
<div class="literalblock">
<div class="content">
<pre><code> # Push context named CTX with value VAL
P;CTX;VAL
# Pop named CTX
O;CTX
# Record event named EV with value VAL
E;EV;VAL</code></pre>
</div></div>
</div>
</div>
<div class="sect1">
<h2 id="_analysing_event_traces">Analysing event traces</h2>
<div class="sectionbody">
<div class="paragraph"><p>You can generate summaries and statistics by processing the event traces.
lib<span class="algo"><span class="algo">Firm</span></span> comes with a script which preprocesses the events and puts them into a sqlite (or mysql) database.
Example usage:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span>$<span class="w"> </span>statev_sql.py<span class="w"> </span>-v<span class="w"> </span>-D<span class="w"> </span>results.db<span class="w"> </span>somefile.ev<span class="w"> </span>someotherfile.ev<span class="w"> </span>...
</pre></div></div></div>
<div class="paragraph"><p>This creates a file results.db containing an sqlite database with a table for contexts and events.
You can then write SQL-queries to gather data.
Example sqlite invocation</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span>$<span class="w"> </span>sqlite3<span class="w"> </span>results.db
</pre></div></div></div>
<div class="paragraph"><p>Some example queries:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="o">#</span><span class="w"> </span><span class="n">Display</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="nb">number</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">blocks</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">instructions</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="k">each</span><span class="w"> </span><span class="k">function</span><span class="p">:</span>
<span class="k">SELECT</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">bemain_irg</span><span class="p">,</span><span class="w"> </span><span class="k">sum</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">bemain_blocks_start</span><span class="p">),</span><span class="w"> </span><span class="k">sum</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">bemain_insns_start</span><span class="p">)</span>
<span class="k">FROM</span><span class="w"> </span><span class="n">ctx</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="k">c</span><span class="p">,</span><span class="w"> </span><span class="n">ev</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">e</span>
<span class="k">WHERE</span><span class="w"> </span><span class="n">e</span><span class="p">.</span><span class="n">id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">id</span>
<span class="k">GROUP</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">bemain_irg</span>
</pre></div></div></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="o">#</span><span class="w"> </span><span class="n">Display</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">maximal</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">average</span><span class="w"> </span><span class="n">register</span><span class="w"> </span><span class="n">pressure</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">ia32_gp</span><span class="w"> </span><span class="n">register</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="n">grouped</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">filename</span>
<span class="k">SELECT</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">bemain_compilation_unit</span><span class="p">,</span><span class="w"> </span><span class="k">max</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">bechordal_maximum_register_pressure</span><span class="p">),</span><span class="w"> </span><span class="k">avg</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">bechordal_average_register_pressure</span><span class="p">)</span>
<span class="k">FROM</span><span class="w"> </span><span class="n">ctx</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="k">c</span><span class="p">,</span><span class="w"> </span><span class="n">ev</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">e</span>
<span class="k">WHERE</span><span class="w"> </span><span class="n">e</span><span class="p">.</span><span class="n">id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">id</span><span class="w"> </span><span class="k">AND</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">bechordal_cls</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'ia32_gp'</span>
<span class="k">GROUP</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="k">c</span><span class="p">.</span><span class="n">bemain_compilation_unit</span>
</pre></div></div></div>
</div>
</div>
<div class="sect1">
<h2 id="_producing_nice_looking_latex_graphics">Producing nice looking latex Graphics</h2>
<div class="sectionbody">
<div class="paragraph"><p>You can use the data in scripts to produce tables and tikz pictures for your LaTeX documents.</p></div>
<div class="imageblock">
<div class="content">
<img src="images/Tableexample.png" alt="images/Tableexample.png" />
</div>
</div>
<div class="imageblock">
<div class="content">
<img src="images/Plotexample.png" alt="images/Plotexample.png" />
</div>
</div>
<div class="paragraph"><p>I have added some of my scripts into the firm svn repository as examples:
<a class="external text" href="http://github.com/MatzeB/libfirm/tree/master/scripts/statev_examples">1</a></p></div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="layout-footer">
<span><a href="https://lists.ira.uni-karlsruhe.de/mailman/listinfo/firm">Mailing list</a>: <a href="mailto:[email protected]">[email protected]</a></span>
</div>
</body>
</html>