diff options
author | Gael Guennebaud <g.gael@free.fr> | 2008-07-09 14:04:48 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2008-07-09 14:04:48 +0000 |
commit | 28539e7597c643dbc2b8d4f49dd16bd86fb7251f (patch) | |
tree | 3bfb96ae898f0afc943a388edcc83c27d28d5b3a /bench/btl/generic_bench/timers | |
parent | 5f55ab524cf0aad34dd6884bcae09eaa6c43c247 (diff) |
imported a reworked version of BTL (Benchmark for Templated Libraries).
the modifications to initial code follow:
* changed build system from plain makefiles to cmake
* added eigen2 (4 versions: vec/novec and fixed/dynamic), GMM++, MTL4 interfaces
* added "transposed matrix * vector" product action
* updated blitz interface to use condensed products instead of hand coded loops
* removed some deprecated interfaces
* changed default storage order to column major for all libraries
* new generic bench timer strategy which is supposed to be more accurate
* various code clean-up
Diffstat (limited to 'bench/btl/generic_bench/timers')
-rw-r--r-- | bench/btl/generic_bench/timers/STL_perf_analyzer.hh | 82 | ||||
-rw-r--r-- | bench/btl/generic_bench/timers/STL_timer.hh | 78 | ||||
-rw-r--r-- | bench/btl/generic_bench/timers/mixed_perf_analyzer.hh | 73 | ||||
-rw-r--r-- | bench/btl/generic_bench/timers/portable_perf_analyzer.hh | 98 | ||||
-rw-r--r-- | bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh | 134 | ||||
-rwxr-xr-x | bench/btl/generic_bench/timers/portable_timer.hh | 103 | ||||
-rw-r--r-- | bench/btl/generic_bench/timers/x86_perf_analyzer.hh | 108 | ||||
-rw-r--r-- | bench/btl/generic_bench/timers/x86_timer.hh | 246 |
8 files changed, 922 insertions, 0 deletions
diff --git a/bench/btl/generic_bench/timers/STL_perf_analyzer.hh b/bench/btl/generic_bench/timers/STL_perf_analyzer.hh new file mode 100644 index 000000000..c9f894b1f --- /dev/null +++ b/bench/btl/generic_bench/timers/STL_perf_analyzer.hh @@ -0,0 +1,82 @@ +//===================================================== +// File : STL_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _STL_PERF_ANALYSER_HH +#define _STL_PERF_ANALYSER_HH + +#include "STL_timer.hh" +#include "bench_parameter.hh" + +template<class ACTION> +class STL_Perf_Analyzer{ +public: + STL_Perf_Analyzer(unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos() + { + MESSAGE("STL_Perf_Analyzer Ctor"); + }; + STL_Perf_Analyzer( const STL_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~STL_Perf_Analyzer( void ){ + MESSAGE("STL_Perf_Analyzer Dtor"); + }; + + + inline double eval_mflops(int size) + { + + ACTION action(size); + + _chronos.start_baseline(_nb_sample); + + do { + + action.initialize(); + } while (_chronos.check()); + + double baseline_time=_chronos.get_time(); + + _chronos.start(_nb_sample); + do { + action.initialize(); + action.calculate(); + } while (_chronos.check()); + + double calculate_time=_chronos.get_time(); + + double corrected_time=calculate_time-baseline_time; + + // cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl; + + return action.nb_op_base()/(corrected_time*1000000.0); + //return action.nb_op_base()/(calculate_time*1000000.0); + + } +private: + + STL_Timer _chronos; + unsigned long long _nb_sample; + + +}; + + + +#endif diff --git a/bench/btl/generic_bench/timers/STL_timer.hh b/bench/btl/generic_bench/timers/STL_timer.hh new file mode 100644 index 000000000..19c54e9c1 --- /dev/null +++ b/bench/btl/generic_bench/timers/STL_timer.hh @@ -0,0 +1,78 @@ +//===================================================== +// File : STL_Timer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// STL Timer Class. Adapted (L.P.) from the timer class by Musser et Al +// described int the Book : STL Tutorial and reference guide. +// Define a timer class for analyzing algorithm performance. +#include <iostream> +#include <iomanip> +#include <vector> +#include <map> +#include <algorithm> +using namespace std; + +class STL_Timer { +public: + STL_Timer(){ baseline = false; }; // Default constructor + // Start a series of r trials: + void start(unsigned int r){ + reps = r; + count = 0; + iterations.clear(); + iterations.reserve(reps); + initial = time(0); + }; + // Start a series of r trials to determine baseline time: + void start_baseline(unsigned int r) + { + baseline = true; + start(r); + } + // Returns true if the trials have been completed, else false + bool check() + { + ++count; + final = time(0); + if (initial < final) { + iterations.push_back(count); + initial = final; + count = 0; + } + return (iterations.size() < reps); + }; + // Returns the results for external use + double get_time( void ) + { + sort(iterations.begin(), iterations.end()); + return 1.0/iterations[reps/2]; + }; +private: + unsigned int reps; // Number of trials + // For storing loop iterations of a trial + vector<long> iterations; + // For saving initial and final times of a trial + time_t initial, final; + // For counting loop iterations of a trial + unsigned long count; + // true if this is a baseline computation, false otherwise + bool baseline; + // For recording the baseline time + double baseline_time; +}; + diff --git a/bench/btl/generic_bench/timers/mixed_perf_analyzer.hh b/bench/btl/generic_bench/timers/mixed_perf_analyzer.hh new file mode 100644 index 000000000..e190236e0 --- /dev/null +++ b/bench/btl/generic_bench/timers/mixed_perf_analyzer.hh @@ -0,0 +1,73 @@ +//===================================================== +// File : mixed_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _MIXED_PERF_ANALYSER_HH +#define _MIXED_PERF_ANALYSER_HH + +#include "x86_perf_analyzer.hh" +#include "portable_perf_analyzer.hh" + +// choose portable perf analyzer for long calculations and x86 analyser for short ones + + +template<class Action> +class Mixed_Perf_Analyzer{ + +public: + Mixed_Perf_Analyzer( void ):_x86pa(),_ppa(),_use_ppa(true) + { + MESSAGE("Mixed_Perf_Analyzer Ctor"); + }; + Mixed_Perf_Analyzer( const Mixed_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~Mixed_Perf_Analyzer( void ){ + MESSAGE("Mixed_Perf_Analyzer Dtor"); + }; + + + inline double eval_mflops(int size) + { + + double result=0.0; + if (_use_ppa){ + result=_ppa.eval_mflops(size); + if (_ppa.get_nb_calc()>DEFAULT_NB_SAMPLE){_use_ppa=false;} + } + else{ + result=_x86pa.eval_mflops(size); + } + + return result; + } + +private: + + Portable_Perf_Analyzer<Action> _ppa; + X86_Perf_Analyzer<Action> _x86pa; + bool _use_ppa; + +}; + +#endif + + + + diff --git a/bench/btl/generic_bench/timers/portable_perf_analyzer.hh b/bench/btl/generic_bench/timers/portable_perf_analyzer.hh new file mode 100644 index 000000000..709f0de5d --- /dev/null +++ b/bench/btl/generic_bench/timers/portable_perf_analyzer.hh @@ -0,0 +1,98 @@ +//===================================================== +// File : portable_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _PORTABLE_PERF_ANALYZER_HH +#define _PORTABLE_PERF_ANALYZER_HH + +#include "utilities.h" +#include "timers/portable_timer.hh" + +template <class Action> +class Portable_Perf_Analyzer{ +public: + Portable_Perf_Analyzer( void ):_nb_calc(1),_chronos(){ + MESSAGE("Portable_Perf_Analyzer Ctor"); + }; + Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~Portable_Perf_Analyzer( void ){ + MESSAGE("Portable_Perf_Analyzer Dtor"); + }; + + + + inline double eval_mflops(int size) + { + Action action(size); + + + double time_action = time_calculate(action); + while (time_action < MIN_TIME) + { + _nb_calc *= 2; + action.initialize(); + time_action = time_calculate(action); + } + + // optimize + for (int i=1; i<NB_TRIES; ++i) + { + action.initialize(); + time_action = std::min(time_action, time_calculate(action)); + } + + time_action = time_action / (double(_nb_calc)); + + // check + action.initialize(); + action.calculate(); + action.check_result(); + + return action.nb_op_base()/(time_action*1000000.0); + } + + double time_calculate(Action & action) + { + // time measurement + _chronos.start(); + for (int ii=0;ii<_nb_calc;ii++) + { + action.calculate(); + } + _chronos.stop(); + return _chronos.user_time(); + } + + unsigned long long get_nb_calc( void ) + { + return _nb_calc; + } + + +private: + unsigned long long _nb_calc; + Portable_Timer _chronos; + +}; + +#endif //_PORTABLE_PERF_ANALYZER_HH + diff --git a/bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh b/bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh new file mode 100644 index 000000000..fce378168 --- /dev/null +++ b/bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh @@ -0,0 +1,134 @@ +//===================================================== +// File : portable_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _PORTABLE_PERF_ANALYZER_HH +#define _PORTABLE_PERF_ANALYZER_HH + +#include "utilities.h" +#include "timers/portable_timer.hh" + +template <class Action> +class Portable_Perf_Analyzer{ +public: + Portable_Perf_Analyzer( void ):_nb_calc(1),_nb_init(1),_chronos(){ + MESSAGE("Portable_Perf_Analyzer Ctor"); + }; + Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~Portable_Perf_Analyzer( void ){ + MESSAGE("Portable_Perf_Analyzer Dtor"); + }; + + + + inline double eval_mflops(int size) + { + + Action action(size); + +// double time_baseline = time_init(action); +// while (time_baseline < MIN_TIME_INIT) +// { +// _nb_init *= 2; +// time_baseline = time_init(action); +// } +// +// // optimize +// for (int i=1; i<NB_TRIES; ++i) +// time_baseline = std::min(time_baseline, time_init(action)); +// +// time_baseline = time_baseline/(double(_nb_init)); + + double time_action = time_calculate(action); + while (time_action < MIN_TIME) + { + _nb_calc *= 2; + time_action = time_calculate(action); + } + + // optimize + for (int i=1; i<NB_TRIES; ++i) + time_action = std::min(time_action, time_calculate(action)); + +// INFOS("size="<<size); +// INFOS("_nb_init="<<_nb_init); +// INFOS("_nb_calc="<<_nb_calc); + + time_action = time_action / (double(_nb_calc)); + + action.check_result(); + + + double time_baseline = time_init(action); + for (int i=1; i<NB_TRIES; ++i) + time_baseline = std::min(time_baseline, time_init(action)); + time_baseline = time_baseline/(double(_nb_init)); + + + +// INFOS("time_baseline="<<time_baseline); +// INFOS("time_action="<<time_action); + + time_action = time_action - time_baseline; + +// INFOS("time_corrected="<<time_action); + + return action.nb_op_base()/(time_action*1000000.0); + } + + inline double time_init(Action & action) + { + // time measurement + _chronos.start(); + for (int ii=0; ii<_nb_init; ii++) + action.initialize(); + _chronos.stop(); + return _chronos.user_time(); + } + + + inline double time_calculate(Action & action) + { + // time measurement + _chronos.start(); + for (int ii=0;ii<_nb_calc;ii++) + { + action.initialize(); + action.calculate(); + } + _chronos.stop(); + return _chronos.user_time(); + } + + unsigned long long get_nb_calc( void ) + { + return _nb_calc; + } + + +private: + unsigned long long _nb_calc; + unsigned long long _nb_init; + Portable_Timer _chronos; + +}; + +#endif //_PORTABLE_PERF_ANALYZER_HH diff --git a/bench/btl/generic_bench/timers/portable_timer.hh b/bench/btl/generic_bench/timers/portable_timer.hh new file mode 100755 index 000000000..3b7c5266b --- /dev/null +++ b/bench/btl/generic_bench/timers/portable_timer.hh @@ -0,0 +1,103 @@ +//===================================================== +// File : portable_timer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> from boost lib +// Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// simple_time extracted from the boost library +// +#ifndef _PORTABLE_TIMER_HH +#define _PORTABLE_TIMER_HH + +#include <time.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <unistd.h> +#include <sys/times.h> + +#define USEC_IN_SEC 1000000 + + +// timer -------------------------------------------------------------------// + +// A timer object measures CPU time. + +class Portable_Timer +{ + public: + + Portable_Timer( void ):_utime_sec_start(-1), + _utime_usec_start(-1), + _utime_sec_stop(-1), + _utime_usec_stop(-1) + { + } + + + void start() + { + + int status=getrusage(RUSAGE_SELF, &resourcesUsage) ; + + _start_time = std::clock(); + + _utime_sec_start = resourcesUsage.ru_utime.tv_sec ; + _utime_usec_start = resourcesUsage.ru_utime.tv_usec ; + + } + + void stop() + { + + int status=getrusage(RUSAGE_SELF, &resourcesUsage) ; + + _stop_time = std::clock(); + + _utime_sec_stop = resourcesUsage.ru_utime.tv_sec ; + _utime_usec_stop = resourcesUsage.ru_utime.tv_usec ; + + } + + double elapsed() + { + return double(_stop_time - _start_time) / CLOCKS_PER_SEC; + } + + double user_time() + { + long tot_utime_sec=_utime_sec_stop-_utime_sec_start; + long tot_utime_usec=_utime_usec_stop-_utime_usec_start; + return double(tot_utime_sec)+ double(tot_utime_usec)/double(USEC_IN_SEC) ; + } + + +private: + + struct rusage resourcesUsage ; + + long _utime_sec_start ; + long _utime_usec_start ; + + long _utime_sec_stop ; + long _utime_usec_stop ; + + std::clock_t _start_time; + std::clock_t _stop_time; + +}; // Portable_Timer + + +#endif // PORTABLE_TIMER_HPP diff --git a/bench/btl/generic_bench/timers/x86_perf_analyzer.hh b/bench/btl/generic_bench/timers/x86_perf_analyzer.hh new file mode 100644 index 000000000..37ea21dcc --- /dev/null +++ b/bench/btl/generic_bench/timers/x86_perf_analyzer.hh @@ -0,0 +1,108 @@ +//===================================================== +// File : x86_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _X86_PERF_ANALYSER_HH +#define _X86_PERF_ANALYSER_HH + +#include "x86_timer.hh" +#include "bench_parameter.hh" + +template<class ACTION> +class X86_Perf_Analyzer{ +public: + X86_Perf_Analyzer( unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos() + { + MESSAGE("X86_Perf_Analyzer Ctor"); + _chronos.find_frequency(); + }; + X86_Perf_Analyzer( const X86_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~X86_Perf_Analyzer( void ){ + MESSAGE("X86_Perf_Analyzer Dtor"); + }; + + + inline double eval_mflops(int size) + { + + ACTION action(size); + + int nb_loop=5; + double calculate_time=0.0; + double baseline_time=0.0; + + for (int j=0 ; j < nb_loop ; j++){ + + _chronos.clear(); + + for(int i=0 ; i < _nb_sample ; i++) + { + _chronos.start(); + action.initialize(); + action.calculate(); + _chronos.stop(); + _chronos.add_get_click(); + } + + calculate_time += double(_chronos.get_shortest_clicks())/_chronos.frequency(); + + if (j==0) action.check_result(); + + _chronos.clear(); + + for(int i=0 ; i < _nb_sample ; i++) + { + _chronos.start(); + action.initialize(); + _chronos.stop(); + _chronos.add_get_click(); + + } + + baseline_time+=double(_chronos.get_shortest_clicks())/_chronos.frequency(); + + } + + double corrected_time = (calculate_time-baseline_time)/double(nb_loop); + + +// INFOS("_nb_sample="<<_nb_sample); +// INFOS("baseline_time="<<baseline_time); +// INFOS("calculate_time="<<calculate_time); +// INFOS("corrected_time="<<corrected_time); + +// cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl; + + return action.nb_op_base()/(corrected_time*1000000.0); + //return action.nb_op_base()/(calculate_time*1000000.0); + } + +private: + + X86_Timer _chronos; + unsigned long long _nb_sample; + + +}; + + + +#endif diff --git a/bench/btl/generic_bench/timers/x86_timer.hh b/bench/btl/generic_bench/timers/x86_timer.hh new file mode 100644 index 000000000..cfb5ee833 --- /dev/null +++ b/bench/btl/generic_bench/timers/x86_timer.hh @@ -0,0 +1,246 @@ +//===================================================== +// File : x86_timer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _X86_TIMER_HH +#define _X86_TIMER_HH + +#include <sys/time.h> +#include <sys/resource.h> +#include <unistd.h> +#include <sys/times.h> +//#include "system_time.h" +#define u32 unsigned int +#include <asm/msr.h> +#include "utilities.h" +#include <map> +#include <fstream> +#include <string> +#include <iostream> + +// frequence de la becanne en Hz +//#define FREQUENCY 648000000 +//#define FREQUENCY 1400000000 +#define FREQUENCY 1695000000 + +using namespace std; + + +class X86_Timer { + +public : + + X86_Timer( void ):_frequency(FREQUENCY),_nb_sample(0) + { + MESSAGE("X86_Timer Default Ctor"); + } + + inline void start( void ){ + + rdtsc(_click_start.n32[0],_click_start.n32[1]); + + } + + + inline void stop( void ){ + + rdtsc(_click_stop.n32[0],_click_stop.n32[1]); + + } + + + inline double frequency( void ){ + return _frequency; + } + + double get_elapsed_time_in_second( void ){ + + return (_click_stop.n64-_click_start.n64)/double(FREQUENCY); + + + } + + unsigned long long get_click( void ){ + + return (_click_stop.n64-_click_start.n64); + + } + + inline void find_frequency( void ){ + + time_t initial, final; + int dummy=2; + + initial = time(0); + start(); + do { + dummy+=2; + } + while(time(0)==initial); + // On est au debut d'un cycle d'une seconde !!! + initial = time(0); + start(); + do { + dummy+=2; + } + while(time(0)==initial); + final=time(0); + stop(); + // INFOS("fine grained time : "<< get_elapsed_time_in_second()); + // INFOS("coarse grained time : "<< final-initial); + _frequency=_frequency*get_elapsed_time_in_second()/double(final-initial); + /// INFOS("CPU frequency : "<< _frequency); + + } + + void add_get_click( void ){ + + _nb_sample++; + _counted_clicks[get_click()]++; + fill_history_clicks(); + + } + + void dump_statistics(string filemane){ + + ofstream outfile (filemane.c_str(),ios::out) ; + + std::map<unsigned long long , unsigned long long>::iterator itr; + for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++) + { + outfile << (*itr).first << " " << (*itr).second << endl ; + } + + outfile.close(); + + } + + void dump_history(string filemane){ + + ofstream outfile (filemane.c_str(),ios::out) ; + + + + for(int i=0 ; i<_history_mean_clicks.size() ; i++) + { + outfile << i << " " + << _history_mean_clicks[i] << " " + << _history_shortest_clicks[i] << " " + << _history_most_occured_clicks[i] << endl ; + } + + outfile.close(); + + } + + + + double get_mean_clicks( void ){ + + std::map<unsigned long long,unsigned long long>::iterator itr; + + unsigned long long mean_clicks=0; + + for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++) + { + + mean_clicks+=(*itr).second*(*itr).first; + } + + return mean_clicks/double(_nb_sample); + + } + + double get_shortest_clicks( void ){ + + return double((*_counted_clicks.begin()).first); + + } + + void fill_history_clicks( void ){ + + _history_mean_clicks.push_back(get_mean_clicks()); + _history_shortest_clicks.push_back(get_shortest_clicks()); + _history_most_occured_clicks.push_back(get_most_occured_clicks()); + + } + + + double get_most_occured_clicks( void ){ + + unsigned long long moc=0; + unsigned long long max_occurence=0; + + std::map<unsigned long long,unsigned long long>::iterator itr; + + for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++) + { + + if (max_occurence<=(*itr).second){ + max_occurence=(*itr).second; + moc=(*itr).first; + } + } + + return double(moc); + + } + + void clear( void ) + { + _counted_clicks.clear(); + + _history_mean_clicks.clear(); + _history_shortest_clicks.clear(); + _history_most_occured_clicks.clear(); + + _nb_sample=0; + } + + + +private : + + union + { + unsigned long int n32[2] ; + unsigned long long n64 ; + } _click_start; + + union + { + unsigned long int n32[2] ; + unsigned long long n64 ; + } _click_stop; + + double _frequency ; + + map<unsigned long long,unsigned long long> _counted_clicks; + + vector<double> _history_mean_clicks; + vector<double> _history_shortest_clicks; + vector<double> _history_most_occured_clicks; + + unsigned long long _nb_sample; + + + +}; + + +#endif |