Add remaining files
[juce-lv2.git] / juce / source / src / core / juce_PerformanceCounter.h
blob70f5417dbe1519b0b0efda91633f875cd5898b5c
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_PERFORMANCECOUNTER_JUCEHEADER__
27 #define __JUCE_PERFORMANCECOUNTER_JUCEHEADER__
29 #include "../io/files/juce_File.h"
32 //==============================================================================
33 /** A timer for measuring performance of code and dumping the results to a file.
35 e.g. @code
37 PerformanceCounter pc ("fish", 50, "/temp/myfishlog.txt");
39 for (;;)
41 pc.start();
43 doSomethingFishy();
45 pc.stop();
47 @endcode
49 In this example, the time of each period between calling start/stop will be
50 measured and averaged over 50 runs, and the results printed to a file
51 every 50 times round the loop.
53 class JUCE_API PerformanceCounter
55 public:
56 //==============================================================================
57 /** Creates a PerformanceCounter object.
59 @param counterName the name used when printing out the statistics
60 @param runsPerPrintout the number of start/stop iterations before calling
61 printStatistics()
62 @param loggingFile a file to dump the results to - if this is File::nonexistent,
63 the results are just written to the debugger output
65 PerformanceCounter (const String& counterName,
66 int runsPerPrintout = 100,
67 const File& loggingFile = File::nonexistent);
69 /** Destructor. */
70 ~PerformanceCounter();
72 //==============================================================================
73 /** Starts timing.
75 @see stop
77 void start();
79 /** Stops timing and prints out the results.
81 The number of iterations before doing a printout of the
82 results is set in the constructor.
84 @see start
86 void stop();
88 /** Dumps the current metrics to the debugger output and to a file.
90 As well as using Logger::outputDebugString to print the results,
91 this will write then to the file specified in the constructor (if
92 this was valid).
94 void printStatistics();
96 private:
97 //==============================================================================
98 String name;
99 int numRuns, runsPerPrint;
100 double totalTime;
101 int64 started;
102 File outputFile;
105 #endif // __JUCE_PERFORMANCECOUNTER_JUCEHEADER__