Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] valgrind's memcheck to wipe out memory leaks from the tracing system
authorLucas Schnorr <Lucas.Schnorr@imag.fr>
Sun, 8 Jan 2012 01:19:39 +0000 (02:19 +0100)
committerLucas Schnorr <Lucas.Schnorr@imag.fr>
Sun, 8 Jan 2012 01:19:39 +0000 (02:19 +0100)
and some simplifications in tracing resource utilization

src/instr/instr_config.c
src/instr/instr_paje.c
src/instr/instr_paje_trace.c
src/instr/instr_private.h
src/instr/instr_resource_utilization.c
src/instr/instr_smpi.c

index ffff7f8..13bd2b9 100644 (file)
@@ -108,6 +108,10 @@ int TRACE_end()
 
   /* destroy all data structures of tracing (and free) */
   destroyAllContainers();
+  instr_paje_free();
+  TRACE_surf_release();
+  TRACE_smpi_release();
+  xbt_dict_free(&created_categories);
 
   /* close the trace file */
   TRACE_paje_end();
index b523297..8d6cf31 100644 (file)
@@ -24,12 +24,27 @@ void instr_paje_init (container_t root)
   rootContainer = root;
 }
 
+void instr_paje_free (void)
+{
+  xbt_dict_free (&allContainers);
+  xbt_dict_free (&trivaNodeTypes);
+  xbt_dict_free (&trivaEdgeTypes);
+}
+
 static long long int new_type_id (void)
 {
   static long long int type_id = 0;
   return type_id++;
 }
 
+static void destroyValue (void *value)
+{
+  xbt_free(((val_t)value)->name);
+  xbt_free(((val_t)value)->color);
+  xbt_free(((val_t)value)->id);
+  xbt_free(value);
+}
+
 static val_t newValue (const char *valuename, const char *color, type_t father)
 {
   val_t ret = xbt_new0(s_val_t, 1);
@@ -297,11 +312,6 @@ type_t getType (const char *name, type_t father)
 
 void destroyContainer (container_t container)
 {
-  //remove me from my father
-  if (container->father){
-    xbt_dict_remove(container->father->children, container->name);
-  }
-
   XBT_DEBUG("destroy container %s", container->name);
 
   //obligation to dump previous events because they might
@@ -318,7 +328,7 @@ void destroyContainer (container_t container)
   //free
   xbt_free (container->name);
   xbt_free (container->id);
-  xbt_free (container->children);
+  xbt_dict_free (&container->children);
   xbt_free (container);
   container = NULL;
 }
@@ -344,8 +354,14 @@ static void recursiveDestroyType (type_t type)
   }
   xbt_free (type->name);
   xbt_free (type->id);
-  xbt_free (type->children);
-  xbt_free (type->values);
+  xbt_free (type->color);
+  xbt_dict_free (&type->children);
+  val_t value;
+  char *value_name;
+  xbt_dict_foreach(type->values, cursor, value_name, value) {
+    destroyValue (value);
+  }
+  xbt_dict_free (&type->values);
   xbt_free (type);
   type = NULL;
 }
index 4a60ed3..1a3b6ab 100644 (file)
@@ -169,6 +169,7 @@ void TRACE_paje_end(void)
 {
   fclose(tracing_file);
   char *filename = TRACE_get_filename();
+  xbt_dynar_free (&buffer);
   XBT_DEBUG("Filename %s is closed", filename);
 }
 
@@ -636,12 +637,15 @@ static void print_pajeNewEvent (paje_event_t event)
 static void free_paje_event (paje_event_t event)
 {
   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, event->event_type, event->timestamp);
-  if (event->event_type == PAJE_StartLink){
+  switch (event->event_type){
+  case PAJE_StartLink:
     xbt_free (((startLink_t)(event->data))->value);
     xbt_free (((startLink_t)(event->data))->key);
-  }else if (event->event_type == PAJE_EndLink){
+    break;
+  case PAJE_EndLink:
     xbt_free (((endLink_t)(event->data))->value);
     xbt_free (((endLink_t)(event->data))->key);
+    break;
   }
   xbt_free (event->data);
   xbt_free (event);
index ffdaac2..896e7df 100644 (file)
@@ -209,6 +209,7 @@ char *getContainerIdByName (const char *name);
 char *getVariableTypeIdByName (const char *name, type_t father);
 container_t getRootContainer (void);
 void instr_paje_init (container_t root);
+void instr_paje_free (void);
 type_t getRootType (void);
 type_t getContainerType (const char *name, type_t father);
 type_t getEventType (const char *name, const char *color, type_t father);
index 4c4b2e3..3b19236 100644 (file)
@@ -18,40 +18,29 @@ static void __TRACE_surf_check_variable_set_to_zero(double now,
                                                     const char *variable,
                                                     const char *resource)
 {
-  /* 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);
+  /*
+   * To trace resource utilization, we use pajeAddVariable and pajeSubVariable only.
+   * The Paje simulator needs a pajeSetVariable in the first place so it knows
+   * the initial value of all variables for subsequent adds/subs. If we don't do
+   * so, the first pajeAddVariable is added to a non-determined value within
+   * the Paje simulator, causing analysis problems.
+   */
+
+  // create a key considering the resource and variable
+  int n = strlen(variable)+strlen(resource)+1;
+  char *key = (char*)xbt_malloc(n*sizeof(char));
+  snprintf (key, n, "%s%s", resource, variable);
+
+  // check if key exists: if it doesn't, set the variable to zero and mark this in the dict
+  if (!xbt_dict_get_or_null(platform_variables, key)) {
     container_t container = getContainerByName (resource);
     type_t type = getVariableType (variable, NULL, container->type);
     new_pajeSetVariable (now, container, type, 0);
-    xbt_dict_set(platform_variables, resource, array, NULL);
-  } 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 (TRACE_categorized ()){
-        container_t container = getContainerByName (resource);
-        type_t type = getVariableType (variable, NULL, container->type);
-        new_pajeSetVariable (now, container, type, 0);
-      }
-    }
+    xbt_dict_set(platform_variables, key, "", NULL);
   }
-  /* end of check */
+  xbt_free(key);
 }
 
-
-
 /*
 static void __TRACE_A_event(smx_action_t action, double now, double delta,
                             const char *variable, const char *resource,
@@ -152,10 +141,11 @@ void TRACE_surf_host_set_utilization(const char *resource,
 
 void TRACE_surf_resource_utilization_alloc()
 {
-  platform_variables = xbt_dict_new_homogeneous(xbt_dynar_free_voidp);
+  platform_variables = xbt_dict_new_homogeneous(NULL);
 }
 
 void TRACE_surf_resource_utilization_release()
 {
+  xbt_dict_free(&platform_variables);
 }
 #endif /* HAVE_TRACING */
index d4fab07..167b6f5 100644 (file)
@@ -148,6 +148,8 @@ void TRACE_smpi_start(void)
 
 void TRACE_smpi_release(void)
 {
+  xbt_dict_free(&keys);
+  xbt_dict_free(&process_category);
   if (!TRACE_smpi_is_enabled()) return;
 
   TRACE_surf_release();