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 #include "instr/private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(tracing_surf,tracing,"Tracing Surf");
13 #define VARIABLE_SEPARATOR '#'
15 static xbt_dict_t created_links;
16 static xbt_dict_t host_containers;
17 static xbt_dict_t platform_variables; /* host or link name -> array of categories */
18 static xbt_dict_t resource_variables; /* (host|link)#variable -> value */
21 static xbt_dict_t gtnets_src; /* %p (action) -> %s */
22 static xbt_dict_t gtnets_dst; /* %p (action) -> %s */
24 void __TRACE_surf_init (void)
26 created_links = xbt_dict_new();
27 platform_variables = xbt_dict_new();
28 host_containers = xbt_dict_new();
29 resource_variables = xbt_dict_new ();
30 gtnets_src = xbt_dict_new ();
31 gtnets_dst = xbt_dict_new ();
32 __TRACE_surf_resource_utilization_initialize();
35 void __TRACE_surf_finalize (void)
37 __TRACE_surf_resource_utilization_finalize();
40 void __TRACE_surf_check_variable_set_to_zero (double now, const char *variable, const char *resource)
42 /* check if we have to set it to 0 */
43 if (!xbt_dict_get_or_null (platform_variables, resource)){
44 xbt_dynar_t array = xbt_dynar_new(sizeof(char*), xbt_free);
45 char *var_cpy = xbt_strdup(variable);
46 xbt_dynar_push (array, &var_cpy);
47 if (IS_TRACING_PLATFORM) pajeSetVariable (now, variable, resource, "0");
48 xbt_dict_set (platform_variables, resource, array, xbt_dynar_free_voidp);
50 xbt_dynar_t array = xbt_dict_get (platform_variables, resource);
54 xbt_dynar_foreach (array, i, cat) {
55 if (strcmp(variable, cat)==0){
60 char *var_cpy = xbt_strdup(variable);
61 xbt_dynar_push (array, &var_cpy);
62 if (IS_TRACING_PLATFORM) pajeSetVariable (now, variable, resource, "0");
68 void __TRACE_surf_set_resource_variable (double date, const char *variable, const char *resource, double value)
70 char aux[100], key[100];
71 char *last_value = NULL;
72 if (!IS_TRACING) return;
73 snprintf (aux, 100, "%f", value);
74 snprintf (key, 100, "%s%c%s", resource, VARIABLE_SEPARATOR, variable);
76 last_value = xbt_dict_get_or_null(resource_variables, key);
78 if (atof(last_value) == value){
82 if (IS_TRACING_PLATFORM) pajeSetVariable (date, variable, resource, aux);
83 xbt_dict_set (resource_variables, xbt_strdup(key), xbt_strdup(aux), xbt_free);
87 * TRACE_surf_link_declaration (name, bandwidth, latency): this function
88 * saves the bandwidth and latency of a link identified by name. This
89 * information is used in the future to create the link container in the trace.
91 * caller: net_link_new (from each network model)
92 * main: create LINK container, set initial bandwidth and latency
95 void TRACE_surf_link_declaration (char *name, double bw, double lat)
97 if (!IS_TRACING) return;
99 if (strcmp (name, "__loopback__")==0 ||
100 strcmp (name, "loopback")==0){ //ignore loopback updates
104 pajeCreateContainer (SIMIX_get_clock(), name, "LINK", "platform", name);
105 xbt_dict_set (created_links, name, xbt_strdup ("1"), xbt_free);
106 TRACE_surf_link_set_bandwidth (SIMIX_get_clock(), name, bw);
107 TRACE_surf_link_set_latency (SIMIX_get_clock(), name, lat);
111 * TRACE_surf_host_declaration (name, power): this function
112 * saves the power of a host identified by name. This information
113 * is used to create the host container in the trace.
115 * caller: cpu_new (from each cpu model) + router parser
116 * main: create HOST containers, set initial power value
119 void TRACE_surf_host_declaration (char *name, double power)
121 if (!IS_TRACING) return;
122 pajeCreateContainer (SIMIX_get_clock(), name, "HOST", "platform", name);
123 xbt_dict_set (host_containers, name, xbt_strdup("1"), xbt_free);
124 TRACE_surf_host_set_power (SIMIX_get_clock(), name, power);
127 void TRACE_surf_host_set_power (double date, char *resource, double power)
129 __TRACE_surf_set_resource_variable (date, "power", resource, power);
132 void TRACE_surf_link_set_bandwidth (double date, char *resource, double bandwidth)
134 __TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth);
137 void TRACE_surf_link_set_latency (double date, char *resource, double latency)
139 __TRACE_surf_set_resource_variable (date, "latency", resource, latency);
142 /* to trace gtnets */
143 void TRACE_surf_gtnets_communicate (void *action, int src, int dst)
145 char key[100], aux[100];
146 if (!IS_TRACING) return;
147 snprintf (key, 100, "%p", action);
149 snprintf (aux, 100, "%d", src);
150 xbt_dict_set (gtnets_src, key, xbt_strdup(aux), xbt_free);
151 snprintf (aux, 100, "%d", dst);
152 xbt_dict_set (gtnets_dst, key, xbt_strdup(aux), xbt_free);
155 int TRACE_surf_gtnets_get_src (void *action)
159 if (!IS_TRACING) return -1;
160 snprintf (key, 100, "%p", action);
162 aux = xbt_dict_get_or_null (gtnets_src, key);
170 int TRACE_surf_gtnets_get_dst (void *action)
174 if (!IS_TRACING) return -1;
175 snprintf (key, 100, "%p", action);
177 aux = xbt_dict_get_or_null (gtnets_dst, key);
185 void TRACE_surf_gtnets_destroy (void *action)
188 if (!IS_TRACING) return;
189 snprintf (key, 100, "%p", action);
190 xbt_dict_remove (gtnets_src, key);
191 xbt_dict_remove (gtnets_dst, key);
194 void TRACE_surf_link_missing (void)
196 CRITICAL0("The trace cannot be done because "
197 "the platform you are using contains "
198 "routes with more than one link.");
199 THROW0(tracing_error, TRACE_ERROR_COMPLEX_ROUTES, "Tracing failed");
202 void TRACE_msg_clean (void)
205 xbt_dict_cursor_t cursor = NULL;
206 __TRACE_surf_finalize();
208 /* get all host from host_containers */
209 xbt_dict_foreach(host_containers, cursor, key, value) {
210 pajeDestroyContainer (MSG_get_clock(), "HOST", key);
214 void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h)
217 if (!IS_TRACING || !IS_TRACING_PLATFORM) return;
219 snprintf (valuestr, 100, "%g", x);
220 pajeSetVariable (0, "vivaldi_x", host, valuestr);
221 snprintf (valuestr, 100, "%g", y);
222 pajeSetVariable (0, "vivaldi_y", host, valuestr);
223 snprintf (valuestr, 100, "%g", h);
224 pajeSetVariable (0, "vivaldi_h", host, valuestr);