• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //=====================================================
2 // File   :  x86_perf_analyzer.hh
3 // Author :  L. Plagne <laurent.plagne@edf.fr)>
4 // Copyright (C) EDF R&D,  mar d�c 3 18:59:35 CET 2002
5 //=====================================================
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 #ifndef _X86_PERF_ANALYSER_HH
21 #define _X86_PERF_ANALYSER_HH
22 
23 #include "x86_timer.hh"
24 #include "bench_parameter.hh"
25 
26 template<class ACTION>
27 class X86_Perf_Analyzer{
28 public:
X86_Perf_Analyzer(unsigned long long nb_sample=DEFAULT_NB_SAMPLE)29   X86_Perf_Analyzer( unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos()
30   {
31     MESSAGE("X86_Perf_Analyzer Ctor");
32     _chronos.find_frequency();
33   };
X86_Perf_Analyzer(const X86_Perf_Analyzer &)34   X86_Perf_Analyzer( const X86_Perf_Analyzer & ){
35     INFOS("Copy Ctor not implemented");
36     exit(0);
37   };
~X86_Perf_Analyzer(void)38   ~X86_Perf_Analyzer( void ){
39     MESSAGE("X86_Perf_Analyzer Dtor");
40   };
41 
42 
eval_mflops(int size)43   inline double eval_mflops(int size)
44   {
45 
46     ACTION action(size);
47 
48     int nb_loop=5;
49     double calculate_time=0.0;
50     double baseline_time=0.0;
51 
52     for (int j=0 ; j < nb_loop ; j++){
53 
54       _chronos.clear();
55 
56       for(int i=0 ; i < _nb_sample  ; i++)
57       {
58         _chronos.start();
59         action.initialize();
60         action.calculate();
61         _chronos.stop();
62         _chronos.add_get_click();
63       }
64 
65       calculate_time += double(_chronos.get_shortest_clicks())/_chronos.frequency();
66 
67       if (j==0) action.check_result();
68 
69       _chronos.clear();
70 
71       for(int i=0 ; i < _nb_sample  ; i++)
72       {
73         _chronos.start();
74         action.initialize();
75         _chronos.stop();
76         _chronos.add_get_click();
77 
78       }
79 
80       baseline_time+=double(_chronos.get_shortest_clicks())/_chronos.frequency();
81 
82     }
83 
84     double corrected_time = (calculate_time-baseline_time)/double(nb_loop);
85 
86 
87 //     INFOS("_nb_sample="<<_nb_sample);
88 //     INFOS("baseline_time="<<baseline_time);
89 //     INFOS("calculate_time="<<calculate_time);
90 //     INFOS("corrected_time="<<corrected_time);
91 
92 //    cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl;
93 
94     return action.nb_op_base()/(corrected_time*1000000.0);
95     //return action.nb_op_base()/(calculate_time*1000000.0);
96   }
97 
98 private:
99 
100   X86_Timer _chronos;
101   unsigned long long _nb_sample;
102 
103 
104 };
105 
106 
107 
108 #endif
109