Randoms + Metaprogramming test.
Added randoms using C++ templates. Might be able to change the profiler class to a template template without the need of the config file.v1
parent
4330e9940d
commit
1587f342ad
|
@ -11,6 +11,7 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <blt/config.h>
|
#include <blt/config.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
#ifdef PHMAP_ENABLED
|
#ifdef PHMAP_ENABLED
|
||||||
#include <parallel_hashmap/phmap.h>
|
#include <parallel_hashmap/phmap.h>
|
||||||
|
@ -30,7 +31,7 @@ namespace BLT {
|
||||||
};
|
};
|
||||||
#ifdef PHMAP_ENABLED
|
#ifdef PHMAP_ENABLED
|
||||||
typedef phmap::parallel_flat_hash_map<std::string_view, CaptureInterval> INTERVAL_MAP;
|
typedef phmap::parallel_flat_hash_map<std::string_view, CaptureInterval> INTERVAL_MAP;
|
||||||
typedef phmap::parallel_flat_hash_map<std::string_view, CapturePoint> POINT_MAP;
|
typedef phmap::parallel_flat_hash_map<std::string_view, std::queue<CapturePoint>> POINT_MAP;
|
||||||
typedef phmap::parallel_flat_hash_map<std::string_view, POINT_MAP> POINT_HISTORY_MAP;
|
typedef phmap::parallel_flat_hash_map<std::string_view, POINT_MAP> POINT_HISTORY_MAP;
|
||||||
typedef phmap::parallel_flat_hash_map<int, std::string_view> ORDER_MAP;
|
typedef phmap::parallel_flat_hash_map<int, std::string_view> ORDER_MAP;
|
||||||
#else
|
#else
|
||||||
|
@ -43,8 +44,8 @@ namespace BLT {
|
||||||
class Profiler {
|
class Profiler {
|
||||||
private:
|
private:
|
||||||
INTERVAL_MAP intervals{};
|
INTERVAL_MAP intervals{};
|
||||||
POINT_MAP points{};
|
std::queue<CapturePoint> points{};
|
||||||
POINT_MAP cyclicPoints{};
|
std::queue<CapturePoint> cyclicPoints{};
|
||||||
POINT_HISTORY_MAP cyclicPointsHistory{};
|
POINT_HISTORY_MAP cyclicPointsHistory{};
|
||||||
ORDER_MAP order{};
|
ORDER_MAP order{};
|
||||||
|
|
||||||
|
@ -55,6 +56,11 @@ namespace BLT {
|
||||||
void finishCycle();
|
void finishCycle();
|
||||||
void startInterval(const std::string_view& name);
|
void startInterval(const std::string_view& name);
|
||||||
void endInterval(const std::string_view& name);
|
void endInterval(const std::string_view& name);
|
||||||
|
void profilerPoint();
|
||||||
|
/**
|
||||||
|
* Uses a separate tracking device that will be reset when finishCycle(); is called.
|
||||||
|
*/
|
||||||
|
void profilerPointCyclic();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,11 @@ namespace BLT {
|
||||||
int headIndex = 0;
|
int headIndex = 0;
|
||||||
T* data = new T[size];
|
T* data = new T[size];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expands the internal array to the new size, copying over the data and shifting its minimal position to index 0
|
||||||
|
* and deletes the old array from memory.
|
||||||
|
* @param newSize new size of the internal array
|
||||||
|
*/
|
||||||
void expand(int newSize){
|
void expand(int newSize){
|
||||||
auto tempData = new T[newSize];
|
auto tempData = new T[newSize];
|
||||||
for (int i = 0; i < size - headIndex; i++)
|
for (int i = 0; i < size - headIndex; i++)
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Created by Brett on 04/01/23.
|
||||||
|
* Licensed under GNU General Public License V3.0
|
||||||
|
* See LICENSE file for license detail
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLT_RANDOM_H
|
||||||
|
#define BLT_RANDOM_H
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
namespace BLT {
|
||||||
|
/**
|
||||||
|
* Creates a container class for generating random number distributions
|
||||||
|
* @tparam T numeric type
|
||||||
|
* @tparam dist std::uniform_real_distribution or std::uniform_int_distribution
|
||||||
|
*/
|
||||||
|
template<typename T, template<typename = T> typename dist = std::uniform_real_distribution>
|
||||||
|
class Random {
|
||||||
|
private:
|
||||||
|
std::random_device rd; // obtain a random number from hardware
|
||||||
|
std::mt19937 gen;
|
||||||
|
dist<T>* distribution = nullptr;
|
||||||
|
public:
|
||||||
|
explicit Random(T min = (T)0, T max = (T)1, long seed = 0): gen(std::mt19937(seed)){
|
||||||
|
distribution = new dist(min, max);
|
||||||
|
}
|
||||||
|
T get(){
|
||||||
|
return *distribution(gen);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //BLT_RANDOM_H
|
|
@ -29,4 +29,13 @@ namespace BLT {
|
||||||
intervals[name].end = {getCurrentTimeNanoseconds()};
|
intervals[name].end = {getCurrentTimeNanoseconds()};
|
||||||
order[lastOrder++] = name;
|
order[lastOrder++] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Profiler::profilerPoint() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Profiler::profilerPointCyclic() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
/*
|
||||||
|
* Created by Brett on 04/01/23.
|
||||||
|
* Licensed under GNU General Public License V3.0
|
||||||
|
* See LICENSE file for license detail
|
||||||
|
*/
|
||||||
|
#include <blt/std/random.h>
|
Loading…
Reference in New Issue