summaryrefslogtreecommitdiff
path: root/indra/newview/llviewerstatsrecorder.h
blob: 37c08a51cf4c45cc52d5c4be225d9142abf58b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
 * @file llviewerstatsrecorder.h
 * @brief record info about viewer events to a metrics log file
 *
 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * 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 GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#ifndef LLVIEWERSTATSRECORDER_H
#define LLVIEWERSTATSRECORDER_H


// This is a diagnostic class used to record information from the viewer
// for analysis.

#include "llframetimer.h"
#include "llviewerobject.h"
#include "llviewerregion.h"

class LLMutex;
class LLViewerObject;

class LLViewerStatsRecorder : public LLSingleton<LLViewerStatsRecorder>
{
	LLSINGLETON(LLViewerStatsRecorder);
	LOG_CLASS(LLViewerStatsRecorder);
	~LLViewerStatsRecorder();

 public:
	// Enable/disable stats recording.  This is broken down into two
	// flags so we can record stats without writing them to the log
	// file.  This is useful to analyzing updates for scene loading.
   void enableObjectStatsRecording(bool enable, bool logging = false);

	bool isEnabled() const { return mEnableStatsRecording; }
	bool isLogging() const { return mEnableStatsLogging; }

	void objectUpdateFailure(S32 msg_size)
    {
        if (mEnableStatsRecording)
        {
            recordObjectUpdateFailure(msg_size);
        }
	}

	void cacheMissEvent(U8 cache_miss_type)
	{
        if (mEnableStatsRecording)
        {
            recordCacheMissEvent(cache_miss_type);
        }
    }

	void cacheHitEvent()
    {
        if (mEnableStatsRecording)
        {
            recordCacheHitEvent();
        }
    }

    void objectUpdateEvent(const EObjectUpdateType update_type)
    {
		if (mEnableStatsRecording)
		{
			recordObjectUpdateEvent(update_type);
		}
	}

	void cacheFullUpdate(LLViewerRegion::eCacheUpdateResult update_result)
    {
		if (mEnableStatsRecording)
		{
			recordCacheFullUpdate(update_result);
		}
	}

	void requestCacheMissesEvent(S32 count)
	{
        if (mEnableStatsRecording)
        {
            recordRequestCacheMissesEvent(count);
        }
	}

	void textureFetch()
	{
        if (mEnableStatsRecording)
        {
            recordTextureFetch();
        }
	}

	void meshLoaded()
	{
		if (mEnableStatsRecording)
		{
			recordMeshLoaded();
		}
	}

	void idle()
	{
        writeToLog(mInterval);
	}

	F32 getTimeSinceStart();

private:
	void recordObjectUpdateFailure(S32 msg_size);
	void recordCacheMissEvent(U8 cache_miss_type);
	void recordCacheHitEvent();
	void recordObjectUpdateEvent(const EObjectUpdateType update_type);
	void recordCacheFullUpdate(LLViewerRegion::eCacheUpdateResult update_result);
	void recordRequestCacheMissesEvent(S32 count);
	void recordTextureFetch();
	void recordMeshLoaded();
	void writeToLog(F32 interval);
    void closeStatsFile();
	void makeStatsFileName();

	static LLViewerStatsRecorder* sInstance;

	LLFILE *	mStatsFile;			// File to write data into
    std::string mStatsFileName;

	LLFrameTimer	mTimer;
	F64			mFileOpenTime;
	F64			mLastSnapshotTime;
    F32         mInterval;					// Interval between data log writes
    F32         mMaxDuration;				// Time limit on file

	bool        mEnableStatsRecording;		// Set to true to enable recording stats data
    bool		mEnableStatsLogging;		// Set true to write stats to log file
	bool		mSkipSaveIfZeros;			// Set true to skip saving stats if all values are zero	

	S32			mObjectCacheHitCount;
	S32			mObjectCacheMissFullCount;
	S32			mObjectCacheMissCrcCount;
	S32			mObjectFullUpdates;
	S32			mObjectTerseUpdates;
	S32			mObjectCacheMissRequests;
	S32			mObjectCacheMissResponses;
	S32			mObjectCacheUpdateDupes;
	S32			mObjectCacheUpdateChanges;
	S32			mObjectCacheUpdateAdds;
	S32			mObjectCacheUpdateReplacements;
	S32			mObjectUpdateFailures;
	S32			mObjectUpdateFailuresSize;
	S32			mTextureFetchCount;
    S32         mMeshLoadedCount;

	void	clearStats();
};

#endif // LLVIEWERSTATSRECORDER_H