Logo AND Algorithmique Numérique Distribuée

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