@@ -54,7 +54,8 @@ public partial class MainWindow : Window
54
54
Dictionary < string , SolidColorBrush > origResourceColors = new Dictionary < string , SolidColorBrush > ( ) ;
55
55
56
56
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
58
59
int currentBuildReport = 0 ;
59
60
60
61
[ DllImport ( "user32" , CharSet = CharSet . Unicode ) ]
@@ -1844,6 +1845,7 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
1844
1845
void RefreshBuildReports ( )
1845
1846
{
1846
1847
currentBuildReport = 0 ;
1848
+ // delete all reports
1847
1849
buildReports . Clear ( ) ;
1848
1850
UpdateBuildReportLabelAndButtons ( ) ;
1849
1851
@@ -1853,17 +1855,21 @@ void RefreshBuildReports()
1853
1855
var logFile = Path . Combine ( Tools . GetEditorLogsFolder ( ) , "Editor.log" ) ;
1854
1856
if ( File . Exists ( logFile ) == false ) return ;
1855
1857
1856
- List < string > subList = null ;
1858
+ BuildReport singleReport = new BuildReport ( ) ;
1857
1859
1858
1860
try
1859
1861
{
1860
1862
using ( FileStream fs = new FileStream ( logFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
1861
1863
{
1862
1864
using ( StreamReader sr = new StreamReader ( fs ) )
1863
1865
{
1864
- bool collect = false ;
1866
+ bool collectRows = false ; // actual log rows
1867
+ bool collectStats = false ; // category stat rows
1868
+ bool collectedBuildTime = false ;
1869
+
1865
1870
bool gotProjectPath = false ;
1866
1871
1872
+ // TODO cleanup here
1867
1873
while ( ! sr . EndOfStream )
1868
1874
{
1869
1875
var line = sr . ReadLine ( ) ;
@@ -1877,25 +1883,112 @@ void RefreshBuildReports()
1877
1883
if ( line == "-projectPath" ) gotProjectPath = true ;
1878
1884
1879
1885
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 )
1882
1888
{
1883
1889
// 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
+
1886
1899
continue ;
1887
1900
}
1888
1901
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 )
1891
1904
{
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 ;
1894
1909
}
1895
1910
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 )
1897
1913
{
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 ) ;
1899
1992
}
1900
1993
}
1901
1994
}
@@ -1905,18 +1998,40 @@ void RefreshBuildReports()
1905
1998
{
1906
1999
gridBuildReport . ItemsSource = null ;
1907
2000
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 ) ;
1909
2008
return ;
1910
2009
}
1911
2010
1912
- if ( buildReports . Count < 1 || buildReports [ 0 ] . Count < 1 )
2011
+ // no build reports found
2012
+ if ( buildReports . Count == 0 )
1913
2013
{
1914
2014
gridBuildReport . ItemsSource = null ;
1915
2015
gridBuildReport . Items . Clear ( ) ;
2016
+
2017
+ gridBuildReportData . ItemsSource = null ;
2018
+ gridBuildReportData . Items . Clear ( ) ;
2019
+
2020
+ txtBuildTime . Text = "" ;
2021
+
1916
2022
Console . WriteLine ( "Failed to parse Editor.Log (probably no build reports there)" ) ;
1917
2023
return ;
1918
2024
}
1919
2025
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
+
1920
2035
DisplayBuildReport ( currentBuildReport ) ;
1921
2036
}
1922
2037
@@ -1942,38 +2057,17 @@ void DisplayBuildReport(int index)
1942
2057
currentBuildReport = buildReports . Count - 1 ;
1943
2058
}
1944
2059
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
-
1974
2060
gridBuildReport . ItemsSource = null ;
1975
2061
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'" ) ;
1977
2071
1978
2072
UpdateBuildReportLabelAndButtons ( ) ;
1979
2073
}
@@ -1983,11 +2077,13 @@ void UpdateBuildReportLabelAndButtons()
1983
2077
btnPrevBuildReport . IsEnabled = currentBuildReport > 0 ;
1984
2078
btnNextBuildReport . IsEnabled = currentBuildReport < buildReports . Count - 1 ;
1985
2079
lblBuildReportIndex . Content = ( buildReports . Count == 0 ? 0 : ( currentBuildReport + 1 ) ) + "/" + ( buildReports . Count ) ;
2080
+ txtBuildTime . Text = "" ;
1986
2081
}
1987
2082
1988
2083
private void BtnClearBuildReport_Click ( object sender , RoutedEventArgs e )
1989
2084
{
1990
2085
gridBuildReport . ItemsSource = null ;
2086
+ gridBuildReportData . ItemsSource = null ;
1991
2087
currentBuildReport = 0 ;
1992
2088
buildReports . Clear ( ) ;
1993
2089
UpdateBuildReportLabelAndButtons ( ) ;
0 commit comments