Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / doc / tracing.doc
1 /*! \page tracing Tracing Simulations for Visualization
2
3 \htmlinclude .tracing.doc.toc
4
5 \section tracing_tracing Tracing Simulations for Visualization
6
7 The trace visualization is widely used to observe and understand the behavior
8 of parallel applications and distributed algorithms. Usually, this is done in a
9 two-step fashion: the user instruments the application and the traces are
10 analyzed after the end of the execution. The visualization itself can highlights
11 unexpected behaviors, bottlenecks and sometimes can be used to correct
12 distributed algorithms. The SimGrid team has instrumented the library
13 in order to let users trace their simulations and analyze them. This part of the
14 user manual explains how the tracing-related features can be enabled and used
15 during the development of simulators using the SimGrid library.
16
17 \subsection tracing_tracing_howitworks How it works
18
19 For now, the SimGrid library is instrumented so users can trace the <b>platform
20 utilization</b> using the MSG, SimDAG and SMPI interface. This means that the tracing will
21 register how much power is used for each host and how much bandwidth is used for
22 each link of the platform. The idea with this type of tracing is to observe the
23 overall view of resources utilization in the first place, especially the
24 identification of bottlenecks, load-balancing among hosts, and so on.
25
26 The idea of the tracing facilities is to give SimGrid users to possibility to
27 classify MSG and SimDAG tasks by category, tracing the platform utilization
28 (hosts and links) for each of the categories. For that,
29 the tracing interface enables the declaration of categories and a function to
30 mark a task with a previously declared category. <em>The tasks that are not
31 classified according to a category are not traced</em>. Even if the user
32 does not specify any category, the simulations can still be traced in terms
33 of resource utilization by using a special parameter that is detailed below.
34
35 \subsection tracing_tracing_enabling Enabling using CMake
36
37 With the sources of SimGrid, it is possible to enable the tracing
38 using the parameter <b>-Denable_tracing=ON</b> when the cmake is
39 executed.  The sections \ref instr_category_functions, \ref
40 instr_mark_functions, and \ref instr_uservariables_functions describe
41 all the functions available when this Cmake options is
42 activated. These functions will have no effect if SimGrid is
43 configured without this option (they are wiped-out by the
44 C-preprocessor).
45
46 \verbatim
47 $ cmake -Denable_tracing=ON .
48 $ make
49 \endverbatim
50
51 \subsection instr_category_functions Tracing categories functions
52 \li \c TRACE_category(const char *category)
53 \li \c TRACE_category_with_color(const char *category, const char *color)
54 \li \c MSG_task_set_category(m_task_t task, const char *category)
55 \li \c MSG_task_get_category(m_task_t task)
56 \li \c SD_task_set_category(SD_task_t task, const char *category)
57 \li \c SD_task_get_category(SD_task_t task)
58
59 \subsection instr_mark_functions Tracing marks functions
60 \li \c TRACE_declare_mark(const char *mark_type)
61 \li \c TRACE_mark(const char *mark_type, const char *mark_value)
62
63 \subsection instr_uservariables_functions Tracing user variables functions
64
65 For hosts:
66
67 \li \c TRACE_host_variable_declare(const char *variable)
68 \li \c TRACE_host_variable_declare_with_color(const char *variable, const char *color)
69 \li \c TRACE_host_variable_set(const char *host, const char *variable, double value)
70 \li \c TRACE_host_variable_add(const char *host, const char *variable, double value)
71 \li \c TRACE_host_variable_sub(const char *host, const char *variable, double value)
72 \li \c TRACE_host_variable_set_with_time(double time, const char *host, const char *variable, double value)
73 \li \c TRACE_host_variable_add_with_time(double time, const char *host, const char *variable, double value)
74 \li \c TRACE_host_variable_sub_with_time(double time, const char *host, const char *variable, double value)
75
76 For links:
77
78 \li \c TRACE_link_variable_declare(const char *variable)
79 \li \c TRACE_link_variable_declare_with_color(const char *variable, const char *color)
80 \li \c TRACE_link_variable_set(const char *link, const char *variable, double value)
81 \li \c TRACE_link_variable_add(const char *link, const char *variable, double value)
82 \li \c TRACE_link_variable_sub(const char *link, const char *variable, double value)
83 \li \c TRACE_link_variable_set_with_time(double time, const char *link, const char *variable, double value)
84 \li \c TRACE_link_variable_add_with_time(double time, const char *link, const char *variable, double value)
85 \li \c TRACE_link_variable_sub_with_time(double time, const char *link, const char *variable, double value)
86
87 For links, but use source and destination to get route:
88
89 \li \c TRACE_link_srcdst_variable_set(const char *src, const char *dst, const char *variable, double value)
90 \li \c TRACE_link_srcdst_variable_add(const char *src, const char *dst, const char *variable, double value)
91 \li \c TRACE_link_srcdst_variable_sub(const char *src, const char *dst, const char *variable, double value)
92 \li \c TRACE_link_srcdst_variable_set_with_time(double time, const char *src, const char *dst, const char *variable, double value)
93 \li \c TRACE_link_srcdst_variable_add_with_time(double time, const char *src, const char *dst, const char *variable, double value)
94 \li \c TRACE_link_srcdst_variable_sub_with_time(double time, const char *src, const char *dst, const char *variable, double value)
95
96 \subsection tracing_tracing_options Tracing configuration Options
97
98 To check which tracing options are available for your simulator, you
99 can just run it with the option <b>--help-tracing</b>. These are the
100 options accepted by the tracing system of SimGrid as of today, you
101 can use them by running your simulator with the <b>--cfg=</b> switch:
102
103 \li <b>\c 
104 tracing
105 </b>:
106   Safe switch. It activates (or deactivates) the tracing system.
107   No other tracing options take effect if this one is not activated.
108 \verbatim
109 --cfg=tracing:1
110 \endverbatim
111
112 \li <b>\c 
113 tracing/categorized
114 </b>:
115   It activates the categorized resource utilization tracing. It should
116   be enabled if tracing categories are used by this simulator.
117 \verbatim
118 --cfg=tracing/categorized:1
119 \endverbatim
120
121 \li <b>\c 
122 tracing/uncategorized
123 </b>:
124   It activates the uncategorized resource utilization tracing. Use it if
125   this simulator do not use tracing categories and resource use have to be
126   traced.
127 \verbatim
128 --cfg=tracing/uncategorized:1
129 \endverbatim
130
131 \li <b>\c 
132 tracing/filename
133 </b>:
134   A file with this name will be created to register the simulation. The file
135   is in the Paje format and can be analyzed using Triva or Paje visualization
136   tools. More information can be found in these webpages:
137      <a href="http://triva.gforge.inria.fr/">http://triva.gforge.inria.fr/</a>
138      <a href="http://paje.sourceforge.net/">http://paje.sourceforge.net/</a>
139 \verbatim
140 --cfg=tracing/filename:mytracefile.trace
141 \endverbatim
142   If you do not provide this parameter, the trace file will be named simgrid.trace.
143
144 \li <b>\c
145 tracing/onelink_only
146 </b>:
147   By default, the tracing system uses all routes in the platform file
148   to re-create a "graph" of the platform and register it in the trace file.
149   This option let the user tell the tracing system to use only the routes
150   that are composed with just one link.
151 \verbatim
152 --cfg=tracing/onelink_only:1
153 \endverbatim
154
155 \li <b>\c 
156 tracing/smpi
157 </b>:
158   This option only has effect if this simulator is SMPI-based. Traces the MPI
159   interface and generates a trace that can be analyzed using Gantt-like
160   visualizations. Every MPI function (implemented by SMPI) is transformed in a
161   state, and point-to-point communications can be analyzed with arrows.
162 \verbatim
163 --cfg=tracing/smpi:1
164 \endverbatim
165
166 \li <b>\c 
167 tracing/smpi/group
168 </b>:
169   This option only has effect if this simulator is SMPI-based. The processes
170   are grouped by the hosts where they were executed.
171 \verbatim
172 --cfg=tracing/smpi/group:1
173 \endverbatim
174
175 \li <b>\c 
176 tracing/msg/process
177 </b>:
178   This option only has effect if this simulator is MSG-based. It traces the
179   behavior of all categorized MSG processes, grouping them by hosts. This option
180   can be used to track process location if this simulator has process migration.
181 \verbatim
182 --cfg=tracing/msg/process:1
183 \endverbatim
184
185 \li <b>\c
186 tracing/buffer
187 </b>:
188  This option put some events in a time-ordered buffer using the
189  insertion sort algorithm. The process of acquiring and releasing
190  locks to access this buffer and the cost of the sorting algorithm
191  make this process slow. The simulator performance can be severely
192  impacted if this option is activated, but you are sure to get a trace
193  file with events sorted.
194 \verbatim
195 --cfg=tracing/buffer:1
196 \endverbatim
197
198 \li <b>\c
199 tracing/onelink_only
200 </b>:
201 This option changes the way SimGrid register its platform on the trace
202 file. Normally, the tracing considers all routes (no matter their
203 size) on the platform file to re-create the resource topology. If this
204 option is activated, only the routes with one link are used to
205 register the topology within an AS.  Routes among AS continue to be
206 traced as usual.
207 \verbatim
208 --cfg=tracing/onelink_only:1
209 \endverbatim
210
211 \li <b>\c
212 tracing/disable_destroy
213 </b>:
214 Disable the destruction of containers at the end of simulation. This
215 can be used with simulators that have a different notion of time
216 (different from the simulated time).
217 \verbatim
218 --cfg=tracing/disable_destroy:1
219 \endverbatim
220
221 \li <b>\c 
222 triva/categorized
223 </b>:
224   This option generates a graph configuration file for Triva considering
225   categorized resource utilization.
226 \verbatim
227 --cfg=triva/categorized:graph_categorized.plist
228 \endverbatim
229
230 \li <b>\c 
231 triva/uncategorized
232 </b>:
233   This option generates a graph configuration file for Triva considering
234   uncategorized resource utilization.
235 \verbatim
236 --cfg=triva/uncategorized:graph_uncategorized.plist
237 \endverbatim
238
239 \subsection tracing_tracing_example_parameters Case studies
240
241 Some scenarios that might help you decide which tracing options
242 you should use to analyze your simulator.
243
244 \li I want to trace the resource utilization of all hosts
245 and links of the platform, and my simulator <b>does not</b> use
246 the tracing API. For that, you can run a uncategorized trace
247 with the following parameters (it will work with <b>any</b> Simgrid
248 simulator):
249 \verbatim
250 ./your_simulator \
251           --cfg=tracing:1 \
252           --cfg=tracing/uncategorized:1 \
253           --cfg=tracing/filename:mytracefile.trace \
254           --cfg=triva/uncategorized:uncat.plist
255 \endverbatim
256
257 \li I want to trace only a subset of my MSG (or SimDAG) tasks.
258 For that, you will need to create tracing categories using the
259 <b>TRACE_category (...)</b> function (as explained above),
260 and then classify your tasks to a previously declared category
261 using the <b>MSG_task_set_category (...)</b>
262 (or <b>SD_task_set_category (...)</b> for SimDAG tasks). After
263 recompiling, run your simulator with the following parameters:
264 \verbatim
265 ./your_simulator \
266           --cfg=tracing:1 \
267           --cfg=tracing/categorized:1 \
268           --cfg=tracing/filename:mytracefile.trace \
269           --cfg=triva/categorized:cat.plist
270 \endverbatim
271
272
273 \subsection tracing_tracing_example Example of Instrumentation
274
275 A simplified example using the tracing mandatory functions.
276
277 \verbatim
278 int main (int argc, char **argv)
279 {
280   MSG_global_init (&argc, &argv);
281
282   //(... after deployment ...)
283
284   //note that category declaration must be called after MSG_create_environment
285   TRACE_category_with_color ("request", "1 0 0");
286   TRACE_category_with_color ("computation", "0.3 1 0.4");
287   TRACE_category ("finalize");
288
289   m_task_t req1 = MSG_task_create("1st_request_task", 10, 10, NULL);
290   m_task_t req2 = MSG_task_create("2nd_request_task", 10, 10, NULL);
291   m_task_t req3 = MSG_task_create("3rd_request_task", 10, 10, NULL);
292   m_task_t req4 = MSG_task_create("4th_request_task", 10, 10, NULL);
293   MSG_task_set_category (req1, "request");
294   MSG_task_set_category (req2, "request");
295   MSG_task_set_category (req3, "request");
296   MSG_task_set_category (req4, "request");
297
298   m_task_t comp = MSG_task_create ("comp_task", 100, 100, NULL);
299   MSG_task_set_category (comp, "computation");
300
301   m_task_t finalize = MSG_task_create ("finalize", 0, 0, NULL);
302   MSG_task_set_category (finalize, "finalize");
303
304   //(...)
305
306   MSG_clean();
307   return 0;
308 }
309 \endverbatim
310
311 \subsection tracing_tracing_analyzing Analyzing the SimGrid Traces
312
313 The SimGrid library, during an instrumented simulation, creates a trace file in
314 the Paje file format that contains the platform utilization for the simulation
315 that was executed. The visualization analysis of this file is performed with the
316 visualization tool <a href="http://triva.gforge.inria.fr">Triva</a>, with
317 special configurations tunned to SimGrid needs. This part of the documentation
318 explains how to configure and use Triva to analyse a SimGrid trace file.
319
320 - <b>Installing Triva</b>: the tool is available in the Inria's Forge, 
321 at <a href="http://triva.gforge.inria.fr">http://triva.gforge.inria.fr</a>.
322 Use the following command to get the sources, and then check the file
323 <i>INSTALL</i>. This file contains instructions to install
324 the tool's dependencies in a Ubuntu/Debian Linux. The tool can also
325 be compiled in MacOSX natively, check <i>INSTALL.mac</i> file.
326 \verbatim
327 $ git clone git://scm.gforge.inria.fr/triva/triva.git
328 $ cd triva
329 $ cat INSTALL
330 \endverbatim
331
332 - <b>Executing Triva</b>: a binary called <i>Triva</i> is available after the
333   installation (you can execute it passing <em>--help</em> to check its
334 options). If the triva binary is not available after following the
335 installation instructions, you may want to execute the following command to
336 initialize the GNUstep environment variables. We strongly recommend that you
337 use the latest GNUstep packages, and not the packages available through apt-get
338 in Ubuntu/Debian packaging systems. If you install GNUstep using the latest
339 available packages, you can execute this command:
340 \verbatim
341 $ source /usr/GNUstep/System/Library/Makefiles/GNUstep.sh
342 \endverbatim
343 You should be able to see this output after the installation of triva:
344 \verbatim
345 $ ./Triva.app/Triva --help
346 Usage: Triva [OPTIONS...] TRACE0 [TRACE1]
347 Trace Analysis through Visualization
348
349 TimeInterval
350     --ti_frequency {double}    Animation: frequency of updates
351     --ti_hide                  Hide the TimeInterval window
352     --ti_forward {double}      Animation: value to move time-slice
353     --ti_apply                 Apply the configuration
354     --ti_update                Update on slider change
355     --ti_animate               Start animation
356     --ti_start {double}        Start of time slice
357     --ti_size {double}         Size of time slice
358 Triva
359     --comparison               Compare Trace Files (Experimental)
360     --graph                    Configurable Graph
361     --list                     Print Trace Type Hierarchy
362     --hierarchy                Export Trace Type Hierarchy (dot)
363     --stat                     Trace Statistics and Memory Utilization
364     --instances                List All Trace Entities
365     --linkview                 Link View (Experimental)
366     --treemap                  Squarified Treemap
367     --merge                    Merge Trace Files (Experimental)
368     --check                    Check Trace File Integrity
369 GraphConfiguration
370     --gc_conf {file}           Graph Configuration in Property List Format
371     --gc_apply                 Apply the configuration
372     --gc_hide                  Hide the GraphConfiguration window
373 \endverbatim
374 Triva expects that the user choose one of the available options 
375 (currently <em>--graph</em> or <em>--treemap</em> for a visualization analysis)
376 and the trace file from the simulation.
377
378 - <b>Understanding Triva - time-slice</b>: the analysis of a trace file using
379   the tool always takes into account the concept of the <em>time-slice</em>.
380 This concept means that what is being visualized in the screen is always
381 calculated considering a specific time frame, with its beggining and end
382 timestamp. The time-slice is configured by the user and can be changed
383 dynamically through the window called <em>Time Interval</em> that is opened
384 whenever a trace file is being analyzed. The next figure depicts the time-slice
385 configuration window.
386 In the top of the window, in the space named <i>Trace Time</i>,
387 the two fields show the beggining of the trace (which usually starts in 0) and
388 the end (that depends on the time simulated by SimGrid). The middle of the
389 window, in the square named <i>Time Slice Configuration</i>, contains the
390 aspects related to the time-slice, including its <i>start</i> and its
391 <i>size</i>. The gray rectangle in the bottom of this part indicates the 
392 <i>current time-slice</i> that is considered for the drawings. If the checkbox 
393 <i>Update Drawings on Sliders Change</i> is not selected, the button
394 <i>Apply</i> must be clicked in order to inform triva that the
395 new time-slice must be considered. The bottom part of the window, in the space
396 indicated by the square <i>Time Slice Animation</i> can be used to advance
397 the time-frame automatically. The user configures the amount of time that the
398 time-frame will forward and how frequent this update will happen. Once this is
399 configured, the user clicks the <i>Play</i> button in order to see the dynamic
400 changes on the drawings.
401 <center>
402 \htmlonly
403 <a href="triva-time_interval.png" border=0><img src="triva-time_interval.png" width="50%" border=0></a>
404 \endhtmlonly
405 </center>
406 <b>Remarks:</b> when the trace has too many hosts or links, the computation to
407 take into account a new time-slice can be expensive. When this happens, the
408 <i>Frequency</i> parameter, but also updates caused by change on configurations
409 when the checkbox <i>Update Drawings on Sliders
410 Change</i> is selected will not be followed.
411
412 - <b>Understanding Triva - graph</b>: one possibility to analyze
413   SimGrid traces is to use Triva's graph view, using the
414   <em>--graph</em> parameter to activate this view, and
415   <em>--gc_conf</em> with a graph configuration to customize the graph
416   according to the traces. A valid graph configuration (we are using
417   the non-XML <a
418   href="http://en.wikipedia.org/wiki/Property_list">Property List
419   Format</a> to describe the configuration) can be created for any
420   SimGrid-based simulator using the
421   <em>--cfg=triva/uncategorized:graph_uncategorized.plist</em> or
422   <em>--cfg=triva/categorized:graph_categorized.plist</em> (if the
423   simulator defines resource utilization categories) when executing
424   the simulation.
425
426 <b>Basic SimGrid Configuration</b>: The basic description of the configuration
427 is as follows:
428 \verbatim
429 {
430   node = (LINK, HOST, );
431   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
432 \endverbatim
433
434 The nodes of the graph will be created based on the <i>node</i>
435 parameter, which in this case is the different <em>"HOST"</em>s and
436 <em>"LINK"</em>s of the platform used to simulate. The <i>edge</i>
437 parameter indicates that the edges of the graph will be created based
438 on the <em>"HOST-LINK"</em>s, <em>"LINK-HOST"</em>s, and
439 <em>"LINK-LINK"</em>s of the platform.  After the definition of these
440 two parameters, the configuration must detail how the nodes
441 (<em>HOST</em>s and <em>LINK</em>s) should be drawn.
442
443 For that, the configuration must have an entry for each of
444 the types used. For <em>HOST</em>, as basic configuration, we have:
445
446 \verbatim
447   HOST = {
448     type = square;
449     size = power;
450     values = (power_used);
451   };
452 \endverbatim
453
454 The parameter <em>size</em> indicates which variable from the trace
455 file will be used to define the size of the node HOST in the
456 visualization. If the simulation was executed with availability
457 traces, the size of the nodes will be changed according to these
458 traces. The parameter <em>type</em> indicates which geometrical shape
459 will be used to represent HOST, and the <em>values</em> parameter
460 indicates which values from the trace will be used to fill the shape.
461
462 For <em>LINK</em> we have:
463
464 \verbatim 
465   LINK = {
466     type = rhombus;
467     size = bandwidth;
468     values = (bandwidth_used);
469   };
470 }
471 \endverbatim
472
473 The same configuration parameters are used here: <em>type</em> (with a
474 rhombus), the <em>size</em> (whose value is from trace's bandwidth
475 variable) and the <em>values</em>.
476
477 <b>Customizing the Graph Representation</b>: triva is capable to handle
478 a customized graph representation based on the variables present in the trace
479 file. In the case of SimGrid, every time a category is created for tasks, two
480 variables in the trace file are defined: one to indicate node utilization (how
481 much power was used by that task category), and another to indicate link
482 utilization (how much bandwidth was used by that category). For instance, if the
483 user declares a category named <i>request</i>, there will be variables named
484 <b>p</b><i>request</i> and a <b>b</b><i>request</i> (<b>p</b> for power and
485 <b>b</b> for bandwidth). It is important to notice that the variable
486 <i>prequest</i> in this case is only available for HOST, and
487 <i>brequest</i> is only available for LINK. <b>Example</b>: suppose there are
488 two categories for tasks: request and compute. To create a customized graph
489 representation with a proportional separation of host and link utilization, use
490 as configuration for HOST and LINK this:
491
492 \verbatim
493   HOST = {
494     type = square;
495     size = power;
496     values = (prequest, pcomputation);
497   };
498   LINK = {
499     type = rhombus;
500     size = bandwidth;
501     values = (brequest, bcomputation);
502   };
503 \endverbatim
504
505 This configuration enables the analysis of resource utilization by MSG tasks,
506 and the identification of load-balancing issues, network bottlenecks, for
507 instance. \n
508
509 <b>The Graph Visualization</b>: The next figure shows a graph visualization of a
510 given time-slice of the masterslave_forwarder example (present in the SimGrid
511 sources). The red color indicates tasks from the <i>compute</i> category. This
512 visualization was generated with the following configuration:
513
514 \verbatim
515 {
516   node = (LINK, HOST, );
517   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
518
519   host = {
520     type = square;
521     size = power;
522     values = (pcompute, pfinalize);
523   };
524   link = {
525     type = rhombus;
526     size = bandwidth;
527     values = (bcompute, bfinalize);
528   };
529 }
530 \endverbatim
531
532 <center>
533 \htmlonly
534 <a href="triva-graph_visualization.png" border=0><img src="triva-graph_visualization.png" width="50%" border=0></a>
535 \endhtmlonly
536 </center>
537
538 - <b>Understading Triva - colors</b>: Colors are now registered in
539 trace files. See the tracing API to how to define them for your
540 simulator.
541
542 */