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/instr_private.h"
8 #include "surf/surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_surf, instr, "Tracing Surf");
14 static xbt_dict_t created_links;
15 static xbt_dict_t host_containers;
16 static xbt_dict_t resource_variables; /* (host|link)#variable -> value */
19 static xbt_dict_t gtnets_src; /* %p (action) -> %s */
20 static xbt_dict_t gtnets_dst; /* %p (action) -> %s */
22 void TRACE_surf_alloc(void)
24 created_links = xbt_dict_new();
25 host_containers = xbt_dict_new();
26 resource_variables = xbt_dict_new();
27 gtnets_src = xbt_dict_new();
28 gtnets_dst = xbt_dict_new();
30 TRACE_surf_resource_utilization_alloc();
33 void TRACE_surf_release(void)
36 xbt_dict_cursor_t cursor = NULL;
37 TRACE_surf_resource_utilization_release();
39 /* get all host from host_containers */
40 xbt_dict_foreach(host_containers, cursor, key, value) {
41 pajeDestroyContainer(MSG_get_clock(), "HOST", key);
43 xbt_dict_foreach(created_links, cursor, key, value) {
44 pajeDestroyContainer(MSG_get_clock(), "LINK", key);
48 static void TRACE_surf_set_resource_variable(double date,
53 char aux[100], key[100];
54 char *last_value = NULL;
55 if (!TRACE_is_active())
57 snprintf(aux, 100, "%f", value);
58 snprintf(key, 100, "%s#%s", resource, variable);
60 last_value = xbt_dict_get_or_null(resource_variables, key);
62 if (atof(last_value) == value) {
66 pajeSetVariable(date, variable, resource, aux);
67 xbt_dict_set(resource_variables, xbt_strdup(key), xbt_strdup(aux),
72 * TRACE_surf_link_declaration (name, bandwidth, latency): this function
73 * saves the bandwidth and latency of a link identified by name. This
74 * information is used in the future to create the link container in the trace.
76 * caller: net_link_new (from each network model)
77 * main: create LINK container, set initial bandwidth and latency
80 void TRACE_surf_link_declaration(void *link, char *name, double bw,
83 if (!TRACE_is_active())
87 xbt_die ("link is NULL");
91 if (!strcmp(name, "loopback") || !strcmp(name, "__loopback__"))
95 snprintf(alias, 100, "%p", link);
96 pajeCreateContainer(SIMIX_get_clock(), alias, "LINK", "platform", name);
97 xbt_dict_set(created_links, alias, xbt_strdup("1"), xbt_free);
98 TRACE_surf_link_set_bandwidth(SIMIX_get_clock(), link, bw);
99 TRACE_surf_link_set_latency(SIMIX_get_clock(), link, lat);
103 * TRACE_surf_host_declaration (name, power): this function
104 * saves the power of a host identified by name. This information
105 * is used to create the host container in the trace.
107 * caller: cpu_new (from each cpu model) + router parser
108 * main: create HOST containers, set initial power value
111 void TRACE_surf_host_declaration(const char *name, double power)
113 if (!TRACE_is_active())
115 pajeCreateContainer(SIMIX_get_clock(), name, "HOST", "platform", name);
116 xbt_dict_set(host_containers, name, xbt_strdup("1"), xbt_free);
117 TRACE_surf_host_set_power(SIMIX_get_clock(), name, power);
120 void TRACE_surf_host_set_power(double date, const char *resource,
123 if (!TRACE_is_active())
125 TRACE_surf_set_resource_variable(date, "power", resource, power);
128 void TRACE_surf_link_set_bandwidth(double date, void *link,
131 if (!TRACE_is_active())
133 if (!TRACE_surf_link_is_traced(link))
137 snprintf(resource, 100, "%p", link);
138 TRACE_surf_set_resource_variable(date, "bandwidth", resource, bandwidth);
141 void TRACE_surf_link_set_latency(double date, void *link, double latency)
143 if (!TRACE_is_active())
145 if (!TRACE_surf_link_is_traced(link))
149 snprintf(resource, 100, "%p", link);
150 TRACE_surf_set_resource_variable(date, "latency", resource, latency);
153 /* to trace gtnets */
154 void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
156 char key[100], aux[100];
157 if (!TRACE_is_active())
159 snprintf(key, 100, "%p", action);
161 snprintf(aux, 100, "%d", src);
162 xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free);
163 snprintf(aux, 100, "%d", dst);
164 xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free);
167 int TRACE_surf_gtnets_get_src(void *action)
171 if (!TRACE_is_active())
173 snprintf(key, 100, "%p", action);
175 aux = xbt_dict_get_or_null(gtnets_src, key);
183 int TRACE_surf_gtnets_get_dst(void *action)
187 if (!TRACE_is_active())
189 snprintf(key, 100, "%p", action);
191 aux = xbt_dict_get_or_null(gtnets_dst, key);
199 void TRACE_surf_gtnets_destroy(void *action)
202 if (!TRACE_is_active())
204 snprintf(key, 100, "%p", action);
205 xbt_dict_remove(gtnets_src, key);
206 xbt_dict_remove(gtnets_dst, key);
209 void TRACE_surf_host_vivaldi_parse(char *host, double x, double y,
213 if (!TRACE_is_active() || !TRACE_platform_is_enabled())
216 snprintf(valuestr, 100, "%g", x);
217 pajeSetVariable(0, "vivaldi_x", host, valuestr);
218 snprintf(valuestr, 100, "%g", y);
219 pajeSetVariable(0, "vivaldi_y", host, valuestr);
220 snprintf(valuestr, 100, "%g", h);
221 pajeSetVariable(0, "vivaldi_h", host, valuestr);
224 extern routing_global_t global_routing;
225 void TRACE_surf_save_onelink(void)
227 if (!TRACE_is_active())
230 //get the onelinks from the parsed platform
231 xbt_dynar_t onelink_routes = global_routing->get_onelink_routes();
235 //save them in trace file
238 xbt_dynar_foreach(onelink_routes, iter, onelink) {
239 char *src = onelink->src;
240 char *dst = onelink->dst;
241 void *link = onelink->link_ptr;
243 if (TRACE_surf_link_is_traced(link)) {
245 snprintf(resource, 100, "%p", link);
247 pajeNewEvent(0, "source", resource, src);
248 pajeNewEvent(0, "destination", resource, dst);
253 int TRACE_surf_link_is_traced(void *link)
256 snprintf(alias, 100, "%p", link);
257 if (xbt_dict_get_or_null(created_links, alias)) {
264 void TRACE_surf_action(surf_action_t surf_action, const char *category)
266 if (!TRACE_is_active())
268 if (!TRACE_platform_is_enabled())
273 surf_action->category = xbt_new(char, strlen(category) + 1);
274 strncpy(surf_action->category, category, strlen(category) + 1);
276 #endif /* HAVE_TRACING */