-
Notifications
You must be signed in to change notification settings - Fork 62
Profiler #195
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
swatanabe-b1
wants to merge
19
commits into
develop
Choose a base branch
from
profiler
base: develop
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
Profiler #195
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4c9122b
Initial attempt at a sampling profiler
swatanabe-b1 bd8ca56
Add parsing of the "name" custom section
swatanabe-b1 df83d4e
Some fixes
swatanabe-b1 9318af2
Add addr2line
swatanabe-b1 78767ef
Show offsets from the start of the wasm instead of from the start of …
swatanabe-b1 a7beb29
Fix uninitialized variable and missing header
swatanabe-b1 34b860b
Fix some backtrace weirdnesses
swatanabe-b1 5b56898
Avoid relying on the ABI of code outside our control for backtrace. …
swatanabe-b1 cc19403
Make the extra code required to get backtraces optional.
swatanabe-b1 fc8ec35
Pass the correct execution_context to the machine_code_writer
swatanabe-b1 49dbb89
Fix posix timer implementation + minor cleanup.
swatanabe-b1 4a86959
Make the profile interval configurable
swatanabe-b1 53e1b23
Update instruction sizes
swatanabe-b1 7653009
Make sure that the backtrace range is correctly managed around host-f…
swatanabe-b1 7d393f4
Fix one more backtrace weirdness.
swatanabe-b1 2a5e7e4
Remove nm. It isn't fully implemented and isn't needed.
swatanabe-b1 9876bc2
Don't kill the compiler
swatanabe-b1 8583b0d
Add missing thread_local
swatanabe-b1 530e758
Feedback
swatanabe-b1 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,102 @@ | ||
| #pragma once | ||
|
|
||
| #include <utility> | ||
| #include <vector> | ||
| #include <cstdint> | ||
| #include <cstddef> | ||
| #include <algorithm> | ||
|
|
||
| namespace eosio::vm { | ||
|
|
||
| struct null_debug_info { | ||
| using builder = null_debug_info; | ||
| void on_code_start(const void* compiled_base, const void* wasm_code_start) {} | ||
| void on_function_start(const void* code_addr, const void* wasm_addr) {} | ||
| void on_instr_start(const void* code_addr, const void* wasm_addr) {} | ||
| void on_code_end(const void* code_addr, const void* wasm_addr) {} | ||
| void set(const null_debug_info&) {} | ||
| void relocate(const void*) {} | ||
| }; | ||
|
|
||
| // Maps a contiguous region of code to offsets onto the code section of the original wasm. | ||
| class profile_instr_map { | ||
| struct addr_entry { | ||
| uint32_t offset; | ||
| uint32_t wasm_addr; | ||
| }; | ||
|
|
||
| public: | ||
|
|
||
| struct builder { | ||
| void on_code_start(const void* compiled_base, const void* wasm_code_start) { | ||
| code_base = compiled_base; | ||
| wasm_base = wasm_code_start; | ||
| } | ||
| void on_function_start(const void* code_addr, const void* wasm_addr) { | ||
| data.push_back({ | ||
| static_cast<std::uint32_t>(reinterpret_cast<const char*>(code_addr) - reinterpret_cast<const char*>(code_base)), | ||
| static_cast<std::uint32_t>(reinterpret_cast<const char*>(wasm_addr) - reinterpret_cast<const char*>(wasm_base)) | ||
| }); | ||
| } | ||
| void on_instr_start(const void* code_addr, const void* wasm_addr) { | ||
| data.push_back({ | ||
| static_cast<std::uint32_t>(reinterpret_cast<const char*>(code_addr) - reinterpret_cast<const char*>(code_base)), | ||
| static_cast<std::uint32_t>(reinterpret_cast<const char*>(wasm_addr) - reinterpret_cast<const char*>(wasm_base)) | ||
| }); | ||
| } | ||
| void on_code_end(const void* code_addr, const void* wasm_addr) { | ||
| code_end = code_addr; | ||
| } | ||
|
|
||
| const void* code_base = nullptr; | ||
| const void* wasm_base = nullptr; | ||
| const void* code_end = nullptr; | ||
| std::vector<addr_entry> data; | ||
| }; | ||
|
|
||
| void set(builder&& b) { | ||
| data = std::move(b.data); | ||
| std::sort(data.begin(), data.end(), [](const addr_entry& lhs, const addr_entry& rhs){ return lhs.offset < rhs.offset; }); | ||
| base_address = b.code_base; | ||
| code_size = reinterpret_cast<const char*>(b.code_end) - reinterpret_cast<const char*>(base_address); | ||
| offset_to_addr = data.data(); | ||
| offset_to_addr_len = data.size(); | ||
| } | ||
|
|
||
| profile_instr_map() = default; | ||
| profile_instr_map(const profile_instr_map&) = delete; | ||
| profile_instr_map& operator=(const profile_instr_map&) = delete; | ||
|
|
||
| // Indicate that the executable code was moved/copied/mmapped/etc to another location | ||
| void relocate(const void* new_base) { base_address = new_base; } | ||
|
|
||
| // Cannot use most of the standard library as the STL is not async-signal-safe | ||
| std::uint32_t translate(const void* pc) const { | ||
| std::size_t diff = (reinterpret_cast<const char*>(pc) - reinterpret_cast<const char*>(base_address)); // negative values wrap | ||
| if(diff >= code_size || diff < offset_to_addr[0].offset) return 0xFFFFFFFFu; | ||
| std::uint32_t offset = diff; | ||
|
|
||
| // Loop invariant: offset_to_addr[lower].offset <= offset < offset_to_addr[upper].offset | ||
| std::size_t lower = 0, upper = offset_to_addr_len; | ||
| while(upper - lower > 1) { | ||
| std::size_t mid = lower + (upper - lower) / 2; | ||
| if(offset_to_addr[mid].offset <= offset) { | ||
| lower = mid; | ||
| } else { | ||
| upper = mid; | ||
| } | ||
| } | ||
|
|
||
| return offset_to_addr[lower].wasm_addr; | ||
| } | ||
| private: | ||
| const void* base_address = nullptr; | ||
| std::size_t code_size = 0; | ||
|
|
||
| addr_entry* offset_to_addr = nullptr; | ||
| std::size_t offset_to_addr_len = 0; | ||
|
|
||
| std::vector<addr_entry> data; | ||
| }; | ||
|
|
||
| } | ||
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
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.