Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new variable for surf_action_t to contain its tracing category
[simgrid.git] / src / instr / surf_instr.c
index a559cf7..bc89131 100644 (file)
@@ -5,6 +5,7 @@
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "instr/private.h"
+#include "surf/surf_private.h"
 
 #ifdef HAVE_TRACING
 
@@ -14,58 +15,39 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(tracing_surf,tracing,"Tracing Surf");
 
 static xbt_dict_t created_links;
 static xbt_dict_t host_containers;
-static xbt_dict_t platform_variables; /* host or link name -> array of categories */
 static xbt_dict_t resource_variables; /* (host|link)#variable -> value */
 
 /* to trace gtnets */
 static xbt_dict_t gtnets_src; /* %p (action) -> %s */
 static xbt_dict_t gtnets_dst; /* %p (action) -> %s */
 
-void __TRACE_surf_init (void)
+void TRACE_surf_alloc (void)
 {
   created_links = xbt_dict_new();
-  platform_variables = xbt_dict_new();
   host_containers = xbt_dict_new();
   resource_variables = xbt_dict_new ();
   gtnets_src = xbt_dict_new ();
   gtnets_dst = xbt_dict_new ();
-  __TRACE_surf_resource_utilization_initialize();
-}
 
-void __TRACE_surf_finalize (void)
-{
-  __TRACE_surf_resource_utilization_finalize();
+  TRACE_surf_resource_utilization_alloc();
 }
 
-void __TRACE_surf_check_variable_set_to_zero (double now, const char *variable, const char *resource)
+void TRACE_surf_release (void)
 {
-  /* check if we have to set it to 0 */
-  if (!xbt_dict_get_or_null (platform_variables, resource)){
-    xbt_dynar_t array = xbt_dynar_new(sizeof(char*), xbt_free);
-    char *var_cpy = xbt_strdup(variable);
-    xbt_dynar_push (array, &var_cpy);
-    if (IS_TRACING_PLATFORM) pajeSetVariable (now, variable, resource, "0");
-    xbt_dict_set (platform_variables, resource, array, xbt_dynar_free_voidp);
-  }else{
-    xbt_dynar_t array = xbt_dict_get (platform_variables, resource);
-    unsigned int i;
-    char* cat;
-    int flag = 0;
-    xbt_dynar_foreach (array, i, cat) {
-      if (strcmp(variable, cat)==0){
-        flag = 1;
-      }
-    }
-    if (flag==0){
-      char *var_cpy = xbt_strdup(variable);
-      xbt_dynar_push (array, &var_cpy);
-      if (IS_TRACING_PLATFORM) pajeSetVariable (now, variable, resource, "0");
-    }
+  char *key, *value;
+  xbt_dict_cursor_t cursor = NULL;
+  TRACE_surf_resource_utilization_release();
+
+  /* get all host from host_containers */
+  xbt_dict_foreach(host_containers, cursor, key, value) {
+    pajeDestroyContainer (MSG_get_clock(), "HOST", key);
+  }
+  xbt_dict_foreach(created_links, cursor, key, value) {
+    pajeDestroyContainer (MSG_get_clock(), "LINK", key);
   }
-  /* end of check */
 }
 
-void __TRACE_surf_set_resource_variable (double date, const char *variable, const char *resource, double value)
+static void TRACE_surf_set_resource_variable (double date, const char *variable, const char *resource, double value)
 {
        char aux[100], key[100];
        char *last_value = NULL;
@@ -92,19 +74,19 @@ void __TRACE_surf_set_resource_variable (double date, const char *variable, cons
  * main: create LINK container, set initial bandwidth and latency
  * return: void
  */
-void TRACE_surf_link_declaration (char *name, double bw, double lat)
+void TRACE_surf_link_declaration (void *link, char *name, double bw, double lat)
 {
   if (!IS_TRACING) return;
 
-  if (strcmp (name, "__loopback__")==0 ||
-      strcmp (name, "loopback")==0){ //ignore loopback updates
-    return;
-  }
+  //filter out loopback
+  if (!strcmp (name, "loopback") || !strcmp (name, "__loopback__")) return;
 
-  pajeCreateContainer (SIMIX_get_clock(), name, "LINK", "platform", name);
-  xbt_dict_set (created_links, name, xbt_strdup ("1"), xbt_free);
-  TRACE_surf_link_set_bandwidth (SIMIX_get_clock(), name, bw);
-  TRACE_surf_link_set_latency (SIMIX_get_clock(), name, lat);
+  char alias[100];
+  snprintf (alias, 100, "%p", link);
+  pajeCreateContainer (SIMIX_get_clock(), alias, "LINK", "platform", name);
+  xbt_dict_set (created_links, alias, xbt_strdup ("1"), xbt_free);
+  TRACE_surf_link_set_bandwidth (SIMIX_get_clock(), link, bw);
+  TRACE_surf_link_set_latency (SIMIX_get_clock(), link, lat);
 }
 
 /*
@@ -126,17 +108,25 @@ void TRACE_surf_host_declaration (char *name, double power)
 
 void TRACE_surf_host_set_power (double date, char *resource, double power)
 {
-  __TRACE_surf_set_resource_variable (date, "power", resource, power);
+  TRACE_surf_set_resource_variable (date, "power", resource, power);
 }
 
-void TRACE_surf_link_set_bandwidth (double date, char *resource, double bandwidth)
+void TRACE_surf_link_set_bandwidth (double date, void *link, double bandwidth)
 {
-  __TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth);
+  if (!TRACE_surf_link_is_traced (link)) return;
+
+  char resource[100];
+  snprintf (resource, 100, "%p", link);
+  TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth);
 }
 
-void TRACE_surf_link_set_latency (double date, char *resource, double latency)
+void TRACE_surf_link_set_latency (double date, void *link, double latency)
 {
-  __TRACE_surf_set_resource_variable (date, "latency", resource, latency);
+  if (!TRACE_surf_link_is_traced (link)) return;
+
+  char resource[100];
+  snprintf (resource, 100, "%p", link);
+  TRACE_surf_set_resource_variable (date, "latency", resource, latency);
 }
 
 /* to trace gtnets */
@@ -191,26 +181,6 @@ void TRACE_surf_gtnets_destroy (void *action)
   xbt_dict_remove (gtnets_dst, key);
 }
 
-void TRACE_surf_link_missing (void)
-{
-  CRITICAL0("The trace cannot be done because "
-                "the platform you are using contains "
-                "routes with more than one link.");
-  THROW0(tracing_error, TRACE_ERROR_COMPLEX_ROUTES, "Tracing failed");
-}
-
-void TRACE_msg_clean (void)
-{
-  char *key, *value;
-  xbt_dict_cursor_t cursor = NULL;
-  __TRACE_surf_finalize();
-
-  /* get all host from host_containers */
-  xbt_dict_foreach(host_containers, cursor, key, value) {
-    pajeDestroyContainer (MSG_get_clock(), "HOST", key);
-  }
-}
-
 void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h)
 {
        char valuestr[100];
@@ -224,4 +194,51 @@ void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h)
   pajeSetVariable (0, "vivaldi_h", host, valuestr);
 }
 
+extern routing_global_t global_routing;
+void TRACE_surf_save_onelink (void)
+{
+  if (!IS_TRACING) return;
+
+  //get the onelinks from the parsed platform
+  xbt_dynar_t onelink_routes = global_routing->get_onelink_routes();
+  if (!onelink_routes) return;
+
+  //save them in trace file
+  onelink_t onelink;
+  unsigned int iter;
+  xbt_dynar_foreach(onelink_routes, iter, onelink) {
+    char *src = onelink->src;
+    char *dst = onelink->dst;
+    void *link = onelink->link_ptr;
+
+    if (TRACE_surf_link_is_traced (link)){
+      char resource[100];
+      snprintf (resource, 100, "%p", link);
+
+      pajeNewEvent (0.1, "source", resource, src);
+      pajeNewEvent (0.1, "destination", resource, dst);
+    }
+  }
+}
+
+int TRACE_surf_link_is_traced (void *link)
+{
+  char alias[100];
+  snprintf (alias, 100, "%p", link);
+  if (xbt_dict_get_or_null (created_links, alias)){
+    return 1;
+  }else{
+    return 0;
+  }
+}
+
+void TRACE_surf_action (surf_action_t surf_action, const char *category)
+{
+  if (!IS_TRACING_PLATFORM) return;
+  if (!category){
+    xbt_die ("invalid tracing category");
+  }
+  surf_action->category = xbt_new (char, strlen (category)+1);
+  strncpy (surf_action->category, category, strlen(category)+1);
+}
 #endif