4444#include " llvm/Object/CVDebugRecord.h"
4545#include " llvm/Support/CRC.h"
4646#include " llvm/Support/Endian.h"
47- #include " llvm/Support/FormatAdapters.h"
4847#include " llvm/Support/FormatVariadic.h"
4948#include " llvm/Support/Path.h"
5049#include " llvm/Support/ScopedPrinter.h"
@@ -133,8 +132,8 @@ class PDBLinker {
133132 // / Write the PDB to disk and store the Guid generated for it in *Guid.
134133 void commit (codeview::GUID *guid);
135134
136- // Print statistics regarding the final PDB
137- void printStats ();
135+ // Collect some statistics regarding the final PDB
136+ void collectStats ();
138137
139138private:
140139 void pdbMakeAbsolute (SmallVectorImpl<char > &fileName);
@@ -154,13 +153,6 @@ class PDBLinker {
154153 DebugStringTableSubsection pdbStrTab;
155154
156155 llvm::SmallString<128 > nativePath;
157-
158- // For statistics
159- uint64_t globalSymbols = 0 ;
160- uint64_t moduleSymbols = 0 ;
161- uint64_t publicSymbols = 0 ;
162- uint64_t nbTypeRecords = 0 ;
163- uint64_t nbTypeRecordsBytes = 0 ;
164156};
165157
166158// / Represents an unrelocated DEBUG_S_FRAMEDATA subsection.
@@ -610,7 +602,9 @@ void PDBLinker::analyzeSymbolSubsection(
610602 addGlobalSymbol (builder.getGsiBuilder (),
611603 file->moduleDBI ->getModuleIndex (), moduleSymOffset,
612604 storage);
613- ++globalSymbols;
605+
606+ if (ctx.pdbStats .has_value ())
607+ ++ctx.pdbStats ->globalSymbols ;
614608 }
615609
616610 // Update the module stream offset and record any string table index
@@ -619,7 +613,9 @@ void PDBLinker::analyzeSymbolSubsection(
619613 if (symbolGoesInModuleStream (sym, scopeLevel)) {
620614 recordStringTableReferences (sym, moduleSymOffset, stringTableFixups);
621615 moduleSymOffset += alignedSize;
622- ++moduleSymbols;
616+
617+ if (ctx.pdbStats .has_value ())
618+ ++ctx.pdbStats ->moduleSymbols ;
623619 }
624620
625621 return Error::success ();
@@ -1192,10 +1188,10 @@ void PDBLinker::addObjectsToPDB() {
11921188 }
11931189 }
11941190
1195- if (ctx.config . showSummary ) {
1191+ if (ctx.pdbStats . has_value () ) {
11961192 for (TpiSource *source : ctx.tpiSourceList ) {
1197- nbTypeRecords += source->nbTypeRecords ;
1198- nbTypeRecordsBytes += source->nbTypeRecordsBytes ;
1193+ ctx. pdbStats -> nbTypeRecords += source->nbTypeRecords ;
1194+ ctx. pdbStats -> nbTypeRecordsBytes += source->nbTypeRecordsBytes ;
11991195 }
12001196 }
12011197}
@@ -1231,43 +1227,24 @@ void PDBLinker::addPublicsToPDB() {
12311227 }
12321228 });
12331229
1234- if (!publics.empty ()) {
1235- publicSymbols = publics.size ();
1230+ if (ctx.pdbStats .has_value ())
1231+ ctx.pdbStats ->publicSymbols = publics.size ();
1232+
1233+ if (!publics.empty ())
12361234 gsiBuilder.addPublicSymbols (std::move (publics));
1237- }
12381235}
12391236
1240- void PDBLinker::printStats () {
1237+ void PDBLinker::collectStats () {
12411238 if (!ctx.config .showSummary )
12421239 return ;
12431240
1241+ ctx.pdbStats ->nbTPIrecords = builder.getTpiBuilder ().getRecordCount ();
1242+ ctx.pdbStats ->nbIPIrecords = builder.getIpiBuilder ().getRecordCount ();
1243+ ctx.pdbStats ->strTabSize = pdbStrTab.size ();
1244+
12441245 SmallString<256 > buffer;
12451246 raw_svector_ostream stream (buffer);
12461247
1247- stream << center_justify (" Summary" , 80 ) << ' \n '
1248- << std::string (80 , ' -' ) << ' \n ' ;
1249-
1250- auto print = [&](uint64_t v, StringRef s) {
1251- stream << formatv (" {0}" ,
1252- fmt_align (formatv (" {0:N}" , v), AlignStyle::Right, 20 ))
1253- << " " << s << ' \n ' ;
1254- };
1255-
1256- print (ctx.objFileInstances .size (),
1257- " Input OBJ files (expanded from all cmd-line inputs)" );
1258- print (ctx.consumedInputsSize ,
1259- " Size of all consumed OBJ files (non-lazy), in bytes" );
1260- print (ctx.typeServerSourceMappings .size (), " PDB type server dependencies" );
1261- print (ctx.precompSourceMappings .size (), " Precomp OBJ dependencies" );
1262- print (nbTypeRecords, " Input type records" );
1263- print (nbTypeRecordsBytes, " Size of all input type records, in bytes" );
1264- print (builder.getTpiBuilder ().getRecordCount (), " Merged TPI records" );
1265- print (builder.getIpiBuilder ().getRecordCount (), " Merged IPI records" );
1266- print (pdbStrTab.size (), " Output PDB strings" );
1267- print (globalSymbols, " Global symbol records" );
1268- print (moduleSymbols, " Module symbol records" );
1269- print (publicSymbols, " Public symbol records" );
1270-
12711248 auto printLargeInputTypeRecs = [&](StringRef name,
12721249 ArrayRef<uint32_t > recCounts,
12731250 TypeCollection &records) {
@@ -1318,9 +1295,9 @@ void PDBLinker::printStats() {
13181295 // FIXME: Reimplement for ghash.
13191296 printLargeInputTypeRecs (" TPI" , tMerger.tpiCounts , tMerger.getTypeTable ());
13201297 printLargeInputTypeRecs (" IPI" , tMerger.ipiCounts , tMerger.getIDTable ());
1321- }
13221298
1323- Msg (ctx) << buffer;
1299+ ctx.pdbStats ->largeInputTypeRecs = buffer.str ();
1300+ }
13241301}
13251302
13261303void PDBLinker::addNatvisFiles () {
@@ -1624,6 +1601,9 @@ void lld::coff::createPDB(COFFLinkerContext &ctx,
16241601 {
16251602 PDBLinker pdb (ctx);
16261603
1604+ if (ctx.config .showSummary )
1605+ ctx.pdbStats .emplace ();
1606+
16271607 pdb.initialize (buildId);
16281608 pdb.addObjectsToPDB ();
16291609 pdb.addImportFilesToPDB ();
@@ -1640,8 +1620,8 @@ void lld::coff::createPDB(COFFLinkerContext &ctx,
16401620 memcpy (&buildId->PDB70 .Signature , &guid, 16 );
16411621 }
16421622
1623+ pdb.collectStats ();
16431624 t1.stop ();
1644- pdb.printStats ();
16451625
16461626 // Manually start this profile point to measure ~PDBLinker().
16471627 if (getTimeTraceProfilerInstance () != nullptr )
0 commit comments