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>: Demonstrates how to trace user-provided variables
14 #include "xbt/sysdep.h" /* calloc, printf */
16 /* Create a log channel to have nice outputs. */
18 #include "xbt/asserts.h"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
21 int master(int argc, char *argv[]);
23 int master(int argc, char *argv[])
25 char *hostname = MSG_host_self()->name;
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);
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);
38 //ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
39 TRACE_host_variable_add(hostname, "HDD_utilization", 100);
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);
48 //SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
49 TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
55 int main(int argc, char *argv[])
57 MSG_global_init(&argc, argv);
59 printf("Usage: %s platform_file deployment_file\n", argv[0]);
63 char *platform_file = argv[1];
64 char *deployment_file = argv[2];
65 MSG_create_environment(platform_file);
67 //declaring user variables
68 TRACE_host_variable_declare("HDD_capacity");
69 TRACE_host_variable_declare("HDD_utilization");
71 //register functions and launch deployment
72 MSG_function_register("master", master);
73 MSG_function_register("slave", master);
74 MSG_launch_application(deployment_file);