Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add "override" specifier.
[simgrid.git] / src / instr / instr_interface.cpp
index 5881002..b859b8d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2019. 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. */
@@ -9,6 +9,8 @@
 #include "src/surf/surf_private.hpp"
 #include "surf/surf.hpp"
 #include <algorithm>
+#include <cmath>
+#include <random>
 
 enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
 
@@ -88,9 +90,11 @@ void TRACE_category_with_color (const char *category, const char *color)
   std::string final_color;
   if (not color) {
     //generate a random color
-    double red = drand48();
-    double green = drand48();
-    double blue = drand48();
+    static std::default_random_engine rnd_engine;
+    std::uniform_real_distribution<double> prng(0.0, std::nextafter(1.0, 2.0));
+    double red   = prng(rnd_engine);
+    double green = prng(rnd_engine);
+    double blue  = prng(rnd_engine);
     final_color  = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
   }else{
     final_color = std::string(color);
@@ -137,8 +141,7 @@ void TRACE_declare_mark(const char *mark_type)
   if (not TRACE_is_enabled() || not TRACE_needs_platform())
     return;
 
-  if (not mark_type)
-    THROWF (tracing_error, 1, "mark_type is nullptr");
+  xbt_assert(mark_type, "mark_type is nullptr");
 
   //check if mark_type is already declared
   if (declared_marks.find(mark_type) != declared_marks.end()) {
@@ -171,10 +174,8 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar
   if (not TRACE_is_enabled() || not TRACE_needs_platform())
     return;
 
-  if (not mark_type)
-    THROWF (tracing_error, 1, "mark_type is nullptr");
-  if (not mark_value)
-    THROWF (tracing_error, 1, "mark_value is nullptr");
+  xbt_assert(mark_type, "mark_type is nullptr");
+  xbt_assert(mark_value, "mark_value is nullptr");
 
   simgrid::instr::EventType* type =
       static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::get_root()->type_->by_name(mark_type));
@@ -226,10 +227,8 @@ void TRACE_mark(const char *mark_type, const char *mark_value)
   if (not TRACE_is_enabled() || not TRACE_needs_platform())
     return;
 
-  if (not mark_type)
-    THROWF (tracing_error, 1, "mark_type is nullptr");
-  if (not mark_value)
-    THROWF (tracing_error, 1, "mark_value is nullptr");
+  xbt_assert(mark_type, "mark_type is nullptr");
+  xbt_assert(mark_value, "mark_value is nullptr");
 
   //check if mark_type is already declared
   simgrid::instr::EventType* type =
@@ -288,7 +287,6 @@ static void instr_user_variable(double time, const char* resource, const char* v
           break;
         default:
           THROW_IMPOSSIBLE;
-          break;
       }
     }
   }