Skip to content

Commit c2fdf28

Browse files
committed
BuildReport: show category stats, show streaming assets folder size (for last build only), add BuildReport class, Tools: add GetFolderSizeInBytes(), GetBytesReadable()
1 parent 3c70b7d commit c2fdf28

File tree

5 files changed

+236
-48
lines changed

5 files changed

+236
-48
lines changed

UnityLauncherPro/Data/BuildReport.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace UnityLauncherPro
4+
{
5+
public class BuildReport
6+
{
7+
public long ElapsedTimeMS { set; get; }
8+
public List<BuildReportItem> Stats { set; get; } // overal per category sizes
9+
public List<BuildReportItem> Items { set; get; } // report rows
10+
}
11+
}

UnityLauncherPro/MainWindow.xaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@
988988
<ColumnDefinition Width="30*" />
989989
</Grid.ColumnDefinitions>
990990
<!--Grid.Column="0"-->
991-
<DataGrid x:Name="gridBuildReport" SelectionMode="Single" CanUserAddRows="False" Margin="4,0,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Visible" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick" HorizontalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Visible">
991+
<DataGrid x:Name="gridBuildReport" SelectionMode="Single" CanUserAddRows="False" Margin="4,0,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Auto" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick" HorizontalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Visible">
992992
<DataGrid.CommandBindings>
993993
<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyRowFolderToClipBoard" CanExecute="CanExecute_Copy"/>
994994
</DataGrid.CommandBindings>
@@ -1014,16 +1014,20 @@
10141014
<local:BuildReportItem Size="10.0 mb" Percentage="50.0%" Path="Assets/Textures/sample.png" />
10151015
</DataGrid>
10161016

1017-
<DataGrid Grid.Column="1" x:Name="gridBuildReportData" SelectionMode="Single" CanUserAddRows="False" Margin="4,0,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick" HorizontalContentAlignment="Stretch">
1017+
<StackPanel Grid.Column="1" Orientation="Vertical">
1018+
<DataGrid x:Name="gridBuildReportData" SelectionMode="Single" CanUserAddRows="False" Margin="4,0,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick" HorizontalContentAlignment="Stretch">
10181019
<DataGrid.Columns>
10191020
<DataGridTextColumn Header="Type" Binding="{Binding Category}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
10201021
<DataGridTextColumn Header="Size" Binding="{Binding Size}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
10211022
<DataGridTextColumn Header="%" Binding="{Binding Percentage}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
10221023
</DataGrid.Columns>
10231024
<local:BuildReportItem Category="Texture" Size="10.0 mb" Percentage="50.0%" />
10241025
</DataGrid>
1025-
</Grid>
1026+
<Label Content="Elapsed time:" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
1027+
<TextBox CaretBrush="#FFE2E2E2" x:Name="txtBuildTime" Background="{DynamicResource ThemeTextBoxBackground}" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" UndoLimit="64" IsReadOnly="True" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="4,0,4,0" />
1028+
</StackPanel>
10261029

1030+
</Grid>
10271031
</Grid>
10281032
<!--<DataGrid x:Name="gridBuildReport" SelectionMode="Single" CanUserAddRows="False" Margin="4,0,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Visible" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick" HorizontalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Top">-->
10291033

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 141 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public partial class MainWindow : Window
5454
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
5555

5656
string currentBuildReportProjectPath = null;
57-
List<List<string>> buildReports = new List<List<string>>();
57+
//List<List<string>> buildReports = new List<List<string>>();
58+
List<BuildReport> buildReports = new List<BuildReport>(); // multiple reports, each contains their own stats and items
5859
int currentBuildReport = 0;
5960

6061
[DllImport("user32", CharSet = CharSet.Unicode)]
@@ -1844,6 +1845,7 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18441845
void RefreshBuildReports()
18451846
{
18461847
currentBuildReport = 0;
1848+
// delete all reports
18471849
buildReports.Clear();
18481850
UpdateBuildReportLabelAndButtons();
18491851

@@ -1853,17 +1855,21 @@ void RefreshBuildReports()
18531855
var logFile = Path.Combine(Tools.GetEditorLogsFolder(), "Editor.log");
18541856
if (File.Exists(logFile) == false) return;
18551857

1856-
List<string> subList = null;
1858+
BuildReport singleReport = new BuildReport();
18571859

18581860
try
18591861
{
18601862
using (FileStream fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
18611863
{
18621864
using (StreamReader sr = new StreamReader(fs))
18631865
{
1864-
bool collect = false;
1866+
bool collectRows = false; // actual log rows
1867+
bool collectStats = false; // category stat rows
1868+
bool collectedBuildTime = false;
1869+
18651870
bool gotProjectPath = false;
18661871

1872+
// TODO cleanup here
18671873
while (!sr.EndOfStream)
18681874
{
18691875
var line = sr.ReadLine();
@@ -1877,25 +1883,112 @@ void RefreshBuildReports()
18771883
if (line == "-projectPath") gotProjectPath = true;
18781884

18791885

1880-
// build report starts, TODO collect report header also
1881-
if (collect == false && line.IndexOf("Used Assets and files from the Resources folder, sorted by uncompressed size:") == 0)
1886+
// build report starts
1887+
if (collectRows == false && line.IndexOf("Used Assets and files from the Resources folder, sorted by uncompressed size:") == 0)
18821888
{
18831889
// init new list for this build report
1884-
subList = new List<string>();
1885-
collect = true;
1890+
singleReport.Items = new List<BuildReportItem>();
1891+
collectRows = true;
1892+
1893+
// category report ends
1894+
if (collectRows == true)
1895+
{
1896+
collectStats = false;
1897+
}
1898+
18861899
continue;
18871900
}
18881901

1889-
// build report ends
1890-
if (collect == true && line.IndexOf("-------------------------------------------------------------------------------") == 0)
1902+
// build report category stats starts
1903+
if (collectStats == false && line.IndexOf("Uncompressed usage by category (Percentages based on user generated assets only):") == 0)
18911904
{
1892-
buildReports.Add(subList);
1893-
collect = false;
1905+
// init new list for this build report
1906+
singleReport.Stats = new List<BuildReportItem>();
1907+
collectStats = true;
1908+
continue;
18941909
}
18951910

1896-
if (collect == true)
1911+
// build report ends with elapsed time
1912+
if (collectedBuildTime == false && line.IndexOf("Build completed with a result of 'Succeeded' in ") == 0)
18971913
{
1898-
subList.Add(line);
1914+
var ms = line.Substring(line.IndexOf("(") + 1, line.IndexOf(")") - line.IndexOf("(") - 1).Trim().Replace(" ms", "");
1915+
singleReport.ElapsedTimeMS = long.Parse(ms);
1916+
collectedBuildTime = true;
1917+
1918+
// get streamingassets folder size and add to report, NOTE need to recalculate sizes then?
1919+
long streamingAssetFolderSize = Tools.GetFolderSizeInBytes(Path.Combine(currentBuildReportProjectPath, "Assets", "StreamingAssets"));
1920+
singleReport.Stats.Insert(singleReport.Stats.Count - 1, new BuildReportItem() { Category = "StreamingAssets", Size = Tools.GetBytesReadable(streamingAssetFolderSize) });
1921+
1922+
// add all rows and stat rows for this build report
1923+
buildReports.Add(singleReport);
1924+
1925+
// make new
1926+
singleReport = new BuildReport();
1927+
continue;
1928+
}
1929+
1930+
// build report ends for rows
1931+
if (collectRows == true && line.IndexOf("-------------------------------------------------------------------------------") == 0)
1932+
{
1933+
collectRows = false;
1934+
collectedBuildTime = false;
1935+
continue;
1936+
}
1937+
1938+
// parse and add this line to current build report
1939+
if (collectRows == true)
1940+
{
1941+
var line2 = line.Trim();
1942+
// get tab after kb
1943+
var space1 = line2.IndexOf('\t');
1944+
// get % between % and path
1945+
var space2 = line2.IndexOf('%');
1946+
1947+
if (space1 == -1 || space2 == -1)
1948+
{
1949+
Console.WriteLine(("Failed to parse build report row: " + line2));
1950+
continue;
1951+
}
1952+
1953+
// create single row
1954+
var r = new BuildReportItem();
1955+
r.Size = line2.Substring(0, space1);
1956+
r.Percentage = line2.Substring(space1 + 2, space2 - space1 - 1);
1957+
r.Path = line2.Substring(space2 + 2, line2.Length - space2 - 2);
1958+
r.Format = Path.GetExtension(r.Path);
1959+
1960+
singleReport.Items.Add(r);
1961+
}
1962+
1963+
1964+
if (collectStats == true)
1965+
{
1966+
var line2 = line.Trim();
1967+
// get 2xspace after category name
1968+
var space1 = line2.IndexOf(" ");
1969+
// get tab after first size
1970+
var space2 = line2.IndexOf('\t');
1971+
// last row didnt contain tab "Complete build size"
1972+
bool lastRow = false;
1973+
if (space2 == -1)
1974+
{
1975+
space2 = line2.Length - 1;
1976+
lastRow = true;
1977+
}
1978+
1979+
if (space1 == -1 || space2 == -1)
1980+
{
1981+
Console.WriteLine(("(2) Failed to parse build report row: " + line2));
1982+
continue;
1983+
}
1984+
1985+
// create single row
1986+
var r = new BuildReportItem();
1987+
r.Category = line2.Substring(0, space1).Trim();
1988+
r.Size = line2.Substring(space1 + 2, space2 - space1 - 1).Trim();
1989+
if (lastRow == false) r.Percentage = line2.Substring(space2 + 2, line2.Length - space2 - 2).Trim();
1990+
1991+
singleReport.Stats.Add(r);
18991992
}
19001993
}
19011994
}
@@ -1905,18 +1998,40 @@ void RefreshBuildReports()
19051998
{
19061999
gridBuildReport.ItemsSource = null;
19072000
gridBuildReport.Items.Clear();
1908-
Console.WriteLine("Failed to open editor log: " + logFile);
2001+
2002+
gridBuildReportData.ItemsSource = null;
2003+
gridBuildReportData.Items.Clear();
2004+
2005+
txtBuildTime.Text = "";
2006+
2007+
Console.WriteLine("Failed to open editor log or other error in parsing: " + logFile);
19092008
return;
19102009
}
19112010

1912-
if (buildReports.Count < 1 || buildReports[0].Count < 1)
2011+
// no build reports found
2012+
if (buildReports.Count == 0)
19132013
{
19142014
gridBuildReport.ItemsSource = null;
19152015
gridBuildReport.Items.Clear();
2016+
2017+
gridBuildReportData.ItemsSource = null;
2018+
gridBuildReportData.Items.Clear();
2019+
2020+
txtBuildTime.Text = "";
2021+
19162022
Console.WriteLine("Failed to parse Editor.Log (probably no build reports there)");
19172023
return;
19182024
}
19192025

2026+
// remove streaming assets info, keep only for last build (because older builds might have had different files there, we dont know)
2027+
for (int i = 0; i < buildReports.Count - 1; i++)
2028+
{
2029+
buildReports[i].Stats[buildReports[i].Stats.Count - 2].Size = "???";
2030+
}
2031+
2032+
// reverse build reports, so that latest is first
2033+
buildReports.Reverse();
2034+
19202035
DisplayBuildReport(currentBuildReport);
19212036
}
19222037

@@ -1942,38 +2057,17 @@ void DisplayBuildReport(int index)
19422057
currentBuildReport = buildReports.Count - 1;
19432058
}
19442059

1945-
// create build report rows array
1946-
var reportSource = new List<BuildReportItem>();
1947-
1948-
// parse actual report rows
1949-
for (int i = 0, len = buildReports[currentBuildReport].Count; i < len; i++)
1950-
{
1951-
var d = buildReports[currentBuildReport][i].Trim();
1952-
1953-
// get tab after kb
1954-
var space1 = d.IndexOf('\t');
1955-
// get % between % and path
1956-
var space2 = d.IndexOf('%');
1957-
1958-
if (space1 == -1 || space2 == -1)
1959-
{
1960-
Console.WriteLine("Failed to parse build report row: " + d);
1961-
continue;
1962-
}
1963-
1964-
// create single row
1965-
var r = new BuildReportItem();
1966-
r.Size = d.Substring(0, space1);
1967-
r.Percentage = d.Substring(space1 + 2, space2 - space1 - 1);
1968-
r.Path = d.Substring(space2 + 2, d.Length - space2 - 2);
1969-
r.Format = Path.GetExtension(r.Path);
1970-
1971-
reportSource.Add(r);
1972-
}
1973-
19742060
gridBuildReport.ItemsSource = null;
19752061
gridBuildReport.Items.Clear();
1976-
gridBuildReport.ItemsSource = reportSource;
2062+
gridBuildReport.ItemsSource = buildReports[currentBuildReport].Items;
2063+
2064+
gridBuildReportData.ItemsSource = null;
2065+
gridBuildReportData.Items.Clear();
2066+
gridBuildReportData.ItemsSource = buildReports[currentBuildReport].Stats;
2067+
2068+
var time = TimeSpan.FromMilliseconds(buildReports[currentBuildReport].ElapsedTimeMS);
2069+
var dt = new DateTime(time.Ticks);
2070+
txtBuildTime.Text = dt.ToString("HH 'hours' mm 'minutes' ss 'seconds'");
19772071

19782072
UpdateBuildReportLabelAndButtons();
19792073
}
@@ -1983,11 +2077,13 @@ void UpdateBuildReportLabelAndButtons()
19832077
btnPrevBuildReport.IsEnabled = currentBuildReport > 0;
19842078
btnNextBuildReport.IsEnabled = currentBuildReport < buildReports.Count - 1;
19852079
lblBuildReportIndex.Content = (buildReports.Count == 0 ? 0 : (currentBuildReport + 1)) + "/" + (buildReports.Count);
2080+
txtBuildTime.Text = "";
19862081
}
19872082

19882083
private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
19892084
{
19902085
gridBuildReport.ItemsSource = null;
2086+
gridBuildReportData.ItemsSource = null;
19912087
currentBuildReport = 0;
19922088
buildReports.Clear();
19932089
UpdateBuildReportLabelAndButtons();

0 commit comments

Comments
 (0)