Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
slave2worker cont'd
[simgrid.git] / examples / msg / trace-user-variables / trace-user-variables.c
1 /* Copyright (c) 2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 /** @addtogroup MSG_examples
8  * 
9  * - <b>tracing/user_variables.c</b>: This program demonstrates how to trace user variables associated to the hosts of
10  * the platform file. You might want to run this program with the following parameters:
11  * --cfg=tracing:yes
12  * --cfg=tracing/platform:yes
13  * (See \ref tracing_tracing_options for details)
14  */
15 #include <stdio.h>
16 #include "simgrid/msg.h"
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
19
20 static int trace_fun(int argc, char *argv[])
21 {
22   const char *hostname = MSG_host_get_name(MSG_host_self());
23   int i;
24
25   //the hostname has an empty HDD with a capacity of 100000 (bytes)
26   TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
27   TRACE_host_variable_set(hostname, "HDD_utilization", 0);
28
29   for (i = 0; i < 10; i++) {
30     //create and execute a task just to make the simulated time advance
31     msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
32     MSG_task_execute (task);
33     MSG_task_destroy (task);
34
35     //ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
36     TRACE_host_variable_add(hostname, "HDD_utilization", 100);
37   }
38
39   for (i = 0; i < 10; i++) {
40     //create and execute a task just to make the simulated time advance
41     msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
42     MSG_task_execute (task);
43     MSG_task_destroy (task);
44
45     //SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
46     TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
47   }
48   return 0;
49 }
50
51 int main(int argc, char *argv[])
52 {
53   MSG_init(&argc, argv);
54   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
55              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
56
57   MSG_create_environment(argv[1]);
58
59   //declaring user variables
60   TRACE_host_variable_declare("HDD_capacity");
61   TRACE_host_variable_declare("HDD_utilization");
62
63   //register functions and launch deployment
64   MSG_function_register("master", trace_fun);
65   MSG_function_register("worker", trace_fun);
66   MSG_launch_application(argv[2]);
67
68   MSG_main();
69
70   //get user declared variables
71   unsigned int cursor;
72   char *variable;
73   xbt_dynar_t host_variables = TRACE_get_host_variables ();
74   if (host_variables){
75     XBT_INFO ("Declared host variables:");
76     xbt_dynar_foreach (host_variables, cursor, variable){
77       XBT_INFO ("%s", variable);
78     }
79     xbt_dynar_free (&host_variables);
80   }
81   xbt_dynar_t link_variables = TRACE_get_link_variables ();
82   if (link_variables){
83     XBT_INFO ("Declared link variables:");
84     xbt_dynar_foreach (link_variables, cursor, variable){
85       XBT_INFO ("%s", variable);
86     }
87     xbt_dynar_free (&link_variables);
88   }
89
90   //create a customized viva graph configuration file
91   FILE *fp;
92   fp = fopen ("viva_graph.plist", "w");
93   if (!fp){
94     return 1;
95   }
96   fprintf (fp, "{\n node = (");
97   xbt_dynar_t nodes_type = TRACE_get_node_types ();
98   if (nodes_type){
99     XBT_INFO ("Node types in the trace:");
100     char *node_type;
101     xbt_dynar_foreach (nodes_type, cursor, node_type){
102       XBT_INFO ("%s", node_type);
103       fprintf (fp, "%s, ", node_type);
104     }
105     xbt_dynar_free (&nodes_type);
106   }
107   fprintf (fp, ");\n edge = (");
108   xbt_dynar_t edges_type = TRACE_get_edge_types ();
109   if (edges_type){
110     XBT_INFO ("Node types in the trace:");
111     char *edge_type;
112     xbt_dynar_foreach (edges_type, cursor, edge_type){
113       XBT_INFO ("%s", edge_type);
114       fprintf (fp, "%s, ", edge_type);
115     }
116     xbt_dynar_free (&edges_type);
117   }
118   fprintf (fp, ");\n");
119   fprintf (fp, " host = {\n  type = square;\n  size = HDD_capacity; \n  values = (HDD_utilization);\n };\n");
120   fprintf (fp, " link = {\n  type = rhombus;\n  size = bandwidth;\n };\n");
121   fprintf (fp, "}\n");
122   fclose (fp);
123
124   return 0;
125 }