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 (void *link, char *name, double bw, double lat)
68 if (!IS_TRACING) return;
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);
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.
83 * caller: cpu_new (from each cpu model) + router parser
84 * main: create HOST containers, set initial power value
87 void TRACE_surf_host_declaration (char *name, double power)
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);
95 void TRACE_surf_host_set_power (double date, char *resource, double power)
97 __TRACE_surf_set_resource_variable (date, "power", resource, power);
100 void TRACE_surf_link_set_bandwidth (double date, void *link, double bandwidth)
103 snprintf (resource, 100, "%p", link);
104 __TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth);
107 void TRACE_surf_link_set_latency (double date, void *link, double latency)
110 snprintf (resource, 100, "%p", link);
111 __TRACE_surf_set_resource_variable (date, "latency", resource, latency);
114 /* to trace gtnets */
115 void TRACE_surf_gtnets_communicate (void *action, int src, int dst)
117 char key[100], aux[100];
118 if (!IS_TRACING) return;
119 snprintf (key, 100, "%p", action);
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);
127 int TRACE_surf_gtnets_get_src (void *action)
131 if (!IS_TRACING) return -1;
132 snprintf (key, 100, "%p", action);
134 aux = xbt_dict_get_or_null (gtnets_src, key);
142 int TRACE_surf_gtnets_get_dst (void *action)
146 if (!IS_TRACING) return -1;
147 snprintf (key, 100, "%p", action);
149 aux = xbt_dict_get_or_null (gtnets_dst, key);
157 void TRACE_surf_gtnets_destroy (void *action)
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);
166 void TRACE_surf_link_missing (void)
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");
174 void TRACE_msg_clean (void)
177 xbt_dict_cursor_t cursor = NULL;
178 TRACE_surf_finalize();
180 /* get all host from host_containers */
181 xbt_dict_foreach(host_containers, cursor, key, value) {
182 pajeDestroyContainer (MSG_get_clock(), "HOST", key);
184 xbt_dict_foreach(created_links, cursor, key, value) {
185 pajeDestroyContainer (MSG_get_clock(), "LINK", key);
189 void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h)
192 if (!IS_TRACING || !IS_TRACING_PLATFORM) return;
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);