-
-
Notifications
You must be signed in to change notification settings - Fork 82
Advanced analysis docs with perfetto #635
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
fsimonis
wants to merge
4
commits into
master
Choose a base branch
from
add-perfetto-doc
base: master
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 2 commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -350,3 +350,105 @@ import pandas | |
| df = pandas.read_csv("profiling.csv") | ||
| selection = df[ (df["participant"] == "A") & (df["rank"] == 0) ] | ||
| ``` | ||
|
|
||
| ## Advanced analysis with perfetto | ||
|
|
||
| So far, we used [perfetto](https://perfetto.dev) for visualizing the traces. | ||
| Sometimes, theses traces are either too large to inspect visually or one needs to extract more detailed data from the tarces than simple event-wise duration sums. | ||
|
|
||
| The perfetto project additionally provides a complete ecosystem of tools for trace processing. | ||
| [PerfettoSQL](https://perfetto.dev/docs/analysis/perfetto-sql-getting-started) and the [trace processor](https://perfetto.dev/docs/analysis/trace-processor-python) allow to systematically extract data from large profiling records. | ||
|
|
||
| ### PerfettoSQL for preCICE | ||
|
|
||
| Important mappings between the two systems are: | ||
|
|
||
| * a preCICE **participant** corresponds to a **process** in perfetto | ||
| * a preCICE **rank** corresponds to a **thread** in perfetto, nested under the process of the participant | ||
| * one preCICE **Event** corresponds to a row in the **slice** table of perfetto | ||
|
|
||
| The most important STL component is the `thread_slice` in the [`slices.with_context`](https://perfetto.dev/docs/analysis/stdlib-docs#slices-with_context) module. | ||
| It adds the thread and process name to each slice, which allows filtering for participant and rank. | ||
|
|
||
| ```sql | ||
| INCLUDE PERFETTO MODULE slices.with_context; | ||
|
|
||
| select * | ||
| from thread_slice | ||
| where process_name = 'B'; | ||
| ``` | ||
|
|
||
| The rank is a string the format `Rank {rank}`. | ||
| The following extracts all slices of the primary rank 0. | ||
|
|
||
| ```sql | ||
| select * | ||
| from thread_slice | ||
| where process_name = 'B' and thread_name = "Rank 0" | ||
| ``` | ||
|
|
||
| ### Prototyping queries in the UI | ||
|
|
||
| After importing a trace into [perfetto UI](ui.perfetto.dev), clicking the SQL tab on the left opens a text input. | ||
| Here, you can run SQL queries, see and download the results. | ||
| This is great for prototyping queries quickly directly in the browser. | ||
|
|
||
| If the output of the query is something that resembles a slice, then you can load it directly into the timeline view. | ||
| Recently executed query results can be seen in the bottom of the timeline. | ||
| Here you can also click "Show debug track" which will load all slices into a single track. | ||
| To group into multiple tracks based on a column such as `thread_name`, select it as `pivot`. | ||
| Then click "add track" to show the result of the query. | ||
|
|
||
| If you don't need to see the other tracks, it may be a good idea to change to a new blank workspace first. | ||
|
|
||
| ### Scripting the processing | ||
|
|
||
| For the scripting, I recommend using the [trace processor](https://perfetto.dev/docs/analysis/trace-processor-python) included in the python package `perfetto`. | ||
fsimonis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| pip install perfetto | ||
| ``` | ||
|
|
||
| In your script: | ||
|
|
||
| ```py | ||
| from perfetto.trace_processor import TraceProcessor | ||
|
|
||
| tp = TraceProcessor("profiling.pftrace") | ||
|
Member
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. A step is missing here: how to get the
Member
Author
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. FYI You can also use the "trace.json". |
||
| ``` | ||
|
|
||
| After that, you can run queries using `tp.query()`: | ||
|
|
||
| ```py | ||
| tp.query("SELECT count(*) from slice") | ||
| ``` | ||
|
|
||
| The result of a query can be: | ||
|
|
||
| * accessed as a `numpy.ndarray` using `tq.query(...).cells` | ||
| * iterated over using `for row in tq.query(...):` | ||
| * or exported to a `pandas.Dataframe` using `tq.query(...).as_pandas_dataframe()` | ||
|
|
||
| You can also use queries to create [views](https://sqlite.org/lang_createview.html) or [tables](https://sqlite.org/lang_createtable.html) to make the processing a bit more convenient. | ||
| If you create tables make sure to use `CREATE PERFETTO TABLE` to get a table tuned for analytics queries. | ||
|
|
||
| ### Helper | ||
|
|
||
| The following table gives for every slice, the total time spend in `.sync` events in case synchronization is enabled in the configuration. | ||
|
|
||
| ```sql | ||
| CREATE PERFETTO TABLE synctime AS | ||
| SELECT a.id AS sid, sum(dur) AS synctime | ||
fsimonis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FROM slice AS s | ||
| JOIN ancestor_slice(s.id) a | ||
| WHERE s.name GLOB '*.sync' | ||
| GROUP BY a.id; | ||
| ``` | ||
|
|
||
| The following is a view that uses preCICE terminology and allows to work with `participant` and numberic `ranks`: | ||
|
|
||
| ```sql | ||
| CREATE VIEW precice AS | ||
| SELECT process_name as participant, cast_int!(SUBSTR(thread_name, 6)) AS rank, * | ||
| FROM thread_slice; | ||
| ``` | ||
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.