1 /* Copyright (c) 2010, 2012-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /** @addtogroup MSG_examples
9 * @section msg_ex_tracing_user_variables Tracing user variables
10 * The tracing mechanism of SimGrid also allows to associate user variables to resources described in the platform file.
11 * The following examples illustrate this feature. They have to be run with the <i>--cfg=tracing:yes</i> and
12 * <i>--cfg=tracing/platform:yes</i> options.
14 * - <b>Hosts: trace-user-variables/trace-user-variables.c</b>. This example shows how user defined variables can be
15 * associated to an host and how to manage the tracing of their evolution.
18 #include "simgrid/msg.h"
20 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
22 static int trace_fun(int argc, char *argv[])
24 const char *hostname = MSG_host_get_name(MSG_host_self());
27 //the hostname has an empty HDD with a capacity of 100000 (bytes)
28 TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
29 TRACE_host_variable_set(hostname, "HDD_utilization", 0);
31 for (i = 0; i < 10; i++) {
32 //create and execute a task just to make the simulated time advance
33 msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
34 MSG_task_execute (task);
35 MSG_task_destroy (task);
37 //ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
38 TRACE_host_variable_add(hostname, "HDD_utilization", 100);
41 for (i = 0; i < 10; i++) {
42 //create and execute a task just to make the simulated time advance
43 msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
44 MSG_task_execute (task);
45 MSG_task_destroy (task);
47 //SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
48 TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
53 int main(int argc, char *argv[])
55 MSG_init(&argc, argv);
56 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
57 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
59 MSG_create_environment(argv[1]);
61 //declaring user variables
62 TRACE_host_variable_declare("HDD_capacity");
63 TRACE_host_variable_declare("HDD_utilization");
65 //register functions and launch deployment
66 MSG_function_register("master", trace_fun);
67 MSG_function_register("worker", trace_fun);
68 MSG_launch_application(argv[2]);
72 //get user declared variables
75 xbt_dynar_t host_variables = TRACE_get_host_variables ();
77 XBT_INFO ("Declared host variables:");
78 xbt_dynar_foreach (host_variables, cursor, variable){
79 XBT_INFO ("%s", variable);
81 xbt_dynar_free (&host_variables);
83 xbt_dynar_t link_variables = TRACE_get_link_variables ();
85 XBT_INFO ("Declared link variables:");
86 xbt_dynar_foreach (link_variables, cursor, variable){
87 XBT_INFO ("%s", variable);
89 xbt_dynar_free (&link_variables);
92 //create a customized viva graph configuration file
94 fp = fopen ("viva_graph.plist", "w");
98 fprintf (fp, "{\n node = (");
99 xbt_dynar_t nodes_type = TRACE_get_node_types ();
101 XBT_INFO ("Node types in the trace:");
103 xbt_dynar_foreach (nodes_type, cursor, node_type){
104 XBT_INFO ("%s", node_type);
105 fprintf (fp, "%s, ", node_type);
107 xbt_dynar_free (&nodes_type);
109 fprintf (fp, ");\n edge = (");
110 xbt_dynar_t edges_type = TRACE_get_edge_types ();
112 XBT_INFO ("Node types in the trace:");
114 xbt_dynar_foreach (edges_type, cursor, edge_type){
115 XBT_INFO ("%s", edge_type);
116 fprintf (fp, "%s, ", edge_type);
118 xbt_dynar_free (&edges_type);
120 fprintf (fp, ");\n");
121 fprintf (fp, " host = {\n type = square;\n size = HDD_capacity; \n values = (HDD_utilization);\n };\n");
122 fprintf (fp, " link = {\n type = rhombus;\n size = bandwidth;\n };\n");