Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
eacff0e2e9a709f29091272637f886d4abe5827b
[simgrid.git] / doc / doxygen / tracing.doc
1 /*! \page tracing Tracing Simulations
2
3
4 Tracing is widely used to observe and understand the behavior of
5 parallel applications and distributed algorithms. Usually, this is
6 done in a two-step fashion: the user instruments the application and
7 the traces are analyzed after the end of the execution. The analysis
8 can highlights unexpected behaviors, bottlenecks and sometimes can be
9 used to correct distributed algorithms. The SimGrid team has
10 instrumented the library in order to let users trace their simulations
11 and analyze them. This part of the user manual explains how the
12 tracing-related features can be enabled and used during the
13 development of simulators using the SimGrid library.
14
15 \section tracing_tracing_enabling Enabling using CMake
16
17 With the sources of SimGrid, it is possible to enable the tracing
18 using the parameter <b>-Denable_tracing=ON</b> when the cmake is
19 executed.  The sections \ref instr_category_functions, \ref
20 instr_mark_functions, and \ref instr_uservariables_functions describe
21 all the functions available when this Cmake options is
22 activated. These functions will have no effect if SimGrid is
23 configured without this option (they are wiped-out by the
24 C-preprocessor).
25
26 \verbatim
27 $ cmake -Denable_tracing=ON .
28 $ make
29 \endverbatim
30
31 \section instr_category_functions Tracing categories functions
32
33 The SimGrid library is instrumented so users can trace the platform
34 utilization using MSG, SimDAG and SMPI interfaces. It registers how
35 much power is used for each host and how much bandwidth is used for
36 each link of the platform. The idea with this type of tracing is to
37 observe the overall view of resources utilization in the first place,
38 especially the identification of bottlenecks, load-balancing among
39 hosts, and so on.
40
41 Another possibility is to trace resource utilization by
42 categories. Categorized resource utilization tracing gives SimGrid
43 users to possibility to classify MSG and SimDAG tasks by category,
44 tracing resource utilization for each of the categories. The functions
45 below let the user declare a category and apply it to tasks. <em>The
46 tasks that are not classified according to a category are not
47 traced</em>. Even if the user does not specify any category, the
48 simulations can still be traced in terms of resource utilization by
49 using a special parameter that is detailed below (see section \ref
50 tracing_tracing_options).
51
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(msg_task_t task, const char *category)
55 \li \c MSG_task_get_category(msg_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 \section 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 \section 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 \section 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 \verbatim --help-tracing \endverbatim
100 to get a very detailed and updated explanation of each tracing
101 parameter. These are some of the options accepted by the tracing
102 system of SimGrid, you can use them by running your simulator with the
103 <b>--cfg=</b> switch:
104
105 \li <b>\c
106 tracing
107 </b>:
108   Safe switch. It activates (or deactivates) the tracing system.
109   No other tracing options take effect if this one is not activated.
110 \verbatim
111 --cfg=tracing:yes
112 \endverbatim
113
114 \li <b>\c
115 tracing/categorized
116 </b>:
117   It activates the categorized resource utilization tracing. It should
118   be enabled if tracing categories are used by this simulator.
119 \verbatim
120 --cfg=tracing/categorized:yes
121 \endverbatim
122
123 \li <b>\c
124 tracing/uncategorized
125 </b>:
126   It activates the uncategorized resource utilization tracing. Use it if
127   this simulator do not use tracing categories and resource use have to be
128   traced.
129 \verbatim
130 --cfg=tracing/uncategorized:yes
131 \endverbatim
132
133 \li <b>\c
134 tracing/filename
135 </b>:
136   A file with this name will be created to register the simulation. The file
137   is in the Paje format and can be analyzed using Viva or Paje visualization
138   tools. More information can be found in these webpages:
139      <a href="http://github.com/schnorr/viva/">http://github.com/schnorr/viva/</a>
140      <a href="http://github.com/schnorr/pajeng/">http://github.com/schnorr/pajeng/</a>
141 \verbatim
142 --cfg=tracing/filename:mytracefile.trace
143 \endverbatim
144   If you do not provide this parameter, the trace file will be named simgrid.trace.
145
146 \li <b>\c
147 tracing/smpi
148 </b>:
149   This option only has effect if this simulator is SMPI-based. Traces the MPI
150   interface and generates a trace that can be analyzed using Gantt-like
151   visualizations. Every MPI function (implemented by SMPI) is transformed in a
152   state, and point-to-point communications can be analyzed with arrows.
153 \verbatim
154 --cfg=tracing/smpi:yes
155 \endverbatim
156
157 \li <b>\c
158 tracing/smpi/group
159 </b>:
160   This option only has effect if this simulator is SMPI-based. The processes
161   are grouped by the hosts where they were executed.
162 \verbatim
163 --cfg=tracing/smpi/group:yes
164 \endverbatim
165
166 \li <b>\c
167 tracing/smpi/computing
168 </b>:
169   This option only has effect if this simulator is SMPI-based. The parts external
170 to SMPI are also outputted to the trace. Provides better way to analyze the data automatically.
171 \verbatim
172 --cfg=tracing/smpi/computing:yes
173 \endverbatim
174
175 \li <b>\c
176 tracing/smpi/internals
177 </b>:
178   This option only has effect if this simulator is SMPI-based. Display internal communications
179 happening during a collective MPI call.
180 \verbatim
181 --cfg=tracing/smpi/internals:yes
182 \endverbatim
183
184 \li <b>\c
185 tracing/smpi/display_sizes
186 </b>:
187   This option only has effect if this simulator is SMPI-based. Display the sizes of the messages
188 exchanged in the trace, both in the links and on the states. For collective, size means the global size of data sent by the process in general.
189 \verbatim
190 --cfg=tracing/smpi/display_sizes:yes
191 \endverbatim
192
193 \li <b>\c
194 tracing/msg/process
195 </b>:
196   This option only has effect if this simulator is MSG-based. It traces the
197   behavior of all categorized MSG processes, grouping them by hosts. This option
198   can be used to track process location if this simulator has process migration.
199 \verbatim
200 --cfg=tracing/msg/process:yes
201 \endverbatim
202
203 \li <b>\c
204 tracing/buffer
205 </b>:
206  This option put some events in a time-ordered buffer using the
207  insertion sort algorithm. The process of acquiring and releasing
208  locks to access this buffer and the cost of the sorting algorithm
209  make this process slow. The simulator performance can be severely
210  impacted if this option is activated, but you are sure to get a trace
211  file with events sorted.
212 \verbatim
213 --cfg=tracing/buffer:yes
214 \endverbatim
215
216 \li <b>\c
217 tracing/onelink_only
218 </b>:
219 This option changes the way SimGrid register its platform on the trace
220 file. Normally, the tracing considers all routes (no matter their
221 size) on the platform file to re-create the resource topology. If this
222 option is activated, only the routes with one link are used to
223 register the topology within an AS.  Routes among AS continue to be
224 traced as usual.
225 \verbatim
226 --cfg=tracing/onelink_only:yes
227 \endverbatim
228
229 \li <b>\c
230 tracing/disable_destroy
231 </b>:
232 Disable the destruction of containers at the end of simulation. This
233 can be used with simulators that have a different notion of time
234 (different from the simulated time).
235 \verbatim
236 --cfg=tracing/disable_destroy:yes
237 \endverbatim
238
239 \li <b>\c
240 tracing/basic
241 </b>:
242 Some visualization tools are not able to parse correctly the Paje file format.
243 Use this option if you are using one of these tools to visualize the simulation
244 trace. Keep in mind that the trace might be incomplete, without all the
245 information that would be registered otherwise.
246 \verbatim
247 --cfg=tracing/basic:yes
248 \endverbatim
249
250 \li <b>\c
251 tracing/comment
252 </b>:
253 Use this to add a comment line to the top of the trace file.
254 \verbatim
255 --cfg=tracing/comment:my_string
256 \endverbatim
257
258 \li <b>\c
259 tracing/comment_file
260 </b>:
261 Use this to add the contents of a file to the top of the trace file as comment.
262 \verbatim
263 --cfg=tracing/comment_file:textual_file.txt
264 \endverbatim
265
266 \li <b>\c
267 viva/categorized
268 </b>:
269   This option generates a graph configuration file for Viva considering
270   categorized resource utilization.
271 \verbatim
272 --cfg=viva/categorized:graph_categorized.plist
273 \endverbatim
274
275 \li <b>\c
276 viva/uncategorized
277 </b>:
278   This option generates a graph configuration file for Viva considering
279   uncategorized resource utilization.
280 \verbatim
281 --cfg=viva/uncategorized:graph_uncategorized.plist
282 \endverbatim
283
284 Please pass \verbatim --help-tracing \endverbatim to your simulator
285 for the updated list of tracing options.
286
287 \section tracing_tracing_example_parameters Case studies
288
289 Some scenarios that might help you decide which tracing options
290 you should use to analyze your simulator.
291
292 \li I want to trace the resource utilization of all hosts
293 and links of the platform, and my simulator <b>does not</b> use
294 the tracing API. For that, you can run a uncategorized trace
295 with the following parameters (it will work with <b>any</b> Simgrid
296 simulator):
297 \verbatim
298 ./your_simulator \
299           --cfg=tracing:yes \
300           --cfg=tracing/uncategorized:yes \
301           --cfg=tracing/filename:mytracefile.trace \
302           --cfg=viva/uncategorized:uncat.plist
303 \endverbatim
304
305 \li I want to trace only a subset of my MSG (or SimDAG) tasks.
306 For that, you will need to create tracing categories using the
307 <b>TRACE_category (...)</b> function (as explained above),
308 and then classify your tasks to a previously declared category
309 using the <b>MSG_task_set_category (...)</b>
310 (or <b>SD_task_set_category (...)</b> for SimDAG tasks). After
311 recompiling, run your simulator with the following parameters:
312 \verbatim
313 ./your_simulator \
314           --cfg=tracing:yes \
315           --cfg=tracing/categorized:yes \
316           --cfg=tracing/filename:mytracefile.trace \
317           --cfg=viva/categorized:cat.plist
318 \endverbatim
319
320
321 \section tracing_tracing_example Example of Instrumentation
322
323 A simplified example using the tracing mandatory functions.
324
325 \verbatim
326 int main (int argc, char **argv)
327 {
328   MSG_init (&argc, &argv);
329
330   //(... after deployment ...)
331
332   //note that category declaration must be called after MSG_create_environment
333   TRACE_category_with_color ("request", "1 0 0");
334   TRACE_category_with_color ("computation", "0.3 1 0.4");
335   TRACE_category ("finalize");
336
337   msg_task_t req1 = MSG_task_create("1st_request_task", 10, 10, NULL);
338   msg_task_t req2 = MSG_task_create("2nd_request_task", 10, 10, NULL);
339   msg_task_t req3 = MSG_task_create("3rd_request_task", 10, 10, NULL);
340   msg_task_t req4 = MSG_task_create("4th_request_task", 10, 10, NULL);
341   MSG_task_set_category (req1, "request");
342   MSG_task_set_category (req2, "request");
343   MSG_task_set_category (req3, "request");
344   MSG_task_set_category (req4, "request");
345
346   msg_task_t comp = MSG_task_create ("comp_task", 100, 100, NULL);
347   MSG_task_set_category (comp, "computation");
348
349   msg_task_t finalize = MSG_task_create ("finalize", 0, 0, NULL);
350   MSG_task_set_category (finalize, "finalize");
351
352   //(...)
353
354   MSG_clean();
355   return 0;
356 }
357 \endverbatim
358
359 \section tracing_tracing_analyzing Analyzing SimGrid Simulation Traces
360
361 A SimGrid-based simulator, when executed with the correct parameters
362 (see above) creates a trace file in the Paje file format holding the
363 simulated behavior of the application or the platform. You have
364 several options to analyze this trace file:
365
366 - Dump its contents to a CSV-like format using `pj_dump` (see <a
367   href="https://github.com/schnorr/pajeng/wiki/pj_dump">PajeNG's wiki
368   on pj_dump</a> and more generally the <a
369   href="https://github.com/schnorr/pajeng/">PajeNG suite</a>) and use
370   gnuplot to plot resource usage, time spent on blocking/executing
371   functions, and so on. Filtering capabilities are at your hand by
372   doing `grep`, with the best regular expression you can provide, to
373   get only parts of the trace (for instance, only a subset of
374   resources or processes).
375
376 - Derive statistics from trace metrics (the ones built-in with any
377   SimGrid simulation, but also those metrics you injected in the trace
378   using the TRACE module) using the <a
379   href="http://www.r-project.org/">R project</a> and all its
380   modules. You can also combine R with <a
381   href="http://ggplot2.org/">ggplot2</a> to get a number of high
382   quality plots from your simulation metrics. You need to `pj_dump`
383   the contents of the SimGrid trace file to use R.
384
385 - Visualize the behavior of your simulation using classic space/time
386   views (gantt-charts) provided by the <a
387   href="https://github.com/schnorr/pajeng/">PajeNG suite</a> and any
388   other tool that supports the <a
389   href="http://paje.sourceforge.net/download/publication/lang-paje.pdf">Paje
390   file format</a>. Consider this option if you need to understand the
391   causality of your distributed simulation.
392
393 - Visualize the behavior of your simulation with treemaps (specially
394   if your simulation has a platform with several thousand resources),
395   provided by the <a href="http://github.com/schnorr/viva/">Viva</a>
396   visualization tool. See <a
397   href="https://github.com/schnorr/viva/wiki">Viva's wiki</a> for
398   further details on what is a treemap and how to use it.
399
400 - Correlate the behavior of your simulator with the platform topology
401   with an interactive, force-directed, and hierarchical graph
402   visualization, provided by <a
403   href="http://github.com/schnorr/viva/">Viva</a>.  Check <a
404   href="https://github.com/schnorr/viva/wiki">Viva's wiki</a> for
405   further details. This <a
406   href="http://hal.inria.fr/hal-00738321/">research report</a>,
407   published at ISPASS 2013, has a detailed description of this
408   visualization technique.
409
410 - You can also check our online <a
411   href="http://simgrid.gforge.inria.fr/tutorials.html"> tutorial
412   section</a> that contains a dedicated tutorial with several
413   suggestions on how to use the tracing infrastructure. Look for the
414   SimGrid User::Visualization 101 tutorial.
415
416 - Ask for help on the <a
417   href="mailto:simgrid-user@lists.gforge.inria.fr">simgrid-user@lists.gforge.inria.fr</a>
418   mailing list, giving us a detailed explanation on what your
419   simulator does and what kind of information you want to trace. You
420   can also check the <a
421   href="http://lists.gforge.inria.fr/pipermail/simgrid-user/">mailing
422   list archive</a> for old messages regarding tracing and analysis.
423
424 \subsection tracing_viva_analysis Viva Visualization Tool
425
426 This subsection describe some of the concepts regarding the <a
427 href="http://github.com/schnorr/viva/">Viva Visualization Tool</a> and
428 its relation with SimGrid traces. You should refer to Viva's website
429 for further details on all its visualization techniques.
430
431 \subsubsection tracing_viva_time_slice Time Slice
432
433 The analysis of a trace file using the tool always takes into account
434 the concept of the <em>time-slice</em>.  This concept means that what
435 is being visualized in the screen is always calculated considering a
436 specific time frame, with its beggining and end timestamp. The
437 time-slice is configured by the user and can be changed dynamically
438 through the window called <em>Time Interval</em> that is opened
439 whenever a trace file is being analyzed. Users are capable to select
440 the beggining and size of the time slice.
441
442 \subsubsection tracing_viva_graph Hierarchical Graph View
443
444 %As stated above (see section \ref tracing_tracing_analyzing), one
445 possibility to analyze SimGrid traces is to use Viva's graph view with
446 a graph configuration to customize the graph according to the
447 traces. A valid graph configuration (we are using the non-XML <a
448 href="http://en.wikipedia.org/wiki/Property_list">Property List
449 Format</a> to describe the configuration) can be created for any
450 SimGrid-based simulator using the
451 <em>--cfg=viva/uncategorized:graph_uncategorized.plist</em> or
452 <em>--cfg=viva/categorized:graph_categorized.plist</em> (if the
453 simulator defines resource utilization categories) when executing the
454 simulation.
455
456 \subsubsection basic_conf Basic Graph Configuration
457
458 The basic description of the configuration is as follows:
459 \verbatim
460 {
461   node = (LINK, HOST, );
462   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
463 \endverbatim
464
465 The nodes of the graph will be created based on the <i>node</i>
466 parameter, which in this case is the different <em>"HOST"</em>s and
467 <em>"LINK"</em>s of the platform used to simulate. The <i>edge</i>
468 parameter indicates that the edges of the graph will be created based
469 on the <em>"HOST-LINK"</em>s, <em>"LINK-HOST"</em>s, and
470 <em>"LINK-LINK"</em>s of the platform.  After the definition of these
471 two parameters, the configuration must detail how the nodes
472 (<em>HOST</em>s and <em>LINK</em>s) should be drawn.
473
474 For that, the configuration must have an entry for each of
475 the types used. For <em>HOST</em>, as basic configuration, we have:
476
477 \verbatim
478   HOST = {
479     type = square;
480     size = power;
481     values = (power_used);
482   };
483 \endverbatim
484
485 The parameter <em>size</em> indicates which variable from the trace
486 file will be used to define the size of the node HOST in the
487 visualization. If the simulation was executed with availability
488 traces, the size of the nodes will be changed according to these
489 traces. The parameter <em>type</em> indicates which geometrical shape
490 will be used to represent HOST, and the <em>values</em> parameter
491 indicates which values from the trace will be used to fill the shape.
492
493 For <em>LINK</em> we have:
494
495 \verbatim
496   LINK = {
497     type = rhombus;
498     size = bandwidth;
499     values = (bandwidth_used);
500   };
501 }
502 \endverbatim
503
504 The same configuration parameters are used here: <em>type</em> (with a
505 rhombus), the <em>size</em> (whose value is from trace's bandwidth
506 variable) and the <em>values</em>.
507
508 \subsubsection custom_graph Customizing the Graph Representation
509
510 Viva is capable to handle a customized graph representation based on
511 the variables present in the trace file. In the case of SimGrid, every
512 time a category is created for tasks, two variables in the trace file
513 are defined: one to indicate node utilization (how much power was used
514 by that task category), and another to indicate link utilization (how
515 much bandwidth was used by that category). For instance, if the user
516 declares a category named <i>request</i>, there will be variables
517 named <b>p</b><i>request</i> and a <b>b</b><i>request</i> (<b>p</b>
518 for power and <b>b</b> for bandwidth). It is important to notice that
519 the variable <i>prequest</i> in this case is only available for HOST,
520 and <i>brequest</i> is only available for LINK. <b>Example</b>:
521 suppose there are two categories for tasks: request and compute. To
522 create a customized graph representation with a proportional
523 separation of host and link utilization, use as configuration for HOST
524 and LINK this:
525
526 \verbatim
527   HOST = {
528     type = square;
529     size = power;
530     values = (prequest, pcomputation);
531   };
532   LINK = {
533     type = rhombus;
534     size = bandwidth;
535     values = (brequest, bcomputation);
536   };
537 \endverbatim
538
539 This configuration enables the analysis of resource utilization by MSG
540 tasks through the identification of load-balancing issues and network
541 bottlenecks, for instance.
542
543 */