summaryrefslogtreecommitdiff
path: root/indra/newview/llmemoryview.cpp
blob: 7fd2572e085eee6dc3b535c4f6cb69493cdbc28f (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/** 
 * @file llmemoryview.cpp
 * @brief LLMemoryView class implementation
 *
 * Copyright (c) 2001-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#include "llviewerprecompiledheaders.h"

#include "indra_constants.h"
#include "llmemoryview.h"

#include "llrect.h"
#include "llerror.h"
#include "llgl.h"
#include "llmath.h"
#include "llfontgl.h"
#include "llmemtype.h"

#include "viewer.h"
#include "llui.h"
#include "llviewercontrol.h"
#include "llstat.h"

#include "llfasttimer.h"

LLMemoryView::LLMemoryView(const std::string& name, const LLRect& rect)
:	LLView(name, rect, TRUE)
{
	setVisible(FALSE);
}

LLMemoryView::~LLMemoryView()
{
}

EWidgetType LLMemoryView::getWidgetType() const
{
	return WIDGET_TYPE_MEMORY_VIEW;
}

LLString LLMemoryView::getWidgetTag() const
{
	return LL_MEMORY_VIEW_TAG;
}

BOOL LLMemoryView::handleMouseDown(S32 x, S32 y, MASK mask)
{
	if (mask & MASK_SHIFT)
	{
	}
	else if (mask & MASK_CONTROL)
	{
	}
	else
	{
	}
	return TRUE;
}

BOOL LLMemoryView::handleMouseUp(S32 x, S32 y, MASK mask)
{
	return TRUE;
}


BOOL LLMemoryView::handleHover(S32 x, S32 y, MASK mask)
{
	return FALSE;
}

//////////////////////////////////////////////////////////////////////////////

struct mtv_display_info {
	S32 memtype;
	const char *desc;
	LLColor4 *color;
};

static LLColor4 red0(0.5f, 0.0f, 0.0f, 1.0f);

static struct mtv_display_info mtv_display_table[] =
{
	{ LLMemType::MTYPE_INIT,			"Init", 			&LLColor4::white },
	{ LLMemType::MTYPE_STARTUP,			"Startup", 			&LLColor4::cyan1 },
	{ LLMemType::MTYPE_MAIN,			"Main", 			&LLColor4::cyan2 },
	{ LLMemType::MTYPE_IMAGEBASE,		"ImageBase",		&LLColor4::yellow1 },
	{ LLMemType::MTYPE_IMAGERAW,		"ImageRaw", 		&LLColor4::yellow2 },
	{ LLMemType::MTYPE_IMAGEFORMATTED,	"ImageFmtd",		&LLColor4::yellow3 },
	{ LLMemType::MTYPE_APPFMTIMAGE,		"ViewerImageFmt",	&LLColor4::orange1 },
	{ LLMemType::MTYPE_APPRAWIMAGE,		"ViewerImageRaw",	&LLColor4::orange2 },
	{ LLMemType::MTYPE_APPAUXRAWIMAGE,	"ViewerImageAux",	&LLColor4::orange3 },
	{ LLMemType::MTYPE_DRAWABLE,		"Drawable", 		&LLColor4::green1 },
	{ LLMemType::MTYPE_OBJECT,			"ViewerObject",		&LLColor4::green2 },
	{ LLMemType::MTYPE_PIPELINE,		"Pipeline",			&LLColor4::green3 },
	{ LLMemType::MTYPE_PARTICLES,		"Particles",		&LLColor4::green4 },
	{ LLMemType::MTYPE_SPACE_PARTITION,	"Space Partition",	&LLColor4::blue2 },
	{ LLMemType::MTYPE_VERTEX_DATA,		"Vertex Buffer",	&LLColor4::blue3 },
	{ LLMemType::MTYPE_AVATAR,			"Avatar",			&LLColor4::purple1 },
	{ LLMemType::MTYPE_REGIONS,			"Regions",			&LLColor4::blue1 },
 	{ LLMemType::MTYPE_TEMP1,			"Temp1",			&LLColor4::red1 },
 	{ LLMemType::MTYPE_TEMP2,			"Temp2",			&LLColor4::magenta1 },
 	{ LLMemType::MTYPE_TEMP3,			"Temp3",			&LLColor4::red2 },
 	{ LLMemType::MTYPE_TEMP4,			"Temp4",			&LLColor4::magenta2 },
 	{ LLMemType::MTYPE_TEMP5,			"Temp5",			&LLColor4::red3 },
 	{ LLMemType::MTYPE_TEMP6,			"Temp6",			&LLColor4::magenta3 },
 	{ LLMemType::MTYPE_TEMP7,			"Temp7",			&LLColor4::red4 },
 	{ LLMemType::MTYPE_TEMP8,			"Temp8",			&LLColor4::magenta4 },

 	{ LLMemType::MTYPE_OTHER,			"Other",			&red0 },
};
static const int MTV_DISPLAY_NUM  = (sizeof(mtv_display_table)/sizeof(mtv_display_table[0]));

void LLMemoryView::draw()
{
	std::string tdesc;
	S32 width = mRect.getWidth();
	S32 height = mRect.getHeight();
	
	LLGLSUIDefault gls_ui;
	LLGLSNoTexture gls_no_tex;
	gl_rect_2d(0, height, width, 0, LLColor4(0.f, 0.f, 0.f, 0.25f));
	
#if MEM_TRACK_TYPE

	S32 left, top, right, bottom;
	S32 x, y;

	S32 margin = 10;
	S32 texth = (S32)LLFontGL::sMonospace->getLineHeight();

	S32 xleft = margin;
	S32 ytop = height - margin;
	S32 labelwidth = 0;
	S32 maxmaxbytes = 1;

	// Make sure all timers are accounted for
	// Set 'MT_OTHER' to unaccounted ticks last frame
	{
		S32 display_memtypes[LLMemType::MTYPE_NUM_TYPES];
		for (S32 i=0; i < LLMemType::MTYPE_NUM_TYPES; i++)
		{
			display_memtypes[i] = 0;
		}
		for (S32 i=0; i < MTV_DISPLAY_NUM; i++)
		{
			S32 tidx = mtv_display_table[i].memtype;
			display_memtypes[tidx]++;
		}
		LLMemType::sMemCount[LLMemType::MTYPE_OTHER] = 0;
		LLMemType::sMaxMemCount[LLMemType::MTYPE_OTHER] = 0;
		for (S32 tidx = 0; tidx < LLMemType::MTYPE_NUM_TYPES; tidx++)
		{
			if (display_memtypes[tidx] == 0)
			{
				LLMemType::sMemCount[LLMemType::MTYPE_OTHER] += LLMemType::sMemCount[tidx];
				LLMemType::sMaxMemCount[LLMemType::MTYPE_OTHER] += LLMemType::sMaxMemCount[tidx];
			}
		}
	}
	
	// Labels
	{
		LLGLSTexture gls_texture;
		y = ytop;
		S32 peak = 0;
		for (S32 i=0; i<MTV_DISPLAY_NUM; i++)
		{
			x = xleft;

			int tidx = mtv_display_table[i].memtype;
			S32 bytes = LLMemType::sMemCount[tidx];
			S32 maxbytes = LLMemType::sMaxMemCount[tidx];
			maxmaxbytes = llmax(maxbytes, maxmaxbytes);
			peak += maxbytes;
			S32 mbytes = bytes >> 20;

			tdesc = llformat("%s [%4d MB]",mtv_display_table[i].desc,mbytes);
			LLFontGL::sMonospace->renderUTF8(tdesc, 0, x, y, LLColor4::white, LLFontGL::LEFT, LLFontGL::TOP);
			
			y -= (texth + 2);

			S32 textw = LLFontGL::sMonospace->getWidth(tdesc);
			if (textw > labelwidth)
				labelwidth = textw;
		}
		x = xleft;
	        tdesc = llformat("Total Bytes: %d MB Overhead: %d KB",
					 LLMemType::sTotalMem >> 20, LLMemType::sOverheadMem >> 10);
         	LLFontGL::sMonospace->renderUTF8(tdesc, 0, x, y, LLColor4::white, LLFontGL::LEFT, LLFontGL::TOP);
	}

	// Bars
	y = ytop;
	labelwidth += 8;
	S32 barw = width - labelwidth - xleft - margin;
	for (S32 i=0; i<MTV_DISPLAY_NUM; i++)
	{
		x = xleft + labelwidth;

		int tidx = mtv_display_table[i].memtype;
		S32 bytes = LLMemType::sMemCount[tidx];
		F32 frac = (F32)bytes / (F32)maxmaxbytes;
		S32 w = (S32)(frac * (F32)barw);
		left = x; right = x + w;
		top = y; bottom = y - texth;		
		gl_rect_2d(left, top, right, bottom, *mtv_display_table[i].color);

		S32 maxbytes = LLMemType::sMaxMemCount[tidx];
		F32 frac2 = (F32)maxbytes / (F32)maxmaxbytes;
		S32 w2 = (S32)(frac2 * (F32)barw);
		left = x + w + 1; right = x + w2;
		top = y; bottom = y - texth;
		LLColor4 tcolor = *mtv_display_table[i].color;
		tcolor.setAlpha(.5f);
		gl_rect_2d(left, top, right, bottom, tcolor);
		
		y -= (texth + 2);
	}

#endif
	
	LLView::draw();
}