Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] fix trace_platform tesh
[simgrid.git] / examples / msg / tracing / user_variables.c
1 /* Copyright (c) 2010. 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 #include <stdio.h>
8 #include "msg/msg.h"
9 #include "xbt/sysdep.h"         /* calloc, printf */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
15
16 int master(int argc, char *argv[]);
17
18 int master(int argc, char *argv[])
19 {
20   char *hostname = MSG_host_self()->name;
21   int i;
22
23   //the hostname has an empty HDD with a capacity of 100000 (bytes)
24   TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
25   TRACE_host_variable_set(hostname, "HDD_utilization", 0);
26
27   for (i = 0; i < 10; i++) {
28     //create and execute a task just to make the simulated time advance
29     m_task_t task = MSG_task_create("task", 10000, 0, NULL);
30     MSG_task_execute (task);
31     MSG_task_destroy (task);
32
33     //ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
34     TRACE_host_variable_add(hostname, "HDD_utilization", 100);
35   }
36
37   for (i = 0; i < 10; i++) {
38     //create and execute a task just to make the simulated time advance
39     m_task_t task = MSG_task_create("task", 10000, 0, NULL);
40     MSG_task_execute (task);
41     MSG_task_destroy (task);
42
43     //SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
44     TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
45   }
46   return 0;
47 }
48
49 /** Main function */
50 int main(int argc, char *argv[])
51 {
52   MSG_global_init(&argc, argv);
53   if (argc < 3) {
54     printf("Usage: %s platform_file deployment_file\n", argv[0]);
55     exit(1);
56   }
57
58   char *platform_file = argv[1];
59   char *deployment_file = argv[2];
60   MSG_create_environment(platform_file);
61
62   //declaring user variables
63   TRACE_host_variable_declare("HDD_capacity");
64   TRACE_host_variable_declare("HDD_utilization");
65
66   //register functions and launch deployment
67   MSG_function_register("master", master);
68   MSG_function_register("slave", master);
69   MSG_launch_application(deployment_file);
70
71   MSG_main();
72   MSG_clean();
73   return 0;
74 }