Changeset 13041 for OpenSceneGraph/trunk/include/osg/Stats
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/Stats (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/Stats
r12056 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 33 33 34 34 Stats(const std::string& name, unsigned int numberOfFrames); 35 35 36 36 void setName(const std::string& name) { _name = name; } 37 37 const std::string& getName() const { return _name; } 38 38 39 39 void allocate(unsigned int numberOfFrames); 40 40 41 41 unsigned int getEarliestFrameNumber() const { return _latestFrameNumber < static_cast<unsigned int>(_attributeMapList.size()) ? 0 : _latestFrameNumber - static_cast<unsigned int>(_attributeMapList.size()) + 1; } 42 42 unsigned int getLatestFrameNumber() const { return _latestFrameNumber; } 43 43 44 44 typedef std::map<std::string, double> AttributeMap; 45 45 typedef std::vector<AttributeMap> AttributeMapList; 46 46 47 47 bool setAttribute(unsigned int frameNumber, const std::string& attributeName, double value); 48 48 49 49 inline bool getAttribute(unsigned int frameNumber, const std::string& attributeName, double& value) const 50 50 { … … 54 54 55 55 bool getAveragedAttribute(const std::string& attributeName, double& value, bool averageInInverseSpace=false) const; 56 56 57 57 bool getAveragedAttribute(unsigned int startFrameNumber, unsigned int endFrameNumber, const std::string& attributeName, double& value, bool averageInInverseSpace=false) const; 58 58 59 59 inline AttributeMap& getAttributeMap(unsigned int frameNumber) 60 60 { … … 62 62 return getAttributeMapNoMutex(frameNumber); 63 63 } 64 64 65 65 inline const AttributeMap& getAttributeMap(unsigned int frameNumber) const 66 66 { … … 68 68 return getAttributeMapNoMutex(frameNumber); 69 69 } 70 70 71 71 typedef std::map<std::string, bool> CollectMap; 72 72 73 73 void collectStats(const std::string& str, bool flag) { _collectMap[str] = flag; } 74 74 75 75 inline bool collectStats(const std::string& str) const 76 76 { 77 77 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); 78 79 CollectMap::const_iterator itr = _collectMap.find(str); 78 79 CollectMap::const_iterator itr = _collectMap.find(str); 80 80 return (itr != _collectMap.end()) ? itr->second : false; 81 81 } … … 83 83 void report(std::ostream& out, const char* indent=0) const; 84 84 void report(std::ostream& out, unsigned int frameNumber, const char* indent=0) const; 85 85 86 86 protected: 87 87 88 88 virtual ~Stats() {} 89 89 90 90 bool getAttributeNoMutex(unsigned int frameNumber, const std::string& attributeName, double& value) const; 91 91 … … 98 98 // reject frame that are in the future 99 99 if (frameNumber > _latestFrameNumber) return -1; 100 100 101 101 // reject frames that are too early 102 102 if (frameNumber < getEarliestFrameNumber()) return -1; 103 103 104 104 if (frameNumber >= _baseFrameNumber) return frameNumber - _baseFrameNumber; 105 105 else return static_cast<int>(_attributeMapList.size()) - (_baseFrameNumber-frameNumber); … … 107 107 108 108 std::string _name; 109 109 110 110 mutable OpenThreads::Mutex _mutex; 111 111 112 112 unsigned int _baseFrameNumber; 113 113 unsigned int _latestFrameNumber; 114 114 115 115 AttributeMapList _attributeMapList; 116 116 AttributeMap _invalidAttributeMap; 117 117 118 118 CollectMap _collectMap; 119 119 120 120 }; 121 121
