Logo AND Algorithmique Numérique Distribuée

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