1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
9 |
* the Free Software Foundation; either version 2 of the License, or * |
10 |
* (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 |
* * |
17 |
* You should have received a copy of the GNU General Public License * |
18 |
* along with this program; if not, write to the Free Software * |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
22 |
|
23 |
#include "Profiler.h" |
24 |
#include <time.h> |
25 |
|
26 |
namespace LinuxSampler { namespace gig { |
27 |
|
28 |
unsigned long long Profiler::profilingSamples = 0; |
29 |
unsigned long long Profiler::profilingTime = 0; |
30 |
double Profiler::tsPerSecond = 0; |
31 |
bool Profiler::bEnabled = false; |
32 |
|
33 |
void Profiler::Reset() |
34 |
{ |
35 |
profilingSamples = 0; |
36 |
profilingTime = 0; |
37 |
} |
38 |
|
39 |
void Profiler::enable() { |
40 |
bEnabled = true; |
41 |
} |
42 |
|
43 |
void Profiler::Calibrate( void ) |
44 |
{ |
45 |
clock_t start_time = clock(); |
46 |
RTMath::time_stamp_t start_clocks = Stamp(); |
47 |
volatile int a = 1; |
48 |
volatile int b = 1; |
49 |
for (volatile int i = 0; i < 100000000; i++) |
50 |
{ |
51 |
a += b; |
52 |
} |
53 |
clock_t stop_time = clock(); |
54 |
RTMath::time_stamp_t stop_clocks = Stamp(); |
55 |
double diff_ticks = (stop_clocks - start_clocks); |
56 |
double diff_time = ((stop_time - start_time) / (double(CLOCKS_PER_SEC))); |
57 |
tsPerSecond = diff_ticks / diff_time; |
58 |
} |
59 |
|
60 |
unsigned int Profiler::GetBogoVoices(unsigned int SamplingFreq) |
61 |
{ |
62 |
if (profilingSamples == 0) return 0; |
63 |
double avgTicks = ((double) profilingTime) / ((double) profilingSamples); |
64 |
unsigned int samplesPerSecond = (unsigned int) (tsPerSecond / avgTicks); |
65 |
unsigned int bogoVoices = samplesPerSecond / SamplingFreq; |
66 |
return bogoVoices; |
67 |
} |
68 |
|
69 |
}} // namespace LinuxSampler::gig |