You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So far, we used [perfetto](https://perfetto.dev) for visualizing the traces.
357
+
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.
358
+
359
+
The perfetto project additionally provides a complete ecosystem of tools for trace processing.
360
+
[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.
361
+
362
+
### PerfettoSQL for preCICE
363
+
364
+
Important mappings between the two systems are:
365
+
366
+
* a preCICE **participant** corresponds to a **process** in perfetto
367
+
* a preCICE **rank** corresponds to a **thread** in perfetto, nested under the process of the participant
368
+
* one preCICE **Event** corresponds to a row in the **slice** table of perfetto
369
+
370
+
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.
371
+
It adds the thread and process name to each slice, which allows filtering for participant and rank.
372
+
373
+
```sql
374
+
INCLUDE PERFETTO MODULE slices.with_context;
375
+
376
+
select*
377
+
from thread_slice
378
+
where process_name ='B';
379
+
```
380
+
381
+
The rank is a string the format `Rank {rank}`.
382
+
The following extracts all slices of the primary rank 0.
383
+
384
+
```sql
385
+
select*
386
+
from thread_slice
387
+
where process_name ='B'and thread_name ="Rank 0"
388
+
```
389
+
390
+
### Prototyping queries in the UI
391
+
392
+
After importing a trace into [perfetto UI](ui.perfetto.dev), clicking the SQL tab on the left opens a text input.
393
+
Here, you can run SQL queries, see and download the results.
394
+
This is great for prototyping queries quickly directly in the browser.
395
+
396
+
If the output of the query is something that resembles a slice, then you can load it directly into the timeline view.
397
+
Recently executed query results can be seen in the bottom of the timeline.
398
+
Here you can also click "Show debug track" which will load all slices into a single track.
399
+
To group into multiple tracks based on a column such as `thread_name`, select it as `pivot`.
400
+
Then click "add track" to show the result of the query.
401
+
402
+
If you don't need to see the other tracks, it may be a good idea to change to a new blank workspace first.
403
+
404
+
### Scripting the processing
405
+
406
+
For the scripting, I recommend using the [trace processor](https://perfetto.dev/docs/analysis/trace-processor-python) included in the python package `perfetto`.
407
+
408
+
```bash
409
+
pip install perfetto
410
+
```
411
+
412
+
In your script:
413
+
414
+
```py
415
+
from perfetto.trace_processor import TraceProcessor
416
+
417
+
tp = TraceProcessor("profiling.pftrace")
418
+
```
419
+
420
+
After that, you can run queries using `tp.query()`:
421
+
422
+
```py
423
+
tp.query("SELECT count(*) from slice")
424
+
```
425
+
426
+
The result of a query can be:
427
+
428
+
* accessed as a `numpy.ndarray` using `tq.query(...).cells`
429
+
* iterated over using `for row in tq.query(...):`
430
+
* or exported to a `pandas.Dataframe` using `tq.query(...).as_pandas_dataframe()`
431
+
432
+
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.
433
+
If you create tables make sure to use `CREATE PERFETTO TABLE` to get a table tuned for analytics queries.
434
+
435
+
### Helper
436
+
437
+
The following table gives for every slice, the total time spend in `.sync` events in case synchronization is enabled in the configuration.
0 commit comments