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 resource_variables; /* (host|link)#variable -> value */
17 static xbt_dict_t gtnets_src; /* %p (action) -> %s */
18 static xbt_dict_t gtnets_dst; /* %p (action) -> %s */
20 void TRACE_surf_alloc(void)
22 resource_variables = xbt_dict_new();
23 gtnets_src = xbt_dict_new();
24 gtnets_dst = xbt_dict_new();
26 TRACE_surf_resource_utilization_alloc();
29 void TRACE_surf_release(void)
31 TRACE_surf_resource_utilization_release();
34 static void TRACE_surf_set_resource_variable(double date,
39 char aux[100], key[100];
40 char *last_value = NULL;
41 if (!TRACE_is_active())
43 snprintf(aux, 100, "%f", value);
44 snprintf(key, 100, "%s#%s", resource, variable);
46 last_value = xbt_dict_get_or_null(resource_variables, key);
48 if (atof(last_value) == value) {
52 pajeSetVariable(date, variable, resource, aux);
53 xbt_dict_set(resource_variables, xbt_strdup(key), xbt_strdup(aux),
57 void TRACE_surf_host_set_power(double date, const char *resource,
60 if (!TRACE_is_active())
62 TRACE_surf_set_resource_variable(date, "power", resource, power);
65 void TRACE_surf_link_set_bandwidth(double date, void *link,
68 if (!TRACE_is_active())
70 if (!TRACE_surf_link_is_traced(link))
74 snprintf(resource, 100, "%p", link);
75 TRACE_surf_set_resource_variable(date, "bandwidth", resource, bandwidth);
78 void TRACE_surf_link_set_latency(double date, void *link, double latency)
80 if (!TRACE_is_active())
82 if (!TRACE_surf_link_is_traced(link))
86 snprintf(resource, 100, "%p", link);
87 TRACE_surf_set_resource_variable(date, "latency", resource, latency);
91 void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
93 char key[100], aux[100];
94 if (!TRACE_is_active())
96 snprintf(key, 100, "%p", action);
98 snprintf(aux, 100, "%d", src);
99 xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free);
100 snprintf(aux, 100, "%d", dst);
101 xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free);
104 int TRACE_surf_gtnets_get_src(void *action)
108 if (!TRACE_is_active())
110 snprintf(key, 100, "%p", action);
112 aux = xbt_dict_get_or_null(gtnets_src, key);
120 int TRACE_surf_gtnets_get_dst(void *action)
124 if (!TRACE_is_active())
126 snprintf(key, 100, "%p", action);
128 aux = xbt_dict_get_or_null(gtnets_dst, key);
136 void TRACE_surf_gtnets_destroy(void *action)
139 if (!TRACE_is_active())
141 snprintf(key, 100, "%p", action);
142 xbt_dict_remove(gtnets_src, key);
143 xbt_dict_remove(gtnets_dst, key);
146 void TRACE_surf_host_vivaldi_parse(char *host, double x, double y,
150 if (!TRACE_is_active() || !TRACE_platform_is_enabled())
153 snprintf(valuestr, 100, "%g", x);
154 pajeSetVariable(0, "vivaldi_x", host, valuestr);
155 snprintf(valuestr, 100, "%g", y);
156 pajeSetVariable(0, "vivaldi_y", host, valuestr);
157 snprintf(valuestr, 100, "%g", h);
158 pajeSetVariable(0, "vivaldi_h", host, valuestr);
161 extern routing_global_t global_routing;
162 void TRACE_surf_save_onelink(void)
164 if (!TRACE_is_active())
167 //get the onelinks from the parsed platform
168 xbt_dynar_t onelink_routes = global_routing->get_onelink_routes();
172 //save them in trace file
175 xbt_dynar_foreach(onelink_routes, iter, onelink) {
176 char *src = onelink->src;
177 char *dst = onelink->dst;
178 void *link = onelink->link_ptr;
180 if (TRACE_surf_link_is_traced(link)) {
182 snprintf(resource, 100, "%p", link);
184 pajeNewEvent(0, "source", resource, src);
185 pajeNewEvent(0, "destination", resource, dst);
190 void TRACE_surf_action(surf_action_t surf_action, const char *category)
192 if (!TRACE_is_active())
194 if (!TRACE_categorized ())
199 surf_action->category = xbt_strdup(category);
201 #endif /* HAVE_TRACING */