Logo AND Algorithmique Numérique Distribuée

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