Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
memory address is the unique identifier of links in the paje trace file
[simgrid.git] / src / instr / surf_instr.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/private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(tracing_surf,tracing,"Tracing Surf");
12
13 #define VARIABLE_SEPARATOR '#'
14
15 static xbt_dict_t created_links;
16 static xbt_dict_t host_containers;
17 static xbt_dict_t resource_variables; /* (host|link)#variable -> value */
18
19 /* to trace gtnets */
20 static xbt_dict_t gtnets_src; /* %p (action) -> %s */
21 static xbt_dict_t gtnets_dst; /* %p (action) -> %s */
22
23 void TRACE_surf_init (void)
24 {
25   created_links = xbt_dict_new();
26   host_containers = xbt_dict_new();
27   resource_variables = xbt_dict_new ();
28   gtnets_src = xbt_dict_new ();
29   gtnets_dst = xbt_dict_new ();
30
31   __TRACE_surf_resource_utilization_initialize();
32 }
33
34 void TRACE_surf_finalize (void)
35 {
36   __TRACE_surf_resource_utilization_finalize();
37 }
38
39 static void __TRACE_surf_set_resource_variable (double date, const char *variable, const char *resource, double value)
40 {
41         char aux[100], key[100];
42         char *last_value = NULL;
43   if (!IS_TRACING) return;
44   snprintf (aux, 100, "%f", value);
45   snprintf (key, 100, "%s%c%s", resource, VARIABLE_SEPARATOR, 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   if (IS_TRACING_PLATFORM) pajeSetVariable (date, variable, resource, aux);
54   xbt_dict_set (resource_variables, xbt_strdup(key), xbt_strdup(aux), xbt_free);
55 }
56
57 /*
58  * TRACE_surf_link_declaration (name, bandwidth, latency): this function
59  * saves the bandwidth and latency of a link identified by name. This
60  * information is used in the future to create the link container in the trace.
61  *
62  * caller: net_link_new (from each network model)
63  * main: create LINK container, set initial bandwidth and latency
64  * return: void
65  */
66 void TRACE_surf_link_declaration (void *link, char *name, double bw, double lat)
67 {
68   if (!IS_TRACING) return;
69
70   char alias[100];
71   snprintf (alias, 100, "%p", link);
72   pajeCreateContainer (SIMIX_get_clock(), alias, "LINK", "platform", name);
73   xbt_dict_set (created_links, alias, xbt_strdup ("1"), xbt_free);
74   TRACE_surf_link_set_bandwidth (SIMIX_get_clock(), link, bw);
75   TRACE_surf_link_set_latency (SIMIX_get_clock(), link, lat);
76 }
77
78 /*
79  * TRACE_surf_host_declaration (name, power): this function
80  * saves the power of a host identified by name. This information
81  * is used to create the host container in the trace.
82  *
83  * caller: cpu_new (from each cpu model) + router parser
84  * main: create HOST containers, set initial power value
85  * return: void
86  */
87 void TRACE_surf_host_declaration (char *name, double power)
88 {
89   if (!IS_TRACING) return;
90   pajeCreateContainer (SIMIX_get_clock(), name, "HOST", "platform", name);
91   xbt_dict_set (host_containers, name, xbt_strdup("1"), xbt_free);
92   TRACE_surf_host_set_power (SIMIX_get_clock(), name, power);
93 }
94
95 void TRACE_surf_host_set_power (double date, char *resource, double power)
96 {
97   __TRACE_surf_set_resource_variable (date, "power", resource, power);
98 }
99
100 void TRACE_surf_link_set_bandwidth (double date, void *link, double bandwidth)
101 {
102   char resource[100];
103   snprintf (resource, 100, "%p", link);
104   __TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth);
105 }
106
107 void TRACE_surf_link_set_latency (double date, void *link, double latency)
108 {
109   char resource[100];
110   snprintf (resource, 100, "%p", link);
111   __TRACE_surf_set_resource_variable (date, "latency", resource, latency);
112 }
113
114 /* to trace gtnets */
115 void TRACE_surf_gtnets_communicate (void *action, int src, int dst)
116 {
117         char key[100], aux[100];
118   if (!IS_TRACING) return;
119   snprintf (key, 100, "%p", action);
120
121   snprintf (aux, 100, "%d", src);
122   xbt_dict_set (gtnets_src, key, xbt_strdup(aux), xbt_free);
123   snprintf (aux, 100, "%d", dst);
124   xbt_dict_set (gtnets_dst, key, xbt_strdup(aux), xbt_free);
125 }
126
127 int TRACE_surf_gtnets_get_src (void *action)
128 {
129         char key[100];
130         char *aux = NULL;
131   if (!IS_TRACING) return -1;
132   snprintf (key, 100, "%p", action);
133
134   aux = xbt_dict_get_or_null (gtnets_src, key);
135   if (aux){
136         return atoi(aux);
137   }else{
138     return -1;
139   }
140 }
141
142 int TRACE_surf_gtnets_get_dst (void *action)
143 {
144         char key[100];
145         char *aux = NULL;
146   if (!IS_TRACING) return -1;
147   snprintf (key, 100, "%p", action);
148
149   aux = xbt_dict_get_or_null (gtnets_dst, key);
150   if (aux){
151         return atoi(aux);
152   }else{
153     return -1;
154   }
155 }
156
157 void TRACE_surf_gtnets_destroy (void *action)
158 {
159   char key[100];
160   if (!IS_TRACING) return;
161   snprintf (key, 100, "%p", action);
162   xbt_dict_remove (gtnets_src, key);
163   xbt_dict_remove (gtnets_dst, key);
164 }
165
166 void TRACE_surf_link_missing (void)
167 {
168   CRITICAL0("The trace cannot be done because "
169                  "the platform you are using contains "
170                  "routes with more than one link.");
171   THROW0(tracing_error, TRACE_ERROR_COMPLEX_ROUTES, "Tracing failed");
172 }
173
174 void TRACE_msg_clean (void)
175 {
176   char *key, *value;
177   xbt_dict_cursor_t cursor = NULL;
178   TRACE_surf_finalize();
179
180   /* get all host from host_containers */
181   xbt_dict_foreach(host_containers, cursor, key, value) {
182     pajeDestroyContainer (MSG_get_clock(), "HOST", key);
183   }
184   xbt_dict_foreach(created_links, cursor, key, value) {
185     pajeDestroyContainer (MSG_get_clock(), "LINK", key);
186   }
187 }
188
189 void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h)
190 {
191         char valuestr[100];
192   if (!IS_TRACING || !IS_TRACING_PLATFORM) return;
193
194   snprintf (valuestr, 100, "%g", x);
195   pajeSetVariable (0, "vivaldi_x", host, valuestr);
196   snprintf (valuestr, 100, "%g", y);
197   pajeSetVariable (0, "vivaldi_y", host, valuestr);
198   snprintf (valuestr, 100, "%g", h);
199   pajeSetVariable (0, "vivaldi_h", host, valuestr);
200 }
201
202 #endif