summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/XDebug.cs
blob: a58b5827ae3e3180273108b07b0ecd9ef3c56c1b (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using UnityEngine;
using XUpdater;

namespace XUtliPoolLib
{
	public class XDebug : XSingleton<XDebug>
	{
		private int _OutputChannels = 0;

		private IPlatform _platform = null;

		private bool _showTimeStick = true;

		private bool _showLog = true;

		private StringBuilder _buffer = new StringBuilder();

		private XDebug.LayerInfo[] m_LayerInfo = new XDebug.LayerInfo[]
		{
			new XDebug.LayerInfo(),
			new XDebug.LayerInfo()
		};

		private int m_MaxLayer = 2;

		private bool m_record = false;

		private bool m_recordStart = false;

		private XDebug.RecordChannel m_RecordChannel = XDebug.RecordChannel.ENone;

		public enum RecordChannel
		{
			ENone,
			ENetwork,
			EResourceLoad
		}

		public enum RecordLayer
		{
			ELayer0,
			ELayer1,
			ENum
		}

		public class SizeInfo
		{
			public string Name = "";

			public float Size = 0f;

			public int Count = 0;
		}

		public class LayerInfo
		{
			public string Name = "";

			public Dictionary<uint, XDebug.SizeInfo> SizeInfoMap = new Dictionary<uint, XDebug.SizeInfo>();

			public void Clear()
			{
				this.SizeInfoMap.Clear();
			}
		}

		public XDebug()
		{
			this._OutputChannels = 5;
		}

		public void Init(IPlatform platform, XFileLog log)
		{
			this._platform = XSingleton<XUpdater.XUpdater>.singleton.XPlatform;
		}

		public void AddLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null, XDebugColor color = XDebugColor.XDebug_None)
		{
			bool flag = this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, color);
			}
		}

		public void AddLog2(string format, params object[] args)
		{
			bool flag = this._showLog && this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				this.AddLog(string.Format(format, args), null, null, null, null, null, XDebugColor.XDebug_None);
			}
		}

		public void AddLog(XDebugChannel channel, string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null, XDebugColor color = XDebugColor.XDebug_None)
		{
			bool flag = this._showLog && this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				bool flag2 = (this._OutputChannels & (int)channel) > 0;
				if (flag2)
				{
					this._buffer.Length = 0;
					this._buffer.Append(log1).Append(log2).Append(log3).Append(log4).Append(log5).Append(log6);
					bool flag3 = color == XDebugColor.XDebug_Green;
					if (flag3)
					{
						this._buffer.Insert(0, "<color=green>");
						this._buffer.Append("</color>");
					}
					bool showTimeStick = this._showTimeStick;
					if (showTimeStick)
					{
						bool flag4 = Thread.CurrentThread.ManagedThreadId == XSingleton<XUpdater.XUpdater>.singleton.ManagedThreadId;
						if (flag4)
						{
							this._buffer.Append(" (at Frame: ").Append(Time.frameCount).Append(" sec: ").Append(Time.realtimeSinceStartup.ToString("F3")).Append(')');
						}
						else
						{
							bool flag5 = string.IsNullOrEmpty(Thread.CurrentThread.Name);
							if (flag5)
							{
								this._buffer.Append(" (from anonymous thread").Append(" with id ").Append(Thread.CurrentThread.ManagedThreadId).Append(")");
							}
							else
							{
								this._buffer.Append(" (from thread ").Append(Thread.CurrentThread.Name).Append(" with id ").Append(Thread.CurrentThread.ManagedThreadId).Append(")");
							}
						}
					}
					bool flag6 = color == XDebugColor.XDebug_Red;
					if (flag6)
					{
						Debug.LogError(this._buffer);
					}
					else
					{
						bool flag7 = color == XDebugColor.XDebug_Yellow;
						if (flag7)
						{
							Debug.LogWarning(this._buffer);
						}
						else
						{
							Debug.Log(this._buffer);
						}
					}
				}
			}
		}

		public void AddGreenLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null)
		{
			bool flag = this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, XDebugColor.XDebug_Green);
			}
		}

		public void AddWarningLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null)
		{
			bool flag = this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, XDebugColor.XDebug_Yellow);
			}
		}

		public void AddWarningLog2(string format, params object[] args)
		{
			bool flag = this._showLog && this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				this.AddWarningLog(string.Format(format, args), null, null, null, null, null);
			}
		}

		public void AddErrorLog2(string format, params object[] args)
		{
			bool flag = this._showLog && this._platform != null && !this._platform.IsPublish();
			if (flag)
			{
				this.AddErrorLog(string.Format(format, args), null, null, null, null, null);
			}
		}

		public void AddErrorLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null)
		{
			this._buffer.Length = 0;
			bool flag = Thread.CurrentThread.ManagedThreadId == XSingleton<XUpdater.XUpdater>.singleton.ManagedThreadId;
			if (flag)
			{
				this._buffer.Append(log1).Append(log2).Append(log3).Append(log4).Append(log5).Append(log6).Append(" (at Frame: ").Append(Time.frameCount).Append(" sec: ").Append(Time.realtimeSinceStartup.ToString("F3")).Append(')');
			}
			else
			{
				this._buffer.Append(log1).Append(log2).Append(log3).Append(log4).Append(log5).Append(log6);
			}
			XFileLog.AddCustomLog("AddErrorLog:  " + this._buffer);
			this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, XDebugColor.XDebug_Red);
		}

		public override bool Init()
		{
			return true;
		}

		public override void Uninit()
		{
		}

		public void BeginProfile(string title)
		{
		}

		public void RegisterGroupProfile(string title)
		{
		}

		public void BeginGroupProfile(string title)
		{
		}

		public void EndProfile()
		{
		}

		public void EndGroupProfile(string title)
		{
		}

		public void InitProfiler()
		{
		}

		public void PrintProfiler()
		{
		}

		public void StartRecord(XDebug.RecordChannel channel)
		{
			this.m_record = true;
			this.m_recordStart = false;
			this.m_RecordChannel = channel;
			XDebug.RecordChannel recordChannel = this.m_RecordChannel;
			if (recordChannel != XDebug.RecordChannel.ENetwork)
			{
				if (recordChannel == XDebug.RecordChannel.EResourceLoad)
				{
					this.m_LayerInfo[0].Name = "SharedRes";
					this.m_LayerInfo[1].Name = "Prefab";
				}
			}
			else
			{
				this.m_LayerInfo[0].Name = "Recv";
				this.m_LayerInfo[1].Name = "Send";
			}
		}

		public void EndRecord()
		{
			this.m_record = false;
			this.m_recordStart = false;
			this.m_RecordChannel = XDebug.RecordChannel.ENone;
		}

		public void BeginRecord()
		{
			bool record = this.m_record;
			if (record)
			{
				this.m_recordStart = true;
			}
		}

		public void ClearRecord()
		{
			this.m_LayerInfo[0].Clear();
			this.m_LayerInfo[1].Clear();
		}

		public bool EnableRecord()
		{
			return this.m_recordStart;
		}

		public void AddPoint(uint key, string name, float size, int layer, XDebug.RecordChannel channel)
		{
			bool flag = this.m_recordStart && channel == this.m_RecordChannel && layer >= 0 && layer < this.m_MaxLayer;
			if (flag)
			{
				Dictionary<uint, XDebug.SizeInfo> sizeInfoMap = this.m_LayerInfo[layer].SizeInfoMap;
				XDebug.SizeInfo sizeInfo = null;
				bool flag2 = !sizeInfoMap.TryGetValue(key, out sizeInfo);
				if (flag2)
				{
					sizeInfo = new XDebug.SizeInfo();
					sizeInfo.Name = name;
					sizeInfoMap.Add(key, sizeInfo);
				}
				sizeInfo.Count++;
				sizeInfo.Size += size;
			}
		}

		public void Print()
		{
			float num = 0f;
			for (int i = 0; i < this.m_MaxLayer; i++)
			{
				XSingleton<XCommon>.singleton.CleanStringCombine();
				float num2 = 0f;
				XDebug.SizeInfo sizeInfo = null;
				XDebug.LayerInfo layerInfo = this.m_LayerInfo[i];
				XSingleton<XCommon>.singleton.AppendString(layerInfo.Name, ":\r\n");
				foreach (KeyValuePair<uint, XDebug.SizeInfo> keyValuePair in layerInfo.SizeInfoMap)
				{
					XDebug.SizeInfo value = keyValuePair.Value;
					XSingleton<XCommon>.singleton.AppendString(string.Format("Name:{0} Count:{1} Size:{2}\r\n", value.Name, value.Count, value.Size));
					num += value.Size;
					num2 += value.Size;
					bool flag = sizeInfo == null || sizeInfo.Size < value.Size;
					if (flag)
					{
						sizeInfo = value;
					}
				}
				XSingleton<XDebug>.singleton.AddWarningLog(XSingleton<XCommon>.singleton.GetString(), null, null, null, null, null);
				bool flag2 = sizeInfo != null;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddWarningLog2("max name:{0} Count:{1} Size:{2}", new object[]
					{
						sizeInfo.Name,
						sizeInfo.Count,
						sizeInfo.Size
					});
				}
				XSingleton<XDebug>.singleton.AddWarningLog2("total {0} size:{1}", new object[]
				{
					layerInfo.Name,
					num2
				});
			}
			XSingleton<XDebug>.singleton.AddWarningLog("total size:", num.ToString(), null, null, null, null);
		}
	}
}