Line data Source code
1 :
2 : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #ifndef EQ_STATISTICSAMPLER_H
20 : #define EQ_STATISTICSAMPLER_H
21 :
22 : #include <eq/fabric/statistic.h> // member
23 : #include <eq/types.h>
24 :
25 : namespace eq
26 : {
27 : /**
28 : * Utility to sample an statistics event.
29 : *
30 : * Holds a Statistic, which is initialized from the owner's data in the
31 : * ctor. Subclasses implement the constructor and destructor to sample the times
32 : * and process the gathered statistics.
33 : */
34 : template <typename Owner>
35 : class StatisticSampler
36 : {
37 : public:
38 : /**
39 : * Construct a new statistics sampler.
40 : *
41 : * @param type The statistics type.
42 : * @param owner The originator of the statistics event.
43 : * @param frameNumber The current frame.
44 : * @version 1.0
45 : */
46 15 : StatisticSampler(const Statistic::Type type, Owner* owner,
47 : const uint32_t frameNumber = LB_UNDEFINED_UINT32)
48 15 : : _owner(owner)
49 : {
50 15 : LBASSERT(owner);
51 15 : LBASSERT(owner->getID() != 0);
52 15 : LBASSERT(owner->getSerial() != CO_INSTANCE_INVALID);
53 15 : statistic.type = type;
54 15 : statistic.frameNumber = frameNumber;
55 15 : statistic.resourceName[0] = '\0';
56 15 : statistic.startTime = 0;
57 15 : statistic.endTime = 0;
58 :
59 15 : if (statistic.frameNumber == LB_UNDEFINED_UINT32)
60 10 : statistic.frameNumber = owner->getCurrentFrame();
61 15 : }
62 :
63 : /** Destruct and finish statistics sampling. @version 1.0 */
64 15 : virtual ~StatisticSampler()
65 : {
66 15 : LBASSERTINFO(statistic.startTime <= statistic.endTime, statistic);
67 30 : }
68 :
69 : Statistic statistic; //!< The statistics event.
70 :
71 : protected:
72 : Owner* const _owner;
73 : };
74 : }
75 :
76 : #endif // EQ_STATISTICSAMPLER_H
|