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();
32 instr_destroy_platform();
35 static void TRACE_surf_set_resource_variable(double date,
40 char aux[100], key[100];
41 char *last_value = NULL;
42 if (!TRACE_is_active())
44 snprintf(aux, 100, "%f", value);
45 snprintf(key, 100, "%s#%s", resource, variable);
47 last_value = xbt_dict_get_or_null(resource_variables, key);
49 if (atof(last_value) == value) {
53 pajeSetVariable(date, variable, resource, aux);
54 xbt_dict_set(resource_variables, xbt_strdup(key), xbt_strdup(aux),
58 void TRACE_surf_host_set_power(double date, const char *resource,
61 if (!TRACE_is_active())
63 TRACE_surf_set_resource_variable(date, "power", resource, power);
66 void TRACE_surf_link_set_bandwidth(double date, void *link,
69 if (!TRACE_is_active())
71 if (!TRACE_surf_link_is_traced(link))
75 snprintf(resource, 100, "%p", link);
76 TRACE_surf_set_resource_variable(date, "bandwidth", resource, bandwidth);
79 void TRACE_surf_link_set_latency(double date, void *link, double latency)
81 if (!TRACE_is_active())
83 if (!TRACE_surf_link_is_traced(link))
87 snprintf(resource, 100, "%p", link);
88 TRACE_surf_set_resource_variable(date, "latency", resource, latency);
92 void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
94 char key[100], aux[100];
95 if (!TRACE_is_active())
97 snprintf(key, 100, "%p", action);
99 snprintf(aux, 100, "%d", src);
100 xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free);
101 snprintf(aux, 100, "%d", dst);
102 xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free);
105 int TRACE_surf_gtnets_get_src(void *action)
109 if (!TRACE_is_active())
111 snprintf(key, 100, "%p", action);
113 aux = xbt_dict_get_or_null(gtnets_src, key);
121 int TRACE_surf_gtnets_get_dst(void *action)
125 if (!TRACE_is_active())
127 snprintf(key, 100, "%p", action);
129 aux = xbt_dict_get_or_null(gtnets_dst, key);
137 void TRACE_surf_gtnets_destroy(void *action)
140 if (!TRACE_is_active())
142 snprintf(key, 100, "%p", action);
143 xbt_dict_remove(gtnets_src, key);
144 xbt_dict_remove(gtnets_dst, key);
147 void TRACE_surf_host_vivaldi_parse(char *host, double x, double y,
151 if (!TRACE_is_active() || !TRACE_platform_is_enabled())
154 snprintf(valuestr, 100, "%g", x);
155 pajeSetVariable(0, "vivaldi_x", host, valuestr);
156 snprintf(valuestr, 100, "%g", y);
157 pajeSetVariable(0, "vivaldi_y", host, valuestr);
158 snprintf(valuestr, 100, "%g", h);
159 pajeSetVariable(0, "vivaldi_h", host, valuestr);
162 void TRACE_surf_action(surf_action_t surf_action, const char *category)
164 if (!TRACE_is_active())
166 if (!TRACE_categorized ())
171 surf_action->category = xbt_strdup(category);
173 #endif /* HAVE_TRACING */