@@ -215,6 +215,38 @@ bool FileIsCached(string src, string dest)
215215 return options . Cache && FileIsUpToDate ( src , dest ) ;
216216 }
217217
218+ /// <summary>
219+ /// Extracts compilation-wide entities, such as compilations and compiler diagnostics.
220+ /// </summary>
221+ public void AnalyseCompilation ( string cwd , string [ ] args )
222+ {
223+ extractionTasks . Add ( ( ) => DoAnalyseCompilation ( cwd , args ) ) ;
224+ }
225+
226+ Entities . Compilation compilationEntity ;
227+ IDisposable compilationTrapFile ;
228+
229+ void DoAnalyseCompilation ( string cwd , string [ ] args )
230+ {
231+ try
232+ {
233+ var assemblyPath = extractor . OutputPath ;
234+ var assembly = compilation . Assembly ;
235+ var projectLayout = layout . LookupProjectOrDefault ( assemblyPath ) ;
236+ var trapWriter = projectLayout . CreateTrapWriter ( Logger , assemblyPath , true ) ;
237+ compilationTrapFile = trapWriter ; // Dispose later
238+ var cx = extractor . CreateContext ( compilation . Clone ( ) , trapWriter , new AssemblyScope ( assembly , assemblyPath , true ) ) ;
239+
240+ compilationEntity = new Entities . Compilation ( cx , cwd , args ) ;
241+ }
242+ catch ( Exception ex ) // lgtm[cs/catch-of-all-exceptions]
243+ {
244+ Logger . Log ( Severity . Error , " Unhandled exception analyzing {0}: {1}" , "compilation" , ex ) ;
245+ }
246+ }
247+
248+ public void LogPerformance ( Entities . Performance p ) => compilationEntity . PopulatePerformance ( p ) ;
249+
218250 /// <summary>
219251 /// Extract an assembly to a new trap file.
220252 /// If the trap file exists, skip extraction to avoid duplicating
@@ -258,7 +290,7 @@ void DoAnalyseAssembly(PortableExecutableReference r)
258290
259291 if ( assembly != null )
260292 {
261- var cx = new Context ( extractor , c , trapWriter , new AssemblyScope ( assembly , assemblyPath ) ) ;
293+ var cx = extractor . CreateContext ( c , trapWriter , new AssemblyScope ( assembly , assemblyPath , false ) ) ;
262294
263295 foreach ( var module in assembly . Modules )
264296 {
@@ -344,7 +376,7 @@ void DoExtractTree(SyntaxTree tree)
344376
345377 if ( ! upToDate )
346378 {
347- Context cx = new Context ( extractor , compilation . Clone ( ) , trapWriter , new SourceScope ( tree ) ) ;
379+ Context cx = extractor . CreateContext ( compilation . Clone ( ) , trapWriter , new SourceScope ( tree ) ) ;
348380 Populators . CompilationUnit . Extract ( cx , tree . GetRoot ( ) ) ;
349381 cx . PopulateAll ( ) ;
350382 cx . ExtractComments ( cx . CommentGenerator ) ;
@@ -373,6 +405,8 @@ public void PerformExtraction(int numberOfThreads)
373405
374406 public void Dispose ( )
375407 {
408+ compilationTrapFile ? . Dispose ( ) ;
409+
376410 stopWatch . Stop ( ) ;
377411 Logger . Log ( Severity . Info , " Peak working set = {0} MB" , Process . GetCurrentProcess ( ) . PeakWorkingSet64 / ( 1024 * 1024 ) ) ;
378412
0 commit comments