Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] updating the user link variables mechanism and its interface
[simgrid.git] / src / instr / instr_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 "instr/instr_private.h"
8 #include "surf/surf_private.h"
9 #include "surf/network_private.h"
10
11 #ifdef HAVE_TRACING
12
13 //extern routing_global_t global_routing;
14 extern xbt_dict_t hosts_types;
15 extern xbt_dict_t links_types;
16
17 void TRACE_user_link_variable(double time, const char *resource,
18                               const char *variable,
19                               double value, const char *what)
20 {
21   if (!TRACE_is_active())
22     return;
23
24   char valuestr[100];
25   snprintf(valuestr, 100, "%g", value);
26
27   if (strcmp(what, "declare") == 0) {
28     {
29       //check if links have been created
30       xbt_assert1 (links_types != NULL && xbt_dict_length(links_types) != 0,
31           "%s must be called after environment creation", __FUNCTION__);
32     }
33
34     char new_type[INSTR_DEFAULT_STR_SIZE];
35     xbt_dict_cursor_t cursor = NULL;
36     char *type;
37     void *data;
38     xbt_dict_foreach(links_types, cursor, type, data) {
39       snprintf (new_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", variable, type);
40       pajeDefineVariableType (new_type, type, variable);
41     }
42   } else{
43     char *link_type = instr_link_type (resource);
44     xbt_assert2 (link_type != NULL,
45         "link %s provided to %s is not known by the tracing mechanism", resource, __FUNCTION__);
46     char variable_type[INSTR_DEFAULT_STR_SIZE];
47     snprintf (variable_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", variable, link_type);
48
49     if (strcmp(what, "set") == 0) {
50       pajeSetVariable(time, variable_type, resource, valuestr);
51     } else if (strcmp(what, "add") == 0) {
52       pajeAddVariable(time, variable_type, resource, valuestr);
53     } else if (strcmp(what, "sub") == 0) {
54       pajeSubVariable(time, variable_type, resource, valuestr);
55     }
56   }
57 }
58
59 void TRACE_user_host_variable(double time, const char *variable,
60                               double value, const char *what)
61 {
62   if (!TRACE_is_active())
63     return;
64
65   char valuestr[100];
66   snprintf(valuestr, 100, "%g", value);
67
68   if (strcmp(what, "declare") == 0) {
69     {
70       //check if hosts have been created
71       xbt_assert1 (hosts_types != NULL && xbt_dict_length(hosts_types) != 0,
72           "%s must be called after environment creation", __FUNCTION__);
73     }
74
75     char new_type[INSTR_DEFAULT_STR_SIZE];
76     xbt_dict_cursor_t cursor = NULL;
77     char *type;
78     void *data;
79     xbt_dict_foreach(hosts_types, cursor, type, data) {
80       snprintf (new_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", variable, type);
81       pajeDefineVariableType (new_type, type, variable);
82     }
83   } else{
84     char *host_name = MSG_host_self()->name;
85     char *host_type = instr_host_type (host_name);
86     char variable_type[INSTR_DEFAULT_STR_SIZE];
87     snprintf (variable_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", variable, host_type);
88
89     if (strcmp(what, "set") == 0) {
90       pajeSetVariable(time, variable_type, host_name, valuestr);
91     } else if (strcmp(what, "add") == 0) {
92       pajeAddVariable(time, variable_type, host_name, valuestr);
93     } else if (strcmp(what, "sub") == 0) {
94       pajeSubVariable(time, variable_type, host_name, valuestr);
95     }
96   }
97 }
98
99 #endif /* HAVE_TRACING */