1 /* Copyright (c) 2010. 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 * - <b>tracing/user_variables.c</b>: This program demonstrates how to
10 * trace user variables associated to the hosts of the platform file.
11 * You might want to run this program with the following parameters:
13 * --cfg=tracing/platform:1
14 * (See \ref tracing_tracing_options for details)
19 #include "xbt/sysdep.h" /* calloc, printf */
21 /* Create a log channel to have nice outputs. */
23 #include "xbt/asserts.h"
24 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
26 int master(int argc, char *argv[]);
28 int master(int argc, char *argv[])
30 const char *hostname = MSG_host_get_name(MSG_host_self());
33 //the hostname has an empty HDD with a capacity of 100000 (bytes)
34 TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
35 TRACE_host_variable_set(hostname, "HDD_utilization", 0);
37 for (i = 0; i < 10; i++) {
38 //create and execute a task just to make the simulated time advance
39 msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
40 MSG_task_execute (task);
41 MSG_task_destroy (task);
43 //ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
44 TRACE_host_variable_add(hostname, "HDD_utilization", 100);
47 for (i = 0; i < 10; i++) {
48 //create and execute a task just to make the simulated time advance
49 msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
50 MSG_task_execute (task);
51 MSG_task_destroy (task);
53 //SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
54 TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
60 int main(int argc, char *argv[])
62 MSG_init(&argc, argv);
64 printf("Usage: %s platform_file deployment_file\n", argv[0]);
68 char *platform_file = argv[1];
69 char *deployment_file = argv[2];
70 MSG_create_environment(platform_file);
72 //declaring user variables
73 TRACE_host_variable_declare("HDD_capacity");
74 TRACE_host_variable_declare("HDD_utilization");
76 //register functions and launch deployment
77 MSG_function_register("master", master);
78 MSG_function_register("slave", master);
79 MSG_launch_application(deployment_file);
83 //get user declared variables
86 xbt_dynar_t host_variables = TRACE_get_host_variables ();
88 XBT_INFO ("Declared host variables:");
89 xbt_dynar_foreach (host_variables, cursor, variable){
90 XBT_INFO ("%s", variable);
92 xbt_dynar_free (&host_variables);
94 xbt_dynar_t link_variables = TRACE_get_link_variables ();
96 XBT_INFO ("Declared link variables:");
97 xbt_dynar_foreach (link_variables, cursor, variable){
98 XBT_INFO ("%s", variable);
100 xbt_dynar_free (&link_variables);
103 //create a customized triva graph configuration file
105 fp = fopen ("triva_graph.plist", "w");
109 fprintf (fp, "{\n node = (");
110 xbt_dynar_t nodes_type = TRACE_get_node_types ();
112 XBT_INFO ("Node types in the trace:");
114 xbt_dynar_foreach (nodes_type, cursor, node_type){
115 XBT_INFO ("%s", node_type);
116 fprintf (fp, "%s, ", node_type);
118 xbt_dynar_free (&nodes_type);
120 fprintf (fp, ");\n edge = (");
121 xbt_dynar_t edges_type = TRACE_get_edge_types ();
123 XBT_INFO ("Node types in the trace:");
125 xbt_dynar_foreach (edges_type, cursor, edge_type){
126 XBT_INFO ("%s", edge_type);
127 fprintf (fp, "%s, ", edge_type);
129 xbt_dynar_free (&edges_type);
131 fprintf (fp, ");\n");
132 fprintf (fp, " host = {\n type = square;\n size = HDD_capacity; \n values = (HDD_utilization);\n };\n");
133 fprintf (fp, " link = {\n type = rhombus;\n size = bandwidth;\n };\n");