Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] remove the function that was used to save the one link routes of the platform...
[simgrid.git] / src / instr / instr_surf.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
10 #ifdef HAVE_TRACING
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_surf, instr, "Tracing Surf");
13
14 static xbt_dict_t resource_variables;   /* (host|link)#variable -> value */
15
16 /* to trace gtnets */
17 static xbt_dict_t gtnets_src;   /* %p (action) -> %s */
18 static xbt_dict_t gtnets_dst;   /* %p (action) -> %s */
19
20 void TRACE_surf_alloc(void)
21 {
22   resource_variables = xbt_dict_new();
23   gtnets_src = xbt_dict_new();
24   gtnets_dst = xbt_dict_new();
25
26   TRACE_surf_resource_utilization_alloc();
27 }
28
29 void TRACE_surf_release(void)
30 {
31   TRACE_surf_resource_utilization_release();
32   instr_destroy_platform();
33 }
34
35 static void TRACE_surf_set_resource_variable(double date,
36                                              const char *variable,
37                                              const char *resource,
38                                              double value)
39 {
40   char aux[100], key[100];
41   char *last_value = NULL;
42   if (!TRACE_is_active())
43     return;
44   snprintf(aux, 100, "%f", value);
45   snprintf(key, 100, "%s#%s", resource, variable);
46
47   last_value = xbt_dict_get_or_null(resource_variables, key);
48   if (last_value) {
49     if (atof(last_value) == value) {
50       return;
51     }
52   }
53   pajeSetVariable(date, variable, resource, aux);
54   xbt_dict_set(resource_variables, xbt_strdup(key), xbt_strdup(aux),
55                xbt_free);
56 }
57
58 void TRACE_surf_host_set_power(double date, const char *resource,
59                                double power)
60 {
61   if (!TRACE_is_active())
62     return;
63   TRACE_surf_set_resource_variable(date, "power", resource, power);
64 }
65
66 void TRACE_surf_link_set_bandwidth(double date, void *link,
67                                    double bandwidth)
68 {
69   if (!TRACE_is_active())
70     return;
71   if (!TRACE_surf_link_is_traced(link))
72     return;
73
74   char resource[100];
75   snprintf(resource, 100, "%p", link);
76   TRACE_surf_set_resource_variable(date, "bandwidth", resource, bandwidth);
77 }
78
79 void TRACE_surf_link_set_latency(double date, void *link, double latency)
80 {
81   if (!TRACE_is_active())
82     return;
83   if (!TRACE_surf_link_is_traced(link))
84     return;
85
86   char resource[100];
87   snprintf(resource, 100, "%p", link);
88   TRACE_surf_set_resource_variable(date, "latency", resource, latency);
89 }
90
91 /* to trace gtnets */
92 void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
93 {
94   char key[100], aux[100];
95   if (!TRACE_is_active())
96     return;
97   snprintf(key, 100, "%p", action);
98
99   snprintf(aux, 100, "%d", src);
100   xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free);
101   snprintf(aux, 100, "%d", dst);
102   xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free);
103 }
104
105 int TRACE_surf_gtnets_get_src(void *action)
106 {
107   char key[100];
108   char *aux = NULL;
109   if (!TRACE_is_active())
110     return -1;
111   snprintf(key, 100, "%p", action);
112
113   aux = xbt_dict_get_or_null(gtnets_src, key);
114   if (aux) {
115     return atoi(aux);
116   } else {
117     return -1;
118   }
119 }
120
121 int TRACE_surf_gtnets_get_dst(void *action)
122 {
123   char key[100];
124   char *aux = NULL;
125   if (!TRACE_is_active())
126     return -1;
127   snprintf(key, 100, "%p", action);
128
129   aux = xbt_dict_get_or_null(gtnets_dst, key);
130   if (aux) {
131     return atoi(aux);
132   } else {
133     return -1;
134   }
135 }
136
137 void TRACE_surf_gtnets_destroy(void *action)
138 {
139   char key[100];
140   if (!TRACE_is_active())
141     return;
142   snprintf(key, 100, "%p", action);
143   xbt_dict_remove(gtnets_src, key);
144   xbt_dict_remove(gtnets_dst, key);
145 }
146
147 void TRACE_surf_host_vivaldi_parse(char *host, double x, double y,
148                                    double h)
149 {
150   char valuestr[100];
151   if (!TRACE_is_active() || !TRACE_platform_is_enabled())
152     return;
153
154   snprintf(valuestr, 100, "%g", x);
155   pajeSetVariable(0, "vivaldi_x", host, valuestr);
156   snprintf(valuestr, 100, "%g", y);
157   pajeSetVariable(0, "vivaldi_y", host, valuestr);
158   snprintf(valuestr, 100, "%g", h);
159   pajeSetVariable(0, "vivaldi_h", host, valuestr);
160 }
161
162 void TRACE_surf_action(surf_action_t surf_action, const char *category)
163 {
164   if (!TRACE_is_active())
165     return;
166   if (!TRACE_categorized ())
167     return;
168   if (!category)
169     return;
170
171   surf_action->category = xbt_strdup(category);
172 }
173 #endif /* HAVE_TRACING */