22 #include "MARandomness.hpp" 25 #include <MCThreadLocalData.hpp> 26 #include <MCTimer.hpp> 28 #include <boost/algorithm/string/replace.hpp> 29 #include <boost/tuple/tuple.hpp> 35 typedef boost::tuple<int64_t, std::string, MC::IntList> RandomPointType;
36 typedef std::vector<RandomPointType> RandomPointList;
41 void CheckStaticRandomnessVariables()
43 if (unlikely(!RandomPoints.get()))
45 RandomPoints.reset(
new RandomPointList);
53 MC::IntList RandomNumbers;
54 unsigned int Count = count == 0 ? 1 : count;
56 for (
unsigned int i = 0; i < Count; ++i)
58 RandomNumbers.push_back(MCRandComplex<int>(min, max));
70 CheckStaticRandomnessVariables();
71 Numbers.push_back(number);
72 #if defined(__clang__) 76 boost::replace_all(ID,
"std::string",
"std::__cxx11::string");
77 RandomPoints->push_back(RandomPointType(timestamp, ID, Numbers));
79 RandomPoints->push_back(RandomPointType(timestamp,
id, Numbers));
85 const MC::IntList& numbers)
87 CheckStaticRandomnessVariables();
88 #if defined(__clang__) 92 boost::replace_all(ID,
"std::string",
"std::__cxx11::string");
93 RandomPoints->push_back(RandomPointType(timestamp, ID, numbers));
95 RandomPoints->push_back(RandomPointType(timestamp,
id, numbers));
103 unsigned int Count = count == 0 ? 1 : count;
105 ::RandomPointList& RandomPointList = *RandomPoints.get();
107 #if defined(__clang__) 109 boost::replace_all(ID,
"std::string",
"std::__cxx11::string");
111 CheckStaticRandomnessVariables();
114 while (!RandomPointList.empty() && RandomPointList.begin()->get<0>() < CurrentTime-5*1000)
116 RandomPointList.erase(RandomPointList.begin());
119 for (
auto iter = RandomPointList.begin(); iter != RandomPointList.end(); ++iter)
122 if (iter->get<0>() < CurrentTime-5*1000)
125 MC_WARNING(
"Unable to find the random point (%s)", ID.c_str());
126 return MC::IntList(Count, min);
128 if (iter->get<1>() == ID)
130 MC::IntList Numbers = iter->get<2>();
132 RandomPointList.erase(iter);
137 MC_WARNING(
"Unable to find the random point (%s)", ID.c_str());
138 return MC::IntList(Count, min);
144 CheckStaticRandomnessVariables();
145 return !RandomPoints->empty();
151 std::string LogMessage =
"Random point: ["+
id+
'|';
153 for (
unsigned int i = 0; i < numbers.size(); ++i)
155 LogMessage +=
MCToStr(numbers[i]);
156 if (i < numbers.size()-1)
160 MC_LOG(
"%s", LogMessage.c_str());
static void LogRandomPoint(const std::string &id, const MC::IntList &numbers)
Log a random point.
#define MC_WARNING(...)
Warning macro.
std::string MCToStr(const T value, bool hex_manipulator=false)
Convert an other type to string with std::stringstream.
static void RegisterRandomPoint(int64_t timestamp, const std::string &id, const int number)
Register a random point with a single number.
static MC::IntList GenerateRandomPoint(const std::string &id, unsigned int count, int min, int max)
Generate a random point.
static bool IsAnyRegisteredPoint()
Check if there is any registered random point.
static int64_t GetElapsedSystemTime(bool relative_time=true)
Get the system time.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
#define MC_LOG(...)
Debug macro.
static MC::IntList QueryRandomPoint(const std::string &id, unsigned int count, int min)
Query a random point.