Skip to content

[Stats] Track NumASTBytesAllocated continuously #19609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jrose-apple
Copy link
Contributor

…so it can be used with -profile-stats-events and -profile-stats-entities to produce flamegraphs.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

Here's a flamegraph of generating the standard library module: AST.NumASTBytesAllocated.events.svg.zip. I really want to do this based on -profile-stats-entities, but that takes over 20GB of memory on my machine with only 16GB of physical RAM, so I guess I'll have to try it somewhere else.

@@ -300,7 +300,9 @@ class ASTContext final {

if (LangOpts.UseMalloc)
return AlignedAlloc(bytes, alignment);


if (arena == AllocationArena::Permanent && Stats)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this && Stats doesn't seem to be being respected. I wonder why.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's crashing in the ASTContext constructor, presumably before Stats is itself initialized.

Nice change otherwise!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…I feel silly. Thanks for catching that!

Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you can figure out the right initialization dance to not crash, looks good!

Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, actually, now that I think about this I'm not sure it's quite right: NumASTBytesAllocated tracks the set of bytes allocated at the end of allocating, but I'm not 100% sure we don't reset that arena from time to time (though I suspect we don't). The framework for stats-counting in general and profiling in particular assumes monotonic growth in counters.

(Still approved if this is not a problem, but I'm just not .. sure)

@jrose-apple
Copy link
Contributor Author

Er, actually, now that I think about this I'm not sure it's quite right: NumASTBytesAllocated tracks the set of bytes allocated at the end of allocating, but I'm not 100% sure we don't reset that arena from time to time (though I suspect we don't). The framework for stats-counting in general and profiling in particular assumes monotonic growth in counters.

We don't reset the arena, but the hole I noticed is that any allocations done before the stats reporter is set up won't be counted. I can add that to setStatsReporter, though.

@jrose-apple jrose-apple force-pushed the your-code-is-programmed-not-to-love-me-but-you-cant-pretend branch from 42d73f0 to 9e56a8e Compare September 28, 2018 20:43
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test compiler performance

1 similar comment
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test compiler performance

@swift-ci
Copy link
Contributor

Build comment file:

Summary for master smoketest

Unexpected test results, excluded stats for Kingfisher, ReactiveCocoa

No regressions above thresholds

Debug

debug brief

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 183,870,680,556 183,919,853,993 49,173,437 0.03%
LLVM.NumLLVMBytesOutput 9,519,684 9,519,684 0 0.0%
time.swift-driver.wall 23.7s 23.7s -67.3ms -0.28%

debug detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 5,914 5,914 0 0.0%
AST.NumLoadedModules 1,510 1,510 0 0.0%
AST.NumTotalClangImportedEntities 18,273 18,273 0 0.0%
AST.NumUsedConformances 1,346 1,346 0 0.0%
IRModule.NumIRBasicBlocks 32,510 32,510 0 0.0%
IRModule.NumIRFunctions 16,732 16,732 0 0.0%
IRModule.NumIRGlobals 14,495 14,495 0 0.0%
IRModule.NumIRInsts 445,415 445,415 0 0.0%
IRModule.NumIRValueSymbols 29,947 29,947 0 0.0%
LLVM.NumLLVMBytesOutput 9,519,684 9,519,684 0 0.0%
SILModule.NumSILGenFunctions 7,845 7,845 0 0.0%
SILModule.NumSILOptFunctions 10,598 10,598 0 0.0%
Sema.NumConformancesDeserialized 23,105 23,105 0 0.0%
Sema.NumConstraintScopes 70,890 70,890 0 0.0%
Sema.NumDeclsDeserialized 265,179 265,179 0 0.0%
Sema.NumDeclsValidated 16,641 16,641 0 0.0%
Sema.NumFunctionsTypechecked 7,044 7,044 0 0.0%
Sema.NumGenericSignatureBuilders 7,760 7,760 0 0.0%
Sema.NumLazyGenericEnvironments 61,052 61,052 0 0.0%
Sema.NumLazyGenericEnvironmentsLoaded 2,376 2,376 0 0.0%
Sema.NumLazyIterableDeclContexts 45,286 45,286 0 0.0%
Sema.NumTypesDeserialized 110,410 110,410 0 0.0%
Sema.NumTypesValidated 14,185 14,185 0 0.0%

Release

release brief

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 221,897,876,636 222,007,089,924 109,213,288 0.05%
LLVM.NumLLVMBytesOutput 10,569,844 10,569,844 0 0.0%
time.swift-driver.wall 41.2s 41.2s -3.4ms -0.01%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 1,383 1,383 0 0.0%
AST.NumLoadedModules 100 100 0 0.0%
AST.NumTotalClangImportedEntities 4,761 4,761 0 0.0%
AST.NumUsedConformances 1,348 1,348 0 0.0%
IRModule.NumIRBasicBlocks 35,129 35,129 0 0.0%
IRModule.NumIRFunctions 15,060 15,060 0 0.0%
IRModule.NumIRGlobals 13,858 13,858 0 0.0%
IRModule.NumIRInsts 336,377 336,377 0 0.0%
IRModule.NumIRValueSymbols 27,854 27,854 0 0.0%
LLVM.NumLLVMBytesOutput 10,569,844 10,569,844 0 0.0%
SILModule.NumSILGenFunctions 6,078 6,078 0 0.0%
SILModule.NumSILOptFunctions 8,944 8,944 0 0.0%
Sema.NumConformancesDeserialized 14,791 14,791 0 0.0%
Sema.NumConstraintScopes 69,488 69,488 0 0.0%
Sema.NumDeclsDeserialized 51,999 51,999 0 0.0%
Sema.NumDeclsValidated 10,362 10,362 0 0.0%
Sema.NumFunctionsTypechecked 4,360 4,360 0 0.0%
Sema.NumGenericSignatureBuilders 2,076 2,076 0 0.0%
Sema.NumLazyGenericEnvironments 11,754 11,754 0 0.0%
Sema.NumLazyGenericEnvironmentsLoaded 201 201 0 0.0%
Sema.NumLazyIterableDeclContexts 5,965 5,965 0 0.0%
Sema.NumTypesDeserialized 28,354 28,354 0 0.0%
Sema.NumTypesValidated 7,103 7,103 0 0.0%

@davidungar
Copy link
Contributor

davidungar commented Sep 29, 2018 via email

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jrose-apple jrose-apple merged commit 36ca10f into swiftlang:master Sep 29, 2018
@jrose-apple jrose-apple deleted the your-code-is-programmed-not-to-love-me-but-you-cant-pretend branch September 29, 2018 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants