-
Notifications
You must be signed in to change notification settings - Fork 70
Add perf tests #420
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
Add perf tests #420
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FROM gcc:8 | ||
|
|
||
| COPY native.c . | ||
|
|
||
| RUN gcc -g -fomit-frame-pointer native.c -o native | ||
|
|
||
| # ensure it's built with debug info | ||
| RUN file native | grep -q "with debug_info" | ||
|
|
||
| CMD ["./native"] |
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,10 @@ | ||
| FROM gcc:8 | ||
|
|
||
| COPY native.c . | ||
|
|
||
| RUN gcc -fno-omit-frame-pointer native.c -o native | ||
|
|
||
| # ensure it's built without debug info | ||
| RUN file native | grep -zvq "with debug_info" | ||
|
|
||
| CMD ["./native"] |
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,14 @@ | ||
| // This one isn't fibonacci like the others, because it's used in tests for perf smart mode, | ||
| // which require consistent stacktraces (and fibonacci is not consistent; these stacks are) | ||
| static void recursive(unsigned int n) { | ||
| if (n > 0) { | ||
| recursive(n - 1); | ||
| } | ||
|
|
||
| while (1) ; | ||
| } | ||
|
|
||
| int main(void) { | ||
| recursive(10); | ||
| return 0; | ||
| } |
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,28 @@ | ||
| # | ||
| # Copyright (c) Granulate. All rights reserved. | ||
| # Licensed under the AGPL3 License. See LICENSE.md in the project root for license information. | ||
| # | ||
|
|
||
| """ | ||
| Tests for the logic from gprofiler/merge.py | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from gprofiler.merge import get_average_frame_count | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "samples,count", | ||
| [ | ||
| (["a 1"], 1), | ||
| (["d_[k] 1"], 0), | ||
| (["d_[k];e_[k] 1"], 0), | ||
| (["a;b;c;d_[k] 1"], 3), | ||
| (["a;b;c;d_[k];e_[k] 1"], 3), | ||
| (["a 1", "a;b 1"], 1.5), | ||
| (["d_[k] 1", "a;d_[k] 1"], 0.5), | ||
| ], | ||
| ) | ||
| def test_get_average_frame_count(samples: str, count: float) -> None: | ||
| assert get_average_frame_count(samples) == count |
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,51 @@ | ||
| # | ||
| # Copyright (c) Granulate. All rights reserved. | ||
| # Licensed under the AGPL3 License. See LICENSE.md in the project root for license information. | ||
| # | ||
|
|
||
| from pathlib import Path | ||
| from threading import Event | ||
|
|
||
| import pytest | ||
|
|
||
| from gprofiler.profilers.perf import DEFAULT_PERF_DWARF_STACK_SIZE, SystemProfiler | ||
| from tests.utils import assert_function_in_collapsed, is_function_in_collapsed, snapshot_pid_collapsed | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("runtime", ["native_fp", "native_dwarf"]) | ||
| @pytest.mark.parametrize("perf_mode", ["fp", "dwarf", "smart"]) | ||
| @pytest.mark.parametrize("in_container", [True]) # native app is built only for container | ||
| def test_perf( | ||
| tmp_path: Path, | ||
| application_pid: int, | ||
| runtime: str, | ||
| perf_mode: str, | ||
| ) -> None: | ||
| """ """ | ||
| with SystemProfiler( | ||
| 99, | ||
| 3, | ||
| Event(), | ||
| str(tmp_path), | ||
| False, | ||
| perf_mode=perf_mode, | ||
| perf_inject=False, | ||
| perf_dwarf_stack_size=DEFAULT_PERF_DWARF_STACK_SIZE, | ||
| ) as profiler: | ||
| process_collapsed = snapshot_pid_collapsed(profiler, application_pid) | ||
|
|
||
| if runtime == "native_dwarf": | ||
| # app is built with DWARF info and without FP, so we expect to see a callstack only in DWARF or smart modes. | ||
| assert is_function_in_collapsed(";recursive;recursive;recursive;recursive;", process_collapsed) ^ bool( | ||
| perf_mode not in ("dwarf", "smart") | ||
| ) | ||
| else: | ||
| # app is built with FP and without DWARF info, but DWARF mode is able to do FP unwinding, | ||
| # so it should always succeed. | ||
| assert runtime == "native_fp" | ||
| assert_function_in_collapsed(";recursive;recursive;recursive;recursive;", process_collapsed) | ||
|
|
||
| # expect to see libc stacks only when collecting with DWARF or smart. | ||
| assert is_function_in_collapsed(";_start;__libc_start_main;main;", process_collapsed) ^ bool( | ||
| perf_mode not in ("dwarf", "smart") | ||
| ) | ||
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
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.