-
Notifications
You must be signed in to change notification settings - Fork 46
Tests: Fix high memory usage on dumping profile log #6875
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
Open
proller
wants to merge
2
commits into
main
Choose a base branch
from
users/proller/profile_log_dump_memory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
161 changes: 161 additions & 0 deletions
161
cloud/filestore/tools/testing/profile_log/ut/common_ut.py
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,161 @@ | ||
| from unittest import mock | ||
|
|
||
| import cloud.filestore.tools.testing.profile_log.common as profile_log | ||
|
|
||
|
|
||
| def _event_line(request_type, *body_parts): | ||
| return "\t".join([ | ||
| "1970-01-01T00:00:00.000010Z", | ||
| "nfs_test", | ||
| request_type, | ||
| "0.000020s", | ||
| "S_OK", | ||
| *body_parts, | ||
| ]) + "\n" | ||
|
|
||
|
|
||
| class _ExecutionResult: | ||
| @property | ||
| def stdout(self): | ||
| raise AssertionError("dumpevents stdout must not be materialized") | ||
|
|
||
|
|
||
| def _execute_writer(dump): | ||
| streams = [] | ||
|
|
||
| def execute(command, **kwargs): | ||
| output = kwargs.get("stdout") | ||
| assert output is not None | ||
|
|
||
| # Writing bytes verifies that the caller supplied a binary file rather | ||
| # than asking common.execute to capture stdout in memory. | ||
| output.write(dump.encode("utf-8")) | ||
| output.flush() | ||
| streams.append(output) | ||
| return _ExecutionResult() | ||
|
|
||
| return execute, streams | ||
|
|
||
|
|
||
| def test_iter_profile_log_events_uses_caller_owned_binary_stdout(): | ||
| dump = _event_line( | ||
| "ReadData", | ||
| "{node_id=42, handle=3}", | ||
| "[{offset=4096, bytes=8192}]", | ||
| "loop_thread_id=17", | ||
| "client_id=test-client", | ||
| ) | ||
| execute, streams = _execute_writer(dump) | ||
|
|
||
| with mock.patch.object( | ||
| profile_log.common, | ||
| "execute", | ||
| side_effect=execute, | ||
| ) as execute_mock: | ||
| events = list(profile_log.iter_profile_log_events( | ||
| "/test/filestore-profile-tool", | ||
| "/test/profile.log", | ||
| "nfs_test", | ||
| )) | ||
|
|
||
| assert events == [( | ||
| "ReadData", | ||
| { | ||
| "node_id": "42", | ||
| "handle": "3", | ||
| "offset": "4096", | ||
| "bytes": "8192", | ||
| "loop_thread_id": "17", | ||
| "client_id": "test-client", | ||
| }, | ||
| )] | ||
| execute_mock.assert_called_once() | ||
| assert execute_mock.call_args.args[0] == [ | ||
| "/test/filestore-profile-tool", | ||
| "dumpevents", | ||
| "--profile-log", | ||
| "/test/profile.log", | ||
| "--fs-id", | ||
| "nfs_test", | ||
| ] | ||
| assert execute_mock.call_args.kwargs["stdout"] is streams[0] | ||
| assert streams[0].closed | ||
|
|
||
|
|
||
| def test_iter_profile_log_events_parses_incrementally(): | ||
|
proller marked this conversation as resolved.
Outdated
|
||
| lines = [ | ||
| _event_line("ReadData", "loop_thread_id=1"), | ||
| _event_line("WriteData", "loop_thread_id=2"), | ||
| ] | ||
| consumed = [] | ||
|
|
||
| def iter_lines(*_args, **_kwargs): | ||
| for line in lines: | ||
| consumed.append(line) | ||
| yield line | ||
|
|
||
| with mock.patch.object( | ||
| profile_log, | ||
| "_iter_profile_log_lines", | ||
| side_effect=iter_lines, | ||
| ): | ||
| events = profile_log.iter_profile_log_events( | ||
| "/test/filestore-profile-tool", | ||
| "/test/profile.log", | ||
| "nfs_test", | ||
| ) | ||
|
|
||
| assert iter(events) is events | ||
| assert consumed == [] | ||
| assert next(events) == ("ReadData", {"loop_thread_id": "1"}) | ||
| assert consumed == [lines[0]] | ||
| assert list(events) == [("WriteData", {"loop_thread_id": "2"})] | ||
|
|
||
|
|
||
| def test_get_profile_log_events_remains_a_list_wrapper(): | ||
|
proller marked this conversation as resolved.
Outdated
|
||
| expected = [ | ||
| ("ReadData", {"loop_thread_id": "1"}), | ||
| ("WriteData", {"loop_thread_id": "2"}), | ||
| ] | ||
|
|
||
| with mock.patch.object( | ||
| profile_log, | ||
| "iter_profile_log_events", | ||
| return_value=iter(expected), | ||
| ) as iter_events: | ||
| events = profile_log.get_profile_log_events( | ||
| "/test/filestore-profile-tool", | ||
| "/test/profile.log", | ||
| "nfs_test", | ||
| ) | ||
|
|
||
| assert isinstance(events, list) | ||
| assert events == expected | ||
| iter_events.assert_called_once_with( | ||
| "/test/filestore-profile-tool", | ||
| "/test/profile.log", | ||
| "nfs_test", | ||
| ) | ||
|
|
||
|
|
||
| def test_analyze_profile_log_filters_by_node_name(): | ||
|
proller marked this conversation as resolved.
|
||
| dump = "".join([ | ||
| _event_line("ReadData", "{node_name=selected, node_id=1}"), | ||
| _event_line("WriteData", "{node_name=other, node_id=2}"), | ||
| _event_line("ReadData", "{node_name=selected, node_id=3}"), | ||
| ]) | ||
| execute, _ = _execute_writer(dump) | ||
|
|
||
| with mock.patch.object( | ||
| profile_log.common, | ||
| "execute", | ||
| side_effect=execute, | ||
| ): | ||
| counts = profile_log.analyze_profile_log( | ||
| "/test/filestore-profile-tool", | ||
| "/test/profile.log", | ||
| "nfs_test", | ||
| node_name_filter="selected", | ||
| ) | ||
|
|
||
| assert counts == {"ReadData": 2} | ||
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,11 @@ | ||
| PY3TEST() | ||
|
|
||
| TEST_SRCS( | ||
| common_ut.py | ||
| ) | ||
|
|
||
| PEERDIR( | ||
| cloud/filestore/tools/testing/profile_log | ||
| ) | ||
|
|
||
| END() |
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 |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ PY_SRCS( | |
| ) | ||
|
|
||
| END() | ||
|
|
||
| RECURSE_FOR_TESTS(ut) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.