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 resource_variables; /* (host|link)#variable -> value */
20 static xbt_dict_t gtnets_src; /* %p (action) -> %s */
21 static xbt_dict_t gtnets_dst; /* %p (action) -> %s */
23 void TRACE_surf_init (void)
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 ();
31 __TRACE_surf_resource_utilization_initialize();
34 void TRACE_surf_finalize (void)
36 __TRACE_surf_resource_utilization_finalize();
39 static void __TRACE_surf_set_resource_variable (double date, const char *variable, const char *resource, double value)
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);
47 last_value = xbt_dict_get_or_null(resource_variables, key);
49 if (atof(last_value) == value){
53 if (IS_TRACING_PLATFORM) pajeSetVariable (date, variable, resource, aux);
54 xbt_dict_set (resource_variables, xbt_strdup(key), xbt_strdup(aux), xbt_free);
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.
62 * caller: net_link_new (from each network model)
63 * main: create LINK container, set initial bandwidth and latency
66 void TRACE_surf_link_declaration (char *name, double bw, double lat)
68 if (!IS_TRACING) return;
70 if (strcmp (name, "__loopback__")==0 ||
71 strcmp (name, "loopback")==0){ //ignore loopback updates
75 pajeCreateContainer (SIMIX_get_clock(), name, "LINK", "platform", name);
76 xbt_dict_set (created_links, name, xbt_strdup ("1"), xbt_free);
77 TRACE_surf_link_set_bandwidth (SIMIX_get_clock(), name, bw);
78 TRACE_surf_link_set_latency (SIMIX_get_clock(), name, lat);
82 * TRACE_surf_host_declaration (name, power): this function
83 * saves the power of a host identified by name. This information
84 * is used to create the host container in the trace.
86 * caller: cpu_new (from each cpu model) + router parser
87 * main: create HOST containers, set initial power value
90 void TRACE_surf_host_declaration (char *name, double power)
92 if (!IS_TRACING) return;
93 pajeCreateContainer (SIMIX_get_clock(), name, "HOST", "platform", name);
94 xbt_dict_set (host_containers, name, xbt_strdup("1"), xbt_free);
95 TRACE_surf_host_set_power (SIMIX_get_clock(), name, power);
98 void TRACE_surf_host_set_power (double date, char *resource, double power)
100 __TRACE_surf_set_resource_variable (date, "power", resource, power);
103 void TRACE_surf_link_set_bandwidth (double date, char *resource, double bandwidth)
105 __TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth);
108 void TRACE_surf_link_set_latency (double date, char *resource, double latency)
110 __TRACE_surf_set_resource_variable (date, "latency", resource, latency);
113 /* to trace gtnets */
114 void TRACE_surf_gtnets_communicate (void *action, int src, int dst)
116 char key[100], aux[100];
117 if (!IS_TRACING) return;
118 snprintf (key, 100, "%p", action);
120 snprintf (aux, 100, "%d", src);
121 xbt_dict_set (gtnets_src, key, xbt_strdup(aux), xbt_free);
122 snprintf (aux, 100, "%d", dst);
123 xbt_dict_set (gtnets_dst, key, xbt_strdup(aux), xbt_free);
126 int TRACE_surf_gtnets_get_src (void *action)
130 if (!IS_TRACING) return -1;
131 snprintf (key, 100, "%p", action);
133 aux = xbt_dict_get_or_null (gtnets_src, key);
141 int TRACE_surf_gtnets_get_dst (void *action)
145 if (!IS_TRACING) return -1;
146 snprintf (key, 100, "%p", action);
148 aux = xbt_dict_get_or_null (gtnets_dst, key);
156 void TRACE_surf_gtnets_destroy (void *action)
159 if (!IS_TRACING) return;
160 snprintf (key, 100, "%p", action);
161 xbt_dict_remove (gtnets_src, key);
162 xbt_dict_remove (gtnets_dst, key);
165 void TRACE_surf_link_missing (void)
167 CRITICAL0("The trace cannot be done because "
168 "the platform you are using contains "
169 "routes with more than one link.");
170 THROW0(tracing_error, TRACE_ERROR_COMPLEX_ROUTES, "Tracing failed");
173 void TRACE_msg_clean (void)
176 xbt_dict_cursor_t cursor = NULL;
177 TRACE_surf_finalize();
179 /* get all host from host_containers */
180 xbt_dict_foreach(host_containers, cursor, key, value) {
181 pajeDestroyContainer (MSG_get_clock(), "HOST", key);
183 xbt_dict_foreach(created_links, cursor, key, value) {
184 pajeDestroyContainer (MSG_get_clock(), "LINK", key);
188 void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h)
191 if (!IS_TRACING || !IS_TRACING_PLATFORM) return;
193 snprintf (valuestr, 100, "%g", x);
194 pajeSetVariable (0, "vivaldi_x", host, valuestr);
195 snprintf (valuestr, 100, "%g", y);
196 pajeSetVariable (0, "vivaldi_y", host, valuestr);
197 snprintf (valuestr, 100, "%g", h);
198 pajeSetVariable (0, "vivaldi_h", host, valuestr);