-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[coverage] Automatic merger for LLVM profile data #1126
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
eb27ca1
[coverage] Initial commit of profdata merging worker
2cf852f
[coverage] Cleaned up profdata merge worker and added debug flag
c6c0b3d
[coverage] Removed explicit swift-%p.profraw arguments from CMake com…
32fda29
[coverage] Made subclass of list test format so we can hook into each…
a41ec1a
[coverage] Cleaned up argument parsing for swift coverage, and hooked…
78612e5
[coverage] Added before_test and after_test hooks in SwiftTest
03964cc
[coverage] Simplified before_test and after_test
3ea61fb
[coverage] Fixed runtime error in lit.cfg
9eb729c
[coverage] Reworked CMake invocation for coverage testing given there…
fb6ee1a
[coverage] Added argument parsing to profdata merge worker and cleane…
259af4d
[coverage] Cleaned up target generation and lit merging code
c83fb1c
[coverage] Fixed CMake invocation of profdata merge worker
1b30a49
[coverage] Added license header to profdata_merge_worker and added ex…
5a2a809
[coverage] Removed printing in CMake
9fccf50
[coverage] Fixed conflicts with master
bb8160a
[coverage] Declared SWIFT_ANALYZE_CODE_COVERAGE in CMakeLists and doc…
b4c7678
[coverage] Documented modes for SWIFT_ANALYZE_CODE_COVERAGE and added…
e997fc3
[coverage] Changed 'none' to 'false' for coverage default
44be500
[coverage] Changed back to old coverage check in CMakeLists.txt files
7608f88
[coverage] Removed print in built script
b1d6e17
[coverage] Added coverage_mode definitions in validation test and Uni…
0e6f798
[coverage] Made sure code coverage doesn't rename the ninja build dir…
e9d009e
[coverage] Merged and fixed conflicts
44e44ad
Merged upstream master into profdata-merge
b8a2249
Merged upstream master into profdata-merge
96d4261
[coverage] Made some stylistic changes for CMake consistency
1777c20
[coverage] Fixed indentation in CMake
d41bd9a
[coverage] Made SWIFT_ANALYZE_CODE_COVERAGE a string option instead o…
f99fd75
[coverage] Converted global non-constants to explicitly passed parame…
d7eff48
[coverage] Converted to print function
693d7da
[coverage] Converted to explicit super in lit.cfg
6572267
[coverage] Split profdata_merge_worker.py into separate files within …
dea48f4
[coverage] Fixed missing import
eb9fb9c
[coverage] Used gettempdir() instead of hard-coding /tmp
45df849
[coverage] Explicit super in process.py
873af8e
[coverage] Fail gracefully on non-Darwin
f713042
[coverage] Added license header to config.py
c75fa76
[coverage] Added README for the profdata module
6ec0dd3
[coverage] Added log file output to profdata merger
cf30318
[coverage] Converted to python standard logging framework
13bae93
[coverage] pep8
2b22040
[coverage] Removed unused imports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Profdata Merge | ||
|
||
Because LLVM's instrumented builds produce a `profraw` file every time a | ||
they are executed, the Swift test suite, when run with coverage enabled, | ||
produces thousands of 30MB profile files. | ||
|
||
When build-script is run with `--swift-analyze-code-coverage merged`, this | ||
module will get called before the tests run and spin up a small server that | ||
runs alongside the test suite. The server accepts filenames that it receives | ||
after each test directory is finished executing, and feeds them to 10 worker | ||
processes which concurrently merge those files together. Doing so means the | ||
test results directory doesn't balloon in size, as the files are merged together | ||
and removed often. | ||
|
||
Once the test suite is finished, it sends a crafted message to the server that | ||
tells it to merge any files left in the queue, then merges all the workers | ||
together into one final file. |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# utils/profdata_merge/config.py | ||
# | ||
# This source file is part of the Swift.org open source project | ||
# | ||
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
# Licensed under Apache License v2.0 with Runtime Library Exception | ||
# | ||
# See http://swift.org/LICENSE.txt for license information | ||
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
|
||
# This file contains the data structure that transforms arguments into usable | ||
# values | ||
|
||
import tempfile | ||
import os | ||
|
||
|
||
class Config(): | ||
"""A class to store configuration information specified by command-line | ||
arguments.""" | ||
def __init__(self, out_dir, no_remove_files): | ||
self.out_dir = out_dir | ||
self.tmp_dir = tempfile.mkdtemp() | ||
self.pid_file_path = os.path.join(self.out_dir, | ||
"profdata_merge_worker.pid") | ||
self.final_profdata_path = os.path.join(self.out_dir, "swift.profdata") | ||
self.remove_files = not no_remove_files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
|
||
# utils/profdata_merge/main.py | ||
# | ||
# This source file is part of the Swift.org open source project | ||
# | ||
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
# Licensed under Apache License v2.0 with Runtime Library Exception | ||
# | ||
# See http://swift.org/LICENSE.txt for license information | ||
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
|
||
# This module is used to prevent profile data filling up available disk space | ||
# by listening for profile data and merging them into a universal profdata | ||
# file while tests are executing. | ||
# This file invokes the runner after parsing arguments. | ||
|
||
from __future__ import print_function | ||
import sys | ||
import argparse | ||
import tempfile | ||
import logging | ||
|
||
import runner | ||
|
||
SERVER_ADDRESS = ('localhost', 12400) | ||
TESTS_FINISHED_SENTINEL = "PROFDATA_MERGE_WORKER_TESTS_FINISHED_SENTINEL" | ||
|
||
if __name__ == "__main__": | ||
if sys.platform != "darwin": | ||
sys.exit("Error: The profile data merge worker requires OS X.") | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-l", "--log-file", | ||
help="The file to write logs in debug mode.") | ||
|
||
subparsers = parser.add_subparsers() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, I had no idea about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually found out about it in |
||
|
||
start = subparsers.add_parser("start") | ||
start.add_argument("-d", "--debug", | ||
help="Run in foreground and report status.", | ||
action="store_true") | ||
start.add_argument("-o", "--output-dir", | ||
help=("The directory to write the PID file" + | ||
"and final profdata file."), | ||
default=tempfile.gettempdir()) | ||
start.add_argument("--no-remove", | ||
action="store_true", | ||
help="Don't remove profraw files after merging them.") | ||
start.set_defaults(func=runner.start_server) | ||
|
||
stop = subparsers.add_parser("stop") | ||
stop.set_defaults(func=runner.stop_server) | ||
|
||
args = parser.parse_args() | ||
|
||
log_args = {'level': logging.DEBUG} | ||
if args.log_file: | ||
log_args['filename'] = args.log_file | ||
|
||
logging.basicConfig(**log_args) | ||
|
||
args.func(args) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It comes from
lit.site.cfg.in
-- CMake fills it in with the appropriate value, and it's used to determine the pre- and post-test behaviorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, whoops! I deleted my comment too late--I had misread 😅