Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix process_time handling
[simgrid.git] / src / mc / mc_record.cpp
index c8d5a07..479b8dc 100644 (file)
@@ -1,36 +1,44 @@
-/* Copyright (c) 2014. The SimGrid Team.
+/* Copyright (c) 2014-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstring>
+#include <cstdio>
+#include <cstdlib>
 
-#include <xbt.h>
-#include <simgrid/simix.h>
+#include <xbt/fifo.h>
+#include <xbt/log.h>
+#include <xbt/sysdep.h>
 
-#include "mc_replay.h"
-#include "mc_record.h"
-#include "mc_base.h"
+#include "simgrid/simix.h"
 
-#ifdef HAVE_MC
-#include "mc_private.h"
-#include "mc_state.h"
-#include "mc_smx.h"
-#include "mc_liveness.h"
-#endif
+#include "src/simix/smx_private.h"
+#include "src/simix/smx_process_private.h"
 
-extern "C" {
+#include "src/mc/mc_replay.h"
+#include "src/mc/mc_record.h"
+#include "src/mc/mc_base.h"
+
+#if HAVE_MC
+#include "src/mc/mc_request.h"
+#include "src/mc/mc_private.h"
+#include "src/mc/mc_state.h"
+#include "src/mc/mc_smx.h"
+#include "src/mc/mc_liveness.h"
+#endif
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
   " Logging specific to MC record/replay facility");
 
-char* MC_record_path = NULL;
+extern "C" {
 
-void MC_record_replay(mc_record_item_t start, size_t len)
+char* MC_record_path = nullptr;
+
+void MC_record_replay(mc_record_item_t start, std::size_t len)
 {
-  MC_wait_for_requests();
+  simgrid::mc::wait_for_requests();
   mc_record_item_t end = start + len;
 
   // Choose the recorded simcall and execute it:
@@ -49,12 +57,13 @@ void MC_record_replay(mc_record_item_t start, size_t len)
     smx_simcall_t simcall = &(process->simcall);
     if(!simcall || simcall->call == SIMCALL_NONE)
       xbt_die("No simcall for this process.");
-    if (!MC_request_is_visible(simcall) || !MC_request_is_enabled(simcall))
+    if (!simgrid::mc::request_is_visible(simcall)
+        || !simgrid::mc::request_is_enabled(simcall))
       xbt_die("Unexpected simcall.");
 
     // Execute the request:
     SIMIX_simcall_handle(simcall, item->value);
-    MC_wait_for_requests();
+    simgrid::mc::wait_for_requests();
   }
 }
 
@@ -62,9 +71,9 @@ xbt_dynar_t MC_record_from_string(const char* data)
 {
   XBT_INFO("path=%s", data);
   if (!data || !data[0])
-    return NULL;
+    return nullptr;
 
-  xbt_dynar_t dynar = xbt_dynar_new(sizeof(s_mc_record_item_t), NULL);
+  xbt_dynar_t dynar = xbt_dynar_new(sizeof(s_mc_record_item_t), nullptr);
 
   const char* current = data;
   while (*current) {
@@ -76,8 +85,8 @@ xbt_dynar_t MC_record_from_string(const char* data)
     xbt_dynar_push(dynar, &item);
 
     // Find next chunk:
-    const char* end = strchr(current, ';');
-    if(end==NULL)
+    const char* end = std::strchr(current, ';');
+    if(end == nullptr)
       break;
     else
       current = end + 1;
@@ -87,20 +96,20 @@ xbt_dynar_t MC_record_from_string(const char* data)
 
 fail:
   xbt_dynar_free(&dynar);
-  return NULL;
+  return nullptr;
 }
 
-#ifdef HAVE_MC
+#if HAVE_MC
 static char* MC_record_stack_to_string_liveness(xbt_fifo_t stack)
 {
   char* buffer;
-  size_t size;
-  FILE* file = open_memstream(&buffer, &size);
+  std::size_t size;
+  std::FILE* file = open_memstream(&buffer, &size);
 
   xbt_fifo_item_t item;
   xbt_fifo_item_t start = xbt_fifo_get_last_item(stack);
   for (item = start; item; item = xbt_fifo_get_prev_item(item)) {
-    mc_pair_t pair = (mc_pair_t) xbt_fifo_get_item_content(item);
+    simgrid::mc::Pair* pair = (simgrid::mc::Pair*) xbt_fifo_get_item_content(item);
     int value;
     smx_simcall_t req = MC_state_get_executed_request(pair->graph_state, &value);
     if (req && req->call != SIMCALL_NONE) {
@@ -110,13 +119,13 @@ static char* MC_record_stack_to_string_liveness(xbt_fifo_t stack)
       // Serialization the (pid, value) pair:
       const char* sep = (item!=start) ? ";" : "";
       if (value)
-        fprintf(file, "%s%u/%u", sep, pid, value);
+        std::fprintf(file, "%s%u/%u", sep, pid, value);
       else
-        fprintf(file, "%s%u", sep, pid);
+        std::fprintf(file, "%s%u", sep, pid);
     }
   }
 
-  fclose(file);
+  std::fclose(file);
   return buffer;
 }
 
@@ -134,8 +143,8 @@ char* MC_record_stack_to_string(xbt_fifo_t stack)
   }
 
   char* buffer;
-  size_t size;
-  FILE* file = open_memstream(&buffer, &size);
+  std::size_t size;
+  std::FILE* file = open_memstream(&buffer, &size);
 
   xbt_fifo_item_t item;
   for (item = start; item; item = xbt_fifo_get_prev_item(item)) {
@@ -150,12 +159,12 @@ char* MC_record_stack_to_string(xbt_fifo_t stack)
     // Serialization the (pid, value) pair:
     const char* sep = (item!=start) ? ";" : "";
     if (value)
-      fprintf(file, "%s%u/%u", sep, pid, value);
+      std::fprintf(file, "%s%u/%u", sep, pid, value);
     else
-      fprintf(file, "%s%u", sep, pid);
+      std::fprintf(file, "%s%u", sep, pid);
   }
 
-  fclose(file);
+  std::fclose(file);
   return buffer;
 }
 
@@ -164,22 +173,19 @@ void MC_record_dump_path(xbt_fifo_t stack)
   if (MC_record_is_active()) {
     char* path = MC_record_stack_to_string(stack);
     XBT_INFO("Path = %s", path);
-    free(path);
+    std::free(path);
   }
 }
 #endif
 
 void MC_record_replay_from_string(const char* path_string)
 {
+  simgrid::mc::processes_time.resize(simix_process_maxpid);
   xbt_dynar_t path = MC_record_from_string(path_string);
   mc_record_item_t start = &xbt_dynar_get_as(path, 0, s_mc_record_item_t);
   MC_record_replay(start, xbt_dynar_length(path));
   xbt_dynar_free(&path);
-}
-
-void MC_record_replay_init()
-{
-  mc_time = xbt_new0(double, simix_process_maxpid);
+  simgrid::mc::processes_time.clear();
 }
 
 }