Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Hawkbat/v0.4.0
v0.4.0
- Loading branch information
Showing
20 changed files
with
1,627 additions
and
667 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEditorInternal; | ||
|
||
public class ProfilerUtil | ||
{ | ||
private const string HtmlOutputPath = "profiler.html"; | ||
|
||
[MenuItem("Tools/Dump selected profiler frame to HTML")] | ||
public static void DumpProfilerFrame() | ||
{ | ||
var property = new ProfilerProperty(); | ||
property.SetRoot(GetSelectedFrame(), ProfilerColumn.TotalPercent, ProfilerViewType.Hierarchy); | ||
property.onlyShowGPUSamples = false; | ||
|
||
if (File.Exists(HtmlOutputPath)) | ||
File.Delete(HtmlOutputPath); | ||
var stream = File.OpenWrite(HtmlOutputPath); | ||
var writer = new StreamWriter(stream); | ||
|
||
writer.WriteLine(@"<html> | ||
<head> | ||
<title>Unity Profiler Data</title> | ||
<style type=""text/css""> | ||
html, body { | ||
font-family: Helvetica, Arial, sans-serif; | ||
} | ||
table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
} | ||
th:first-child, td:first-child { | ||
text-align: left; | ||
} | ||
th:not(:first-child), td:not(:first-child) { | ||
text-align: right; | ||
} | ||
tbody tr:nth-child(odd) { | ||
background-color: #EEE; | ||
} | ||
th, td { | ||
margin: 0; | ||
padding: 5px; | ||
} | ||
th { | ||
padding-bottom: 10px; | ||
} | ||
td { | ||
font-size: 12px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<table> | ||
<thead> | ||
<tr><th>Path</th><th>Total</th><th>Self</th><th>Calls</th><th>GC Alloc</th><th>Total ms</th><th>Self ms</th></tr> | ||
</thead> | ||
<tbody>"); | ||
|
||
while (property.Next(true)) | ||
{ | ||
writer.Write("<td style=\"padding-left:" + property.depth * 10 + "px\">"); | ||
writer.Write(property.GetColumn(ProfilerColumn.FunctionName)); | ||
writer.Write("</td>"); | ||
|
||
writer.Write("<td>"); | ||
writer.Write(property.GetColumn(ProfilerColumn.TotalPercent)); | ||
writer.Write("</td>"); | ||
|
||
writer.Write("<td>"); | ||
writer.Write(property.GetColumn(ProfilerColumn.SelfPercent)); | ||
writer.Write("</td>"); | ||
|
||
writer.Write("<td>"); | ||
writer.Write(property.GetColumn(ProfilerColumn.Calls)); | ||
writer.Write("</td>"); | ||
|
||
writer.Write("<td>"); | ||
writer.Write(property.GetColumn(ProfilerColumn.GCMemory)); | ||
writer.Write("</td>"); | ||
|
||
writer.Write("<td>"); | ||
writer.Write(property.GetColumn(ProfilerColumn.TotalTime)); | ||
writer.Write("</td>"); | ||
|
||
writer.Write("<td>"); | ||
writer.Write(property.GetColumn(ProfilerColumn.SelfTime)); | ||
writer.Write("</td>"); | ||
|
||
writer.WriteLine("</tr>"); | ||
} | ||
|
||
writer.WriteLine(@"</tbody> | ||
</table> | ||
</body> | ||
</html>"); | ||
|
||
writer.Close(); | ||
} | ||
|
||
private static int GetSelectedFrame() | ||
{ | ||
var editorAssembly = Assembly.GetAssembly(typeof(EditorApplication)); | ||
var profilerWindowType = editorAssembly.GetType("UnityEditor.ProfilerWindow"); | ||
var profilerWindowsField = profilerWindowType.GetField("m_ProfilerWindows", BindingFlags.NonPublic | BindingFlags.Static); | ||
var firstProfilerWindow = ((System.Collections.IList)profilerWindowsField.GetValue(null))[0]; | ||
var getFrameMethod = profilerWindowType.GetMethod("GetActiveVisibleFrameIndex"); | ||
return (int)getFrameMethod.Invoke(firstProfilerWindow, null); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.