Skip to content

Commit

Permalink
For expensive headers, print which places included them the most times
Browse files Browse the repository at this point in the history
  • Loading branch information
aras-p committed Aug 12, 2023
1 parent f32e70a commit 5c75a05
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 2 deletions.
39 changes: 38 additions & 1 deletion src/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ void Analysis::EndAnalysis()
if (!expensiveHeaders.empty())
{
fprintf(out, "%s%s**** Expensive headers%s:\n", col::kBold, col::kMagenta, col::kReset);
ska::bytell_hash_map<DetailIndex, int> includedFromMap;
std::vector<std::pair<DetailIndex, int>> includedFromArray;
for (const auto& e : expensiveHeaders)
{
const auto& es = headerMap[e.first];
Expand All @@ -495,14 +497,14 @@ void Analysis::EndAnalysis()
fprintf(out, "%s%i%s ms: %s%s%s (included %i times, avg %i ms), included via:\n", col::kBold, ms, col::kReset, col::kBold, e.first.data(), col::kReset, es.count, avg);
int pathCount = 0;

// print most costly include chains
auto sortedIncludeChains = es.includePaths;
std::sort(sortedIncludeChains.begin(), sortedIncludeChains.end(), [](const auto& a, const auto& b)
{
if (a.us != b.us)
return a.us > b.us;
return a.files < b.files;
});

for (const auto& chain : sortedIncludeChains)
{
fprintf(out, " ");
Expand All @@ -519,6 +521,41 @@ void Analysis::EndAnalysis()
{
fprintf(out, " ...\n");
}

// print most often happening includers
includedFromMap.clear();
for (const auto& chain : sortedIncludeChains)
{
if (chain.files.empty())
continue;
includedFromMap[chain.files.front()]++;
}
includedFromArray.resize(0);
includedFromArray.reserve(includedFromMap.size());
for (const auto& from : includedFromMap)
{
includedFromArray.push_back(from);
}
std::sort(includedFromArray.begin(), includedFromArray.end(), [](const auto& a, const auto& b)
{
if (a.second != b.second)
return a.second > b.second;
return a.first < b.first;
});
pathCount = 0;
fprintf(out, " included mostly from:\n");
for (const auto& from : includedFromArray)
{
fprintf(out, " %i: %s\n", from.second, utils::GetFilename(GetBuildName(from.first)).data());
++pathCount;
if (pathCount > config.headerChainCount)
break;
}
if (pathCount > config.headerChainCount)
{
fprintf(out, " ...\n");
}

fprintf(out, "\n");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
struct IUnknown; // workaround for old Win SDK header failures when using /permissive-
#endif

static const char* kVersion = "1.4.1";
static const char* kVersion = "1.5.0";

#include "external/enkiTS/TaskScheduler.h"
#define SOKOL_IMPL
Expand Down
1 change: 1 addition & 0 deletions tests/clang11-pid-45/_AnalysisOutputExpected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Compilation (1 times):
1 ms: main (test.cc)

**** Function sets that took longest to compile / optimize:

17 changes: 17 additions & 0 deletions tests/hlsl2glsl-mac-clang-10.0-dev/_AnalysisOutputExpected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,40 @@ Compilation (4 times):
**** Expensive headers:
794 ms: hlslang/OSDependent/Mac/osinclude.h (included 1 times, avg 794 ms), included via:
hlslLinker.json (794 ms)
included mostly from:
1: hlslLinker.json

559 ms: hlslang/GLSLCodeGen/glslFunction.h (included 3 times, avg 186 ms), included via:
glslFunction.json (458 ms)
hlslLinker.json hlslLinker.h (73 ms)
glslOutput.json glslOutput.h (27 ms)
included mostly from:
1: glslFunction.json
1: glslOutput.h
1: hlslLinker.h

464 ms: hlslang/GLSLCodeGen/glslOutput.h (included 1 times, avg 464 ms), included via:
glslOutput.json (464 ms)
included mostly from:
1: glslOutput.json

459 ms: hlslang/GLSLCodeGen/hlslLinker.h (included 1 times, avg 459 ms), included via:
hlslLinker.json (459 ms)
included mostly from:
1: hlslLinker.json

453 ms: hlslang/GLSLCodeGen/glslStruct.h (included 4 times, avg 113 ms), included via:
glslCommon.json (446 ms)
glslFunction.json glslFunction.h (2 ms)
glslOutput.json glslOutput.h (2 ms)
hlslLinker.json hlslLinker.h glslFunction.h (2 ms)
included mostly from:
2: glslFunction.h
1: glslCommon.json
1: glslOutput.h

3 ms: hlslang/GLSLCodeGen/hlslCrossCompiler.h (included 1 times, avg 3 ms), included via:
hlslLinker.json (3 ms)
included mostly from:
1: hlslLinker.json

Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,51 @@ Compilation (2 times):
**** Expensive headers:
1287 ms: /libo2/include/vcl/svapp.hxx (included 1 times, avg 1287 ms), included via:
SkiaHelper.json (1287 ms)
included mostly from:
1: SkiaHelper.json

927 ms: /libo2/vcl/inc/skia/utils.hxx (included 1 times, avg 927 ms), included via:
SkiaHelper.json (927 ms)
included mostly from:
1: SkiaHelper.json

246 ms: /libo2/workdir/CustomTarget/officecfg/registry/officecfg/Office/Common.hxx (included 1 times, avg 246 ms), included via:
SkiaHelper.json (246 ms)
included mostly from:
1: SkiaHelper.json

47 ms: /libo2/include/desktop/crashreport.hxx (included 1 times, avg 47 ms), included via:
SkiaHelper.json (47 ms)
included mostly from:
1: SkiaHelper.json

29 ms: /usr/include/c++/9/fstream (included 1 times, avg 29 ms), included via:
SkiaHelper.json (29 ms)
included mostly from:
1: SkiaHelper.json

10 ms: /libo2/vcl/inc/skia/zone.hxx (included 1 times, avg 10 ms), included via:
SkiaHelper.json (10 ms)
included mostly from:
1: SkiaHelper.json

8 ms: /libo2/vcl/inc/watchdog.hxx (included 1 times, avg 8 ms), included via:
SkiaHelper.json (8 ms)
included mostly from:
1: SkiaHelper.json

4 ms: /libo2/include/vcl/skia/SkiaHelper.hxx (included 1 times, avg 4 ms), included via:
SkiaHelper.json (4 ms)
included mostly from:
1: SkiaHelper.json

3 ms: /libo2/workdir/UnpackedTarball/skia/include/core/SkSurface.h (included 1 times, avg 3 ms), included via:
SkiaHelper.json (3 ms)
included mostly from:
1: SkiaHelper.json

1 ms: /libo2/include/sal/log.hxx (included 1 times, avg 1 ms), included via:
SkiaHelper.json (1 ms)
included mostly from:
1: SkiaHelper.json

28 changes: 28 additions & 0 deletions tests/self-win-clang-13.0/_AnalysisOutputExpected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,41 +151,69 @@ Compilation (8 times):
Analysis.json Analysis.h (263 ms)
BuildEvents.json (257 ms)
main.json Analysis.h (253 ms)
included mostly from:
2: Analysis.h
1: BuildEvents.json

583 ms: src/external/cute_files.h (included 2 times, avg 291 ms), included via:
BuildEvents.json (577 ms)
main.json (6 ms)
included mostly from:
1: main.json
1: BuildEvents.json

518 ms: src/Analysis.h (included 2 times, avg 259 ms), included via:
Analysis.json (264 ms)
main.json (254 ms)
included mostly from:
1: main.json
1: Analysis.json

276 ms: src/external/sokol_time.h (included 1 times, avg 276 ms), included via:
main.json (276 ms)
included mostly from:
1: main.json

257 ms: src/external/simdjson/simdjson.h (included 1 times, avg 257 ms), included via:
BuildEvents.json (257 ms)
included mostly from:
1: BuildEvents.json

232 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30037/include/algorithm (included 4 times, avg 58 ms), included via:
Arena.json (188 ms)
main.json (14 ms)
BuildEvents.json bytell_hash_map.hpp (14 ms)
Analysis.json bytell_hash_map.hpp (14 ms)
included mostly from:
2: bytell_hash_map.hpp
1: Arena.json
1: main.json

226 ms: src/external/flat_hash_map/bytell_hash_map.hpp (included 2 times, avg 113 ms), included via:
Analysis.json (114 ms)
BuildEvents.json (112 ms)
included mostly from:
1: BuildEvents.json
1: Analysis.json

159 ms: src/external/enkiTS/TaskScheduler.h (included 1 times, avg 159 ms), included via:
main.json (159 ms)
included mostly from:
1: main.json

71 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30037/include/mutex (included 2 times, avg 35 ms), included via:
BuildEvents.json (51 ms)
main.json TaskScheduler.h condition_variable (19 ms)
included mostly from:
1: condition_variable
1: BuildEvents.json

52 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30037/include/vector (included 4 times, avg 13 ms), included via:
Arena.json (22 ms)
Analysis.json Analysis.h BuildEvents.h (10 ms)
main.json Analysis.h BuildEvents.h (10 ms)
BuildEvents.json BuildEvents.h (10 ms)
included mostly from:
3: BuildEvents.h
1: Arena.json

25 changes: 25 additions & 0 deletions tests/self-win-clang-cl-10.0rc2/_AnalysisOutputExpected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,60 @@ Compilation (6 times):
701 ms: C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/um/windows.h (included 2 times, avg 350 ms), included via:
Allocator.json (352 ms)
main.json sokol_time.h (348 ms)
included mostly from:
1: Allocator.json
1: sokol_time.h

587 ms: src/BuildEvents.h (included 2 times, avg 293 ms), included via:
BuildEvents.json (305 ms)
main.json Analysis.h (282 ms)
included mostly from:
1: Analysis.h
1: BuildEvents.json

353 ms: src/external/sokol_time.h (included 1 times, avg 353 ms), included via:
main.json (353 ms)
included mostly from:
1: main.json

282 ms: src/Analysis.h (included 1 times, avg 282 ms), included via:
main.json (282 ms)
included mostly from:
1: main.json

255 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.25.28610/include/algorithm (included 3 times, avg 85 ms), included via:
Allocator.json (233 ms)
BuildEvents.json sajson.h (12 ms)
main.json (10 ms)
included mostly from:
1: Allocator.json
1: main.json
1: sajson.h

210 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.25.28610/include/iterator (included 1 times, avg 210 ms), included via:
BuildEvents.json (210 ms)
included mostly from:
1: BuildEvents.json

55 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.25.28610/include/unordered_map (included 1 times, avg 55 ms), included via:
BuildEvents.json (55 ms)
included mostly from:
1: BuildEvents.json

52 ms: src/external/sajson.h (included 1 times, avg 52 ms), included via:
BuildEvents.json (52 ms)
included mostly from:
1: BuildEvents.json

41 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.25.28610/include/stdexcept (included 2 times, avg 20 ms), included via:
Allocator.json (38 ms)
BuildEvents.json iterator istream ostream ios xlocnum streambuf xiosbase system_error (2 ms)
included mostly from:
1: Allocator.json
1: system_error

26 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.25.28610/include/map (included 1 times, avg 26 ms), included via:
main.json (26 ms)
included mostly from:
1: main.json

10 changes: 10 additions & 0 deletions tests/self-win-clang-cl-9.0rc2/_AnalysisOutputExpected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,23 @@ Compilation (3 times):
Colors.json (715 ms)
Utils.json (683 ms)
Allocator.json (341 ms)
included mostly from:
1: Allocator.json
1: Colors.json
1: Utils.json

231 ms: src/Utils.h (included 1 times, avg 231 ms), included via:
Utils.json (231 ms)
included mostly from:
1: Utils.json

209 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.22.27905/include/algorithm (included 1 times, avg 209 ms), included via:
Allocator.json (209 ms)
included mostly from:
1: Allocator.json

35 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.22.27905/include/stdexcept (included 1 times, avg 35 ms), included via:
Allocator.json (35 ms)
included mostly from:
1: Allocator.json

6 changes: 6 additions & 0 deletions tests/verylong-symbol-name-38/_AnalysisOutputExpected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ Compilation (2 times):
**** Expensive headers:
191 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/include/string (included 1 times, avg 191 ms), included via:
test.json (191 ms)
included mostly from:
1: test.json

19 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/include/map (included 1 times, avg 19 ms), included via:
test.json (19 ms)
included mostly from:
1: test.json

7 ms: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/include/vector (included 1 times, avg 7 ms), included via:
test.json (7 ms)
included mostly from:
1: test.json

0 comments on commit 5c75a05

Please sign in to comment.