Skip to content

Commit 7a680b6

Browse files
committed
Merge remote-tracking branch 'larry_origin/master'
# Conflicts: # MemoryCrawler/MemoryCrawler/Crawler/crawler.cpp # MemoryCrawler/MemoryCrawler/Crawler/crawler.h # MemoryCrawler/MemoryCrawler/Crawler/serialize.cpp # MemoryCrawler/MemoryCrawler/Crawler/stream.cpp # MemoryCrawler/MemoryCrawler/Crawler/stream.h # MemoryCrawler/MemoryCrawler/main.cpp # MemoryCrawler/MemoryCrawler/utils.h # MemoryCrawler/UnityProfiler/Crawler/record.cpp
2 parents cea1a44 + 669c630 commit 7a680b6

39 files changed

+5024
-1066
lines changed

Editor/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void encode<T>(MemoryStream stream)
4646
{
4747
if (property.PropertyType == typeof(string))
4848
{
49-
stream.Write(string.Format(" item.{0} = new string(fs.readString());\n", property.Name));
49+
stream.Write(string.Format(" item.{0} = fs.readString();\n", property.Name));
5050
}
5151
else if (property.PropertyType == typeof(ulong))
5252
{

Editor/MemoryCapture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ private static void ExportMemorySnapshot(PackedMemorySnapshot snapshot, bool nat
202202

203203
RepackUInt32(stream, offset, (uint)stream.Length);
204204

205-
Debug.LogFormat("+ {0}", filepath);
206205
stream.Close();
206+
Debug.LogFormat("+ {0}", filepath);
207+
207208
}
208209

209210
private static void RepackUInt32(Stream input, long offset, uint size)

Editor/UnityProfilerRecorder.cs

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@
99
using UnityEngine;
1010
using UnityEngine.Profiling;
1111

12+
#if UNITY_2019_1_OR_NEWER
13+
public static class ProfilerColumn
14+
{
15+
public static int DontSort = -1;
16+
public static int FunctionName = 0;
17+
public static int TotalPercent = 1;
18+
public static int SelfPercent = 2;
19+
public static int Calls = 3;
20+
public static int GCMemory = 4;
21+
public static int TotalTime = 5;
22+
public static int SelfTime = 6;
23+
public static int DrawCalls = 7;
24+
public static int TotalGPUTime = 8;
25+
public static int SelfGPUTime = 9;
26+
public static int TotalGPUPercent = 10; // 0x0000000A
27+
public static int SelfGPUPercent = 11; // 0x0000000B
28+
public static int WarningCount = 12; // 0x0000000C
29+
public static int ObjectName = 13; // 0x0000000D
30+
}
31+
32+
public static class ProfilerViewType
33+
{
34+
public static int Hierarchy = 0;
35+
public static int Timeline = 1;
36+
public static int RawHierarchy = 2;
37+
}
38+
39+
#endif
40+
1241
namespace Moobyte.MemoryProfiler
1342
{
1443
internal struct StackSample
@@ -36,6 +65,7 @@ private static void StartRecordingQuickly()
3665
}
3766

3867
private static Dictionary<int, List<int>> metadatas;
68+
private static byte profilerAreaCount = 0;
3969

4070
public static void StartRecording(bool includeUnityFormat = false)
4171
{
@@ -68,19 +98,33 @@ public static void StartRecording(bool includeUnityFormat = false)
6898

6999
var offset = stream.Position;
70100
metadatas = new Dictionary<int, List<int>>();
71-
stream.Write((byte)ProfilerArea.AreaCount); // area count
72-
for (var area = ProfilerArea.CPU; area < ProfilerArea.AreaCount; area++)
101+
var paType = typeof(ProfilerArea);
102+
var areaNames = Enum.GetNames(paType);
103+
104+
profilerAreaCount = (byte)areaNames.Length;
105+
if (areaNames[areaNames.Length - 1].Equals("AreaCount"))
73106
{
107+
--profilerAreaCount;
108+
}
109+
110+
stream.Write(profilerAreaCount); // area count
111+
for (var area = 0; area < profilerAreaCount; area++)
112+
{
113+
var areaValue = (ProfilerArea) area;
74114
stream.Write((byte)area);
75-
stream.Write(area.ToString());
115+
stream.Write(areaValue.ToString());
76116
List<int> children;
77117
metadatas.Add((int)area, children = new List<int>());
78-
var properties = ProfilerDriver.GetGraphStatisticsPropertiesForArea(area);
118+
var properties = ProfilerDriver.GetGraphStatisticsPropertiesForArea(areaValue);
79119
stream.Write((byte)properties.Length);
80120
for (var i = 0; i < properties.Length; i++)
81121
{
82122
var name = properties[i];
123+
#if UNITY_2018_1_OR_NEWER
124+
var identifier = ProfilerDriver.GetStatisticsIdentifierForArea(areaValue, name);
125+
#else
83126
var identifier = ProfilerDriver.GetStatisticsIdentifier(name);
127+
#endif
84128
stream.Write(name);
85129

86130
children.Add(identifier);
@@ -109,7 +153,6 @@ public static void StartRecording(bool includeUnityFormat = false)
109153
[MenuItem("性能/停止采样", false, 55)]
110154
public static void StopRecording()
111155
{
112-
Profiler.enabled = false;
113156
Profiler.logFile = null;
114157
EditorApplication.update -= Update;
115158

@@ -166,8 +209,6 @@ internal static int getStringRef(string v)
166209
static void Update()
167210
{
168211
var stopFrameIndex = ProfilerDriver.lastFrameIndex;
169-
170-
171212
var frameIndex = Math.Max(frameCursor + 1, ProfilerDriver.firstFrameIndex);
172213
while (frameIndex <= stopFrameIndex)
173214
{
@@ -187,8 +228,8 @@ static void Update()
187228
{
188229
cursor.Pop();
189230
}
190-
191-
var drawCalls = root.GetColumnAsSingle(ProfilerColumn.DrawCalls);
231+
232+
#if UNITY_2017_1_OR_NEWER
192233
samples.Add(sequence, new StackSample
193234
{
194235
id = sequence,
@@ -198,11 +239,16 @@ static void Update()
198239
totalTime = root.GetColumnAsSingle(ProfilerColumn.TotalTime),
199240
selfTime = root.GetColumnAsSingle(ProfilerColumn.SelfTime),
200241
});
201-
202-
if (cursor.Count != 0)
203-
{
204-
relations[sequence] = cursor.Peek();
205-
}
242+
#else
243+
var ss = new StackSample {id = sequence, name = root.propertyName};
244+
int.TryParse(root.GetColumn(ProfilerColumn.Calls), out ss.callsCount);
245+
int.TryParse(root.GetColumn(ProfilerColumn.GCMemory), out ss.gcAllocBytes);
246+
float.TryParse(root.GetColumn(ProfilerColumn.TotalTime), out ss.totalTime);
247+
float.TryParse(root.GetColumn(ProfilerColumn.SelfTime), out ss.selfTime);
248+
samples.Add(sequence, ss);
249+
#endif
250+
251+
relations[sequence] = cursor.Count != 0 ? cursor.Peek() : -1;
206252

207253
if (root.HasChildren)
208254
{
@@ -217,9 +263,26 @@ static void Update()
217263
stream.Write(frameIndex);
218264
stream.Write(string.IsNullOrEmpty(root.frameTime) ? (1000f / frameFPS) : float.Parse(root.frameTime));
219265
stream.Write(frameFPS);
220-
266+
if (frameIndex == stopFrameIndex) // encode memory info
267+
{
268+
stream.Write((ushort) 0);
269+
/**
270+
stream.Write((ushort) (8 * 6));
271+
stream.Write(Profiler.usedHeapSizeLong); // 1
272+
stream.Write(Profiler.GetMonoUsedSizeLong()); // 2
273+
stream.Write(Profiler.GetMonoHeapSizeLong()); // 3
274+
stream.Write(Profiler.GetTotalAllocatedMemoryLong()); // 4
275+
stream.Write(Profiler.GetTotalReservedMemoryLong()); // 5
276+
stream.Write(Profiler.GetTotalUnusedReservedMemoryLong()); // 6
277+
*/
278+
}
279+
else
280+
{
281+
stream.Write((ushort) 0);
282+
}
283+
221284
//encode statistics
222-
for (ProfilerArea area = 0; area < ProfilerArea.AreaCount; area++)
285+
for (var area = 0; area < profilerAreaCount; area++)
223286
{
224287
var statistics = metadatas[(int)area];
225288
stream.Write((byte)area);
@@ -260,4 +323,4 @@ static void Update()
260323
frameCursor = stopFrameIndex;
261324
}
262325
}
263-
}
326+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 larryhou
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MemoryCrawler/MemoryCrawler.xcodeproj/project.pbxproj

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
6B0AC7432252FC5D00B58C69 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B0AC7422252FC5D00B58C69 /* main.cpp */; };
1313
6B3498DB2269643400E7E4EC /* stat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B3498DA2269643400E7E4EC /* stat.cpp */; };
1414
6B5343722255B43F003CDBD0 /* serialize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B5343712255B43F003CDBD0 /* serialize.cpp */; };
15+
6B70A2CB23697310005A8D41 /* fragment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B70A2C923697310005A8D41 /* fragment.cpp */; };
16+
6B70A2CE23710B35005A8D41 /* format.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B70A2CC23710B35005A8D41 /* format.cpp */; };
1517
6B74B76F2254748200A69BC0 /* stream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B74B76D2254748200A69BC0 /* stream.cpp */; };
1618
6B74B77222548A0900A69BC0 /* snapshot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B74B77122548A0900A69BC0 /* snapshot.cpp */; };
19+
6B7E64C2235FFC120054958C /* rserialize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B7E64C0235FFC120054958C /* rserialize.cpp */; };
1720
6BCA665022575EE100A4C96A /* crawler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BCA664F22575EE100A4C96A /* crawler.cpp */; };
1821
6BCA665322584B6100A4C96A /* heap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BCA665222584B6100A4C96A /* heap.cpp */; };
1922
6BD1B05D227F15FB00E3CBD7 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BD1B05C227F15FB00E3CBD7 /* main.cpp */; };
@@ -63,10 +66,16 @@
6366
6B5343702255B43E003CDBD0 /* serialize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = serialize.h; sourceTree = "<group>"; };
6467
6B5343712255B43F003CDBD0 /* serialize.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = serialize.cpp; sourceTree = "<group>"; };
6568
6B5343732255B61C003CDBD0 /* perf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = perf.h; sourceTree = "<group>"; };
69+
6B70A2C923697310005A8D41 /* fragment.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = fragment.cpp; sourceTree = "<group>"; };
70+
6B70A2CA23697310005A8D41 /* fragment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = fragment.h; sourceTree = "<group>"; };
71+
6B70A2CC23710B35005A8D41 /* format.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = format.cpp; sourceTree = "<group>"; };
72+
6B70A2CD23710B35005A8D41 /* format.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = format.h; sourceTree = "<group>"; };
6673
6B74B76D2254748200A69BC0 /* stream.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = stream.cpp; sourceTree = "<group>"; };
6774
6B74B76E2254748200A69BC0 /* stream.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stream.h; sourceTree = "<group>"; };
6875
6B74B7702254838500A69BC0 /* types.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = types.h; sourceTree = "<group>"; };
6976
6B74B77122548A0900A69BC0 /* snapshot.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = snapshot.cpp; sourceTree = "<group>"; };
77+
6B7E64C0235FFC120054958C /* rserialize.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = rserialize.cpp; sourceTree = "<group>"; };
78+
6B7E64C1235FFC120054958C /* rserialize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = rserialize.h; sourceTree = "<group>"; };
7079
6B87DD0F2265CCC6001B0BE3 /* leak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = leak.h; sourceTree = "<group>"; };
7180
6BCA664E22575EE100A4C96A /* crawler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = crawler.h; sourceTree = "<group>"; };
7281
6BCA664F22575EE100A4C96A /* crawler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = crawler.cpp; sourceTree = "<group>"; };
@@ -144,6 +153,8 @@
144153
6B008E4E228D5CB100F18852 /* types.cpp */,
145154
6B5343702255B43E003CDBD0 /* serialize.h */,
146155
6B5343712255B43F003CDBD0 /* serialize.cpp */,
156+
6B7E64C0235FFC120054958C /* rserialize.cpp */,
157+
6B7E64C1235FFC120054958C /* rserialize.h */,
147158
6B5343732255B61C003CDBD0 /* perf.h */,
148159
6BCA664E22575EE100A4C96A /* crawler.h */,
149160
6BCA664F22575EE100A4C96A /* crawler.cpp */,
@@ -154,6 +165,10 @@
154165
6B87DD0F2265CCC6001B0BE3 /* leak.h */,
155166
6B3498D92269643400E7E4EC /* stat.h */,
156167
6B3498DA2269643400E7E4EC /* stat.cpp */,
168+
6B70A2C923697310005A8D41 /* fragment.cpp */,
169+
6B70A2CA23697310005A8D41 /* fragment.h */,
170+
6B70A2CC23710B35005A8D41 /* format.cpp */,
171+
6B70A2CD23710B35005A8D41 /* format.h */,
157172
);
158173
path = Crawler;
159174
sourceTree = "<group>";
@@ -266,11 +281,14 @@
266281
6B74B77222548A0900A69BC0 /* snapshot.cpp in Sources */,
267282
6B0AC7432252FC5D00B58C69 /* main.cpp in Sources */,
268283
6B5343722255B43F003CDBD0 /* serialize.cpp in Sources */,
284+
6B70A2CB23697310005A8D41 /* fragment.cpp in Sources */,
269285
6B3498DB2269643400E7E4EC /* stat.cpp in Sources */,
286+
6B7E64C2235FFC120054958C /* rserialize.cpp in Sources */,
270287
6BD1B06B227F1DD300E3CBD7 /* utils.cpp in Sources */,
271288
6B74B76F2254748200A69BC0 /* stream.cpp in Sources */,
272289
6BCA665322584B6100A4C96A /* heap.cpp in Sources */,
273290
6B008E4F228D5CB100F18852 /* types.cpp in Sources */,
291+
6B70A2CE23710B35005A8D41 /* format.cpp in Sources */,
274292
);
275293
runOnlyForDeploymentPostprocessing = 0;
276294
};
@@ -339,6 +357,7 @@
339357
GCC_PREPROCESSOR_DEFINITIONS = (
340358
"DEBUG=1",
341359
"$(inherited)",
360+
"PERF_DEBUG=1",
342361
);
343362
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
344363
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
@@ -409,26 +428,35 @@
409428
6B0AC7472252FC5D00B58C69 /* Debug */ = {
410429
isa = XCBuildConfiguration;
411430
buildSettings = {
431+
CODE_SIGN_IDENTITY = "-";
412432
CODE_SIGN_STYLE = Automatic;
413433
DEPLOYMENT_LOCATION = YES;
414-
DEVELOPMENT_TEAM = PRLP6W5S32;
434+
DEVELOPMENT_TEAM = "";
415435
DSTROOT = /;
416436
GCC_PREPROCESSOR_DEFINITIONS = (
417437
"DEBUG=1",
418438
"$(inherited)",
439+
"PERF_DEBUG=1",
419440
);
420441
PRODUCT_NAME = "$(TARGET_NAME)";
442+
PROVISIONING_PROFILE_SPECIFIER = "";
421443
};
422444
name = Debug;
423445
};
424446
6B0AC7482252FC5D00B58C69 /* Release */ = {
425447
isa = XCBuildConfiguration;
426448
buildSettings = {
449+
CODE_SIGN_IDENTITY = "-";
427450
CODE_SIGN_STYLE = Automatic;
428451
DEPLOYMENT_LOCATION = YES;
429-
DEVELOPMENT_TEAM = PRLP6W5S32;
452+
DEVELOPMENT_TEAM = "";
430453
DSTROOT = /;
454+
GCC_PREPROCESSOR_DEFINITIONS = (
455+
"PERF_DEBUG=1",
456+
"STRIP_NATIVE_CONNECTIONS=1",
457+
);
431458
PRODUCT_NAME = "$(TARGET_NAME)";
459+
PROVISIONING_PROFILE_SPECIFIER = "";
432460
};
433461
name = Release;
434462
};
@@ -450,6 +478,7 @@
450478
DEPLOYMENT_LOCATION = YES;
451479
DEVELOPMENT_TEAM = PRLP6W5S32;
452480
DSTROOT = /;
481+
GCC_PREPROCESSOR_DEFINITIONS = "PERF_DEBUG=1";
453482
PRODUCT_NAME = "$(TARGET_NAME)";
454483
};
455484
name = Release;

0 commit comments

Comments
 (0)