timnicolas / bomberman

3d remake of the classic game Bomberman in C++ with OpenGL.
https://tnicolas42.github.io/bomberman
MIT License
7 stars 0 forks source link

getStats functions #236

Closed zer0nim closed 4 years ago

zer0nim commented 4 years ago

J'ai repris les fonctions de stats d'appels de fonctions qu'on avais dans ft_vox

Headers:

// -- getStats for clasic functions --------------------------------------------

// return non void
template<typename RetT, typename ...Args>
RetT getStats(std::string name, RetT (&func)(Args...), Args... args);

// return void
template<typename ...Args>
void getStatsVoid(std::string name, void (&func)(Args...), Args... args);

// -- getStats for member function ---------------------------------------------

// return non void
template<typename RetT, typename ClassT, typename ...Args>
RetT getStatsM(std::string name, ClassT &obj, RetT (ClassT::*func)(Args...), Args... args);

// return void
template<typename ClassT, typename ...Args>
void getStatsMVoid(std::string name, ClassT &obj, void (ClassT::*func)(Args...), Args... args);

Ça fonctionne que pour les fonctions publiques par contre

Exemple d'usage:

-  bool a = hey(42);
+  bool a = getStats<bool, int>("hey", &hey, 42);
-  heyRetVoid(42);
+  getStatsVoid<bool, int>("heyRetVoid", &heyRetVoid, 42);
-  this->calcGreedyChunk();
+  getStatsMVoid<GreedyChunk3>("calcGreedyChunk", *this, &GreedyChunk3::calcGreedyChunk);
- _sceneMap[_scene]->update()
+ getStatsM<bool, AScene>("update", *_sceneMap[_scene], AScene::update)

J'ai fait un test dans le programe sur SceneGame update/draw dans le dernier level, voilà le retour:

[DEBUG]: functions calls stats:
[DEBUG]: SceneGame update{
[DEBUG]:   function called: 3887 times
[DEBUG]:   total exec time: 3.85241299s
[DEBUG]:   average: 0.00099110s
[DEBUG]:   min: 0.00000441s
[DEBUG]:   min: 0.02475878s
[DEBUG]: }
[DEBUG]: SceneGame draw{
[DEBUG]:   function called: 3887 times
[DEBUG]:   total exec time: 119.71526061s
[DEBUG]:   average: 0.03079888s
[DEBUG]:   min: 0.01683456s
[DEBUG]:   min: 0.06699984s
[DEBUG]: }

(revenez un commit avant si vous voulez tester)