DataDirector API
DDD_PerformanceMonitor.h
Go to the documentation of this file.
1 /*! \file DDD_PerformanceMonitor.h
2 
3  \brief classes for measuring application performance
4 
5  \par Copyright Information
6 
7  Copyright (c) 2012 The DiSTI Corporation.<br>
8  11301 Corporate Blvd; Suite 100<br>
9  Orlando, Florida 32817<br>
10  USA<br>
11  <br>
12  All rights reserved.<br>
13 
14  This Software contains proprietary trade secrets of DiSTI and may not be
15 reproduced, in whole or part, in any form, or by any means of electronic,
16 mechanical, or otherwise, without the written permission of DiSTI. Said
17 permission may be derived through the purchase of applicable DiSTI product
18 licenses which detail the distribution rights of this content and any
19 Derivative Works based on this or other copyrighted DiSTI Software.
20 
21  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
22 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
23 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
24 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
26 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
27 
28  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
29 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
30 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
31 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
32 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
33 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
34 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
35 EXCEED FIVE DOLLARS (US$5.00).
36 
37  The aforementioned terms and restrictions are governed by the laws of the
38 State of Florida and the United States of America.
39 
40 */
41 
42 #ifndef _DDD_PerformanceMonitor_h_
43 #define _DDD_PerformanceMonitor_h_
44 
45 
46 #include "DDD_Include.h"
47 #include "dynamic_ptr_array.h"
48 #include "timer.h"
49 #include <string>
50 
51 namespace disti
52 {
53 
54 /** \brief Performance monitor class; profiles an individual task. */
55 class DDD_EXPORT DDD_PerformanceMonitor
56 {
57  friend class DDD_PerformanceMonitorSystem;
58 protected:
59  Timer _timer; /**< Timer used to track performance */
60  std::string _name; /**< Friendly name for display purposes. Must be unique */
61  INT_64 _sample; /**< The most recent performance sample. */
62  bool _started; /**< True if measurement has been started (i.e. timer is counting */
63 
64  /** Constructor
65  * \param name The name of the performance monitor to create. Must be unique.
66  */
67  DDD_PerformanceMonitor(std::string &name);
68 public:
69 
70  /** \return Returns the name of this performance monitor */
71  std::string &Name() { return _name; }
72 
73  /** Start measuring performance. Call this immediately before the code you want to profile */
74  void StartMeasurement();
75 
76  /** Stop measuring performance. Call this immediately after the code you want to profile */
77  void FinishMeasurement();
78 
79  /** \return Returns the last performance sample, i.e. the amount of time that elapsed between
80  * the most recent two calls to StartMeasurement and FinishMeasurement
81  */
82  INT_64 LastPerformanceSample();
83 };
84 
85 /** \brief A collection of DDD_PerformanceMonitors. A singleton. */
86 class DDD_EXPORT DDD_PerformanceMonitorSystem : public DynamicPtrArray<DDD_PerformanceMonitor *>
87 {
88 protected:
89 
90  /** Constructor. Protected because this is a singleton */
92 
93  /** Destructor. Protected because this is a singleton */
95 public:
96 
97  /** Public interface to the singleton
98  * \return Returns a pointer to the singleton instance
99  */
100  static DDD_PerformanceMonitorSystem *Instance();
101 
102  /** Register a new performance monitor
103  * \param name The name of the new performance monitor. Must be unique.
104  * \return A pointer to the new performance monitor. For efficiency the caller
105  * should cache this value. Returns NULL if there was already a monitor
106  * registered with 'name'
107  */
108  DDD_PerformanceMonitor *RegisterPerformanceMonitor(std::string name);
109 
110  /** \return Returns a pointer to the performance monitor with the given name
111  * or NULL if none was found
112  * \param name The name of the monitor to find
113  */
114  DDD_PerformanceMonitor *FindMonitor(std::string name);
115 };
116 
117 } // end of namespace disti
118 
119 #endif
120 
A templated array of object pointers. The array dynamically resizes as needed.
Definition: dynamic_ptr_array.h:55
The disti::Timer class. An OS portable timing class.
Timer _timer
Definition: DDD_PerformanceMonitor.h:59
Definition: timer.h:64
std::string _name
Definition: DDD_PerformanceMonitor.h:60
bool _started
Definition: DDD_PerformanceMonitor.h:62
A collection of DDD_PerformanceMonitors. A singleton.
Definition: DDD_PerformanceMonitor.h:86
The disti::DynamicPtrArray class. A templated array of objects pointers capable of dynamically growin...
std::string & Name()
Definition: DDD_PerformanceMonitor.h:71
Performance monitor class; profiles an individual task.
Definition: DDD_PerformanceMonitor.h:55
INT_64 _sample
Definition: DDD_PerformanceMonitor.h:61
Definition: AttributeChangedEmitter.h:46