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"
8 #include "surf/surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(tracing_surf, tracing, "Tracing Surf");
14 #define VARIABLE_SEPARATOR '#'
16 static xbt_dict_t created_links;
17 static xbt_dict_t host_containers;
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_alloc(void)
26 created_links = xbt_dict_new();
27 host_containers = xbt_dict_new();
28 resource_variables = xbt_dict_new();
29 gtnets_src = xbt_dict_new();
30 gtnets_dst = xbt_dict_new();
32 TRACE_surf_resource_utilization_alloc();
35 void TRACE_surf_release(void)
38 xbt_dict_cursor_t cursor = NULL;
39 TRACE_surf_resource_utilization_release();
41 /* get all host from host_containers */
42 xbt_dict_foreach(host_containers, cursor, key, value) {
43 pajeDestroyContainer(MSG_get_clock(), "HOST", key);
45 xbt_dict_foreach(created_links, cursor, key, value) {
46 pajeDestroyContainer(MSG_get_clock(), "LINK", key);
50 static void TRACE_surf_set_resource_variable(double date,
55 char aux[100], key[100];
56 char *last_value = NULL;
59 snprintf(aux, 100, "%f", value);
60 snprintf(key, 100, "%s%c%s", resource, VARIABLE_SEPARATOR, variable);
62 last_value = xbt_dict_get_or_null(resource_variables, key);
64 if (atof(last_value) == value) {
68 if (IS_TRACING_PLATFORM)
69 pajeSetVariable(date, variable, resource, aux);
70 xbt_dict_set(resource_variables, xbt_strdup(key), xbt_strdup(aux),
75 * TRACE_surf_link_declaration (name, bandwidth, latency): this function
76 * saves the bandwidth and latency of a link identified by name. This
77 * information is used in the future to create the link container in the trace.
79 * caller: net_link_new (from each network model)
80 * main: create LINK container, set initial bandwidth and latency
83 void TRACE_surf_link_declaration(void *link, char *name, double bw,
90 if (!strcmp(name, "loopback") || !strcmp(name, "__loopback__"))
94 snprintf(alias, 100, "%p", link);
95 pajeCreateContainer(SIMIX_get_clock(), alias, "LINK", "platform", name);
96 xbt_dict_set(created_links, alias, xbt_strdup("1"), xbt_free);
97 TRACE_surf_link_set_bandwidth(SIMIX_get_clock(), link, bw);
98 TRACE_surf_link_set_latency(SIMIX_get_clock(), link, lat);
102 * TRACE_surf_host_declaration (name, power): this function
103 * saves the power of a host identified by name. This information
104 * is used to create the host container in the trace.
106 * caller: cpu_new (from each cpu model) + router parser
107 * main: create HOST containers, set initial power value
110 void TRACE_surf_host_declaration(const char *name, double power)
114 pajeCreateContainer(SIMIX_get_clock(), name, "HOST", "platform", name);
115 xbt_dict_set(host_containers, name, xbt_strdup("1"), xbt_free);
116 TRACE_surf_host_set_power(SIMIX_get_clock(), name, power);
119 void TRACE_surf_host_set_power(double date, const char *resource,
122 TRACE_surf_set_resource_variable(date, "power", resource, power);
125 void TRACE_surf_link_set_bandwidth(double date, void *link,
128 if (!TRACE_surf_link_is_traced(link))
132 snprintf(resource, 100, "%p", link);
133 TRACE_surf_set_resource_variable(date, "bandwidth", resource, bandwidth);
136 void TRACE_surf_link_set_latency(double date, void *link, double latency)
138 if (!TRACE_surf_link_is_traced(link))
142 snprintf(resource, 100, "%p", link);
143 TRACE_surf_set_resource_variable(date, "latency", resource, latency);
146 /* to trace gtnets */
147 void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
149 char key[100], aux[100];
152 snprintf(key, 100, "%p", action);
154 snprintf(aux, 100, "%d", src);
155 xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free);
156 snprintf(aux, 100, "%d", dst);
157 xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free);
160 int TRACE_surf_gtnets_get_src(void *action)
166 snprintf(key, 100, "%p", action);
168 aux = xbt_dict_get_or_null(gtnets_src, key);
176 int TRACE_surf_gtnets_get_dst(void *action)
182 snprintf(key, 100, "%p", action);
184 aux = xbt_dict_get_or_null(gtnets_dst, key);
192 void TRACE_surf_gtnets_destroy(void *action)
197 snprintf(key, 100, "%p", action);
198 xbt_dict_remove(gtnets_src, key);
199 xbt_dict_remove(gtnets_dst, key);
202 void TRACE_surf_host_vivaldi_parse(char *host, double x, double y,
206 if (!IS_TRACING || !IS_TRACING_PLATFORM)
209 snprintf(valuestr, 100, "%g", x);
210 pajeSetVariable(0, "vivaldi_x", host, valuestr);
211 snprintf(valuestr, 100, "%g", y);
212 pajeSetVariable(0, "vivaldi_y", host, valuestr);
213 snprintf(valuestr, 100, "%g", h);
214 pajeSetVariable(0, "vivaldi_h", host, valuestr);
217 extern routing_global_t global_routing;
218 void TRACE_surf_save_onelink(void)
223 //get the onelinks from the parsed platform
224 xbt_dynar_t onelink_routes = global_routing->get_onelink_routes();
228 //save them in trace file
231 xbt_dynar_foreach(onelink_routes, iter, onelink) {
232 char *src = onelink->src;
233 char *dst = onelink->dst;
234 void *link = onelink->link_ptr;
236 if (TRACE_surf_link_is_traced(link)) {
238 snprintf(resource, 100, "%p", link);
240 pajeNewEvent(0.1, "source", resource, src);
241 pajeNewEvent(0.1, "destination", resource, dst);
246 int TRACE_surf_link_is_traced(void *link)
249 snprintf(alias, 100, "%p", link);
250 if (xbt_dict_get_or_null(created_links, alias)) {
257 void TRACE_surf_action(surf_action_t surf_action, const char *category)
261 if (!IS_TRACING_PLATFORM)
264 xbt_die("invalid tracing category");
266 surf_action->category = xbt_new(char, strlen(category) + 1);
267 strncpy(surf_action->category, category, strlen(category) + 1);