2007-01-20 03:53:23 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_STATS
|
|
|
|
#define OSG_STATS 1
|
|
|
|
|
|
|
|
#include <osg/Referenced>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2007-01-20 17:03:58 +08:00
|
|
|
class OSG_EXPORT Stats : public osg::Referenced
|
2007-01-20 03:53:23 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2007-01-30 19:40:23 +08:00
|
|
|
Stats(const std::string& name, unsigned int numberOfFrames=50);
|
2007-01-20 03:53:23 +08:00
|
|
|
|
|
|
|
void setName(const std::string& name) { _name = name; }
|
|
|
|
const std::string& getName() const { return _name; }
|
|
|
|
|
|
|
|
void allocate(unsigned int numberOfFrames);
|
|
|
|
|
|
|
|
int getEarliestFrameNumber() const { return _latestFrameNumber < static_cast<int>(_attributeMapList.size()) ? 0 : _latestFrameNumber - _attributeMapList.size() + 1; }
|
|
|
|
int getLatestFrameNumber() const { return _latestFrameNumber; }
|
|
|
|
|
|
|
|
typedef std::map<std::string, double> AttributeMap;
|
|
|
|
typedef std::vector<AttributeMap> AttributeMapList;
|
|
|
|
|
|
|
|
bool setAttribute(int frameNumber, const std::string& attributeName, double value);
|
|
|
|
bool getAttribute(int frameNumber, const std::string& attributeName, double& value) const;
|
2007-01-30 19:40:23 +08:00
|
|
|
|
|
|
|
bool getAveragedAttribute(const std::string& attributeName, double& value) const;
|
|
|
|
bool getAveragedAttribute(int startFrameNumber, int endFrameNumber, const std::string& attributeName, double& value) const;
|
2007-01-20 03:53:23 +08:00
|
|
|
|
|
|
|
AttributeMap& getAttributeMap(int frameNumber);
|
|
|
|
const AttributeMap& getAttributeMap(int frameNumber) const;
|
|
|
|
|
2007-01-30 19:40:23 +08:00
|
|
|
typedef std::map<std::string, bool> CollectMap;
|
|
|
|
|
|
|
|
void collectStats(const std::string& str, bool flag) { _collectMap[str] = flag; }
|
|
|
|
|
|
|
|
inline bool collectStats(const std::string& str) const
|
|
|
|
{
|
|
|
|
CollectMap::const_iterator itr = _collectMap.find(str);
|
|
|
|
return (itr != _collectMap.end()) ? itr->second : false;
|
|
|
|
}
|
|
|
|
|
2007-01-22 19:22:37 +08:00
|
|
|
void report(std::ostream& out, const char* indent=0) const ;
|
|
|
|
void report(std::ostream& out, unsigned int frameNumber, const char* indent=0) const;
|
2007-01-20 03:53:23 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Stats() {}
|
|
|
|
|
|
|
|
int getIndex(int frameNumber) const
|
|
|
|
{
|
|
|
|
// reject frame that are in the future
|
|
|
|
if (frameNumber > _latestFrameNumber) return -1;
|
|
|
|
|
|
|
|
// reject frames that are too early
|
|
|
|
if (frameNumber < getEarliestFrameNumber()) return -1;
|
|
|
|
|
|
|
|
if (frameNumber >= _baseFrameNumber) return frameNumber - _baseFrameNumber;
|
|
|
|
else return _attributeMapList.size() - (_baseFrameNumber-frameNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string _name;
|
|
|
|
|
|
|
|
int _baseFrameNumber;
|
|
|
|
int _latestFrameNumber;
|
|
|
|
|
|
|
|
AttributeMapList _attributeMapList;
|
|
|
|
AttributeMap _invalidAttributeMap;
|
|
|
|
|
2007-01-30 19:40:23 +08:00
|
|
|
CollectMap _collectMap;
|
|
|
|
|
2007-01-20 03:53:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|