Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] pay attention to configuration options when tracing
[simgrid.git] / src / instr / instr_surf.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "instr/instr_private.h"
8 #include "surf/surf_private.h"
9
10 #ifdef HAVE_TRACING
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_surf, instr, "Tracing Surf");
13
14 static xbt_dict_t resource_variables;   /* (host|link)#variable -> value */
15
16 /* to trace gtnets */
17 static xbt_dict_t gtnets_src;   /* %p (action) -> %s */
18 static xbt_dict_t gtnets_dst;   /* %p (action) -> %s */
19
20 void TRACE_surf_alloc(void)
21 {
22   resource_variables = xbt_dict_new();
23   gtnets_src = xbt_dict_new();
24   gtnets_dst = xbt_dict_new();
25
26   TRACE_surf_resource_utilization_alloc();
27 }
28
29 void TRACE_surf_release(void)
30 {
31   TRACE_surf_resource_utilization_release();
32   instr_destroy_platform();
33 }
34
35 static void TRACE_surf_set_resource_variable(double date,
36                                              const char *variable,
37                                              const char *resource,
38                                              double value)
39 {
40   char value_str[INSTR_DEFAULT_STR_SIZE];
41   snprintf(value_str, 100, "%f", value);
42   pajeSetVariable(date, variable, resource, value_str);
43 }
44
45 void TRACE_surf_host_set_power(double date, const char *resource,
46                                double power)
47 {
48   if (!TRACE_is_active())
49     return;
50
51   char *host_type = instr_host_type (resource);
52   char variable_type[INSTR_DEFAULT_STR_SIZE];
53   snprintf (variable_type, INSTR_DEFAULT_STR_SIZE, "power-%s", host_type);
54
55   TRACE_surf_set_resource_variable(date, variable_type, resource, power);
56 }
57
58 void TRACE_surf_link_set_bandwidth(double date, const char *resource, double bandwidth)
59 {
60   if (!TRACE_is_active())
61     return;
62
63   char *link_type = instr_link_type (resource);
64   char variable_type[INSTR_DEFAULT_STR_SIZE];
65   snprintf (variable_type, INSTR_DEFAULT_STR_SIZE, "bandwidth-%s", link_type);
66
67   TRACE_surf_set_resource_variable(date, variable_type, resource, bandwidth);
68 }
69
70 //FIXME: this function is not used (latency availability traces support exists in surf network models?)
71 void TRACE_surf_link_set_latency(double date, const char *resource, double latency)
72 {
73   if (!TRACE_is_active())
74     return;
75
76   char *link_type = instr_link_type (resource);
77   char variable_type[INSTR_DEFAULT_STR_SIZE];
78   snprintf (variable_type, INSTR_DEFAULT_STR_SIZE, "latency-%s", link_type);
79
80   TRACE_surf_set_resource_variable(date, variable_type, resource, latency);
81 }
82
83 /* to trace gtnets */
84 void TRACE_surf_gtnets_communicate(void *action, int src, int dst)
85 {
86   char key[100], aux[100];
87   if (!TRACE_is_active())
88     return;
89   snprintf(key, 100, "%p", action);
90
91   snprintf(aux, 100, "%d", src);
92   xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free);
93   snprintf(aux, 100, "%d", dst);
94   xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free);
95 }
96
97 int TRACE_surf_gtnets_get_src(void *action)
98 {
99   char key[100];
100   char *aux = NULL;
101   if (!TRACE_is_active())
102     return -1;
103   snprintf(key, 100, "%p", action);
104
105   aux = xbt_dict_get_or_null(gtnets_src, key);
106   if (aux) {
107     return atoi(aux);
108   } else {
109     return -1;
110   }
111 }
112
113 int TRACE_surf_gtnets_get_dst(void *action)
114 {
115   char key[100];
116   char *aux = NULL;
117   if (!TRACE_is_active())
118     return -1;
119   snprintf(key, 100, "%p", action);
120
121   aux = xbt_dict_get_or_null(gtnets_dst, key);
122   if (aux) {
123     return atoi(aux);
124   } else {
125     return -1;
126   }
127 }
128
129 void TRACE_surf_gtnets_destroy(void *action)
130 {
131   char key[100];
132   if (!TRACE_is_active())
133     return;
134   snprintf(key, 100, "%p", action);
135   xbt_dict_remove(gtnets_src, key);
136   xbt_dict_remove(gtnets_dst, key);
137 }
138
139 void TRACE_surf_action(surf_action_t surf_action, const char *category)
140 {
141   if (!TRACE_is_active())
142     return;
143   if (!TRACE_categorized ())
144     return;
145   if (!category)
146     return;
147
148   surf_action->category = xbt_strdup(category);
149 }
150 #endif /* HAVE_TRACING */