Skip to content
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

LLVM xray profiling #36

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

LLVM xray profiling #36

wants to merge 3 commits into from

Conversation

raphdev
Copy link

@raphdev raphdev commented Mar 13, 2023

This PR adds required flags to compile debug builds with LLVM Xray to allow profiling, controlled similarly to sanitizers in #35. With xray instrumentation, we can capture traces and use the llvm-xray tool to convert the output to different formats. See Agoric/agoric-sdk#7068 for context.

To use (from agoric-sdk):

cd packages/xsnap
SANITIZER=xray yarn build
# enable instrumentation via env var
XRAY_OPTIONS="xray_mode=xray-basic prepatch_main=true verbosity=1" yarn test

Each run of xsnap will print its PID and output:

==51498==XRay: Log file in 'xray-log.xsnap-worker.zUy3ve'

We can parse xray-log.xsnap-worker.zUy3ve with llvm-xray:

llvm-xray account xray-log.xsnap-worker.zUy3ve --instr_map ./xsnap-native/xsnap/build/bin/lin/debug/xsnap-worker --top=3 --sort=sum --sortorder=dsc
Functions with latencies: 218
   funcid      count [      min,       med,       90p,       99p,       max]       sum  function    
     1434          2 [ 3.126452,  3.129465,  3.129465,  3.129465,  3.129465]  6.255916  xsRun.c:0:0: fxRunID
       97          1 [ 3.129466,  3.129466,  3.129466,  3.129466,  3.129466]  3.129466  xsAPI.c:0:0: fxRunCount
      946          1 [ 3.129462,  3.129462,  3.129462,  3.129462,  3.129462]  3.129462  xsGlobal.c:0:0: fx_eval
llvm-xray stack xray-log.xsnap-worker.zUy3ve --instr_map ./xsnap-native/xsnap/build/bin/lin/debug/xsnap-worker --aggregate-threads 

Unique Stacks: 280
Top 10 Stacks by leaf sum:

Sum: 1696600127
lvl   function                                                            count              sum
#0    main                                                                    0                0
#1    fxRunCount                                                              1       3129466209
#2    fxRunID                                                                 1       3129464668
#3    fx_eval                                                                 1       3129461960
#4    fxRunScript                                                             1       3126494793
#5    fxRunID                                                                 1       3126451793
#6    fxOrdinarySetProperty                                               58649       1696600127

Sum: 1553126385
lvl   function                                                            count              sum
#0    main                                                                    0                0
#1    fxRunCount                                                              1       3129466209
#2    fxRunID                                                                 1       3129464668
#3    fx_eval                                                                 1       3129461960
#4    fxRunScript                                                             1       3126494793
#5    fxRunID                                                                 1       3126451793
#6    fxRunIn                                                             62350       2306815599
#7    fxHasAt                                                             58246       2011622143
#8    fxHasAll                                                            56539       1735811985
#9    fxOrdinaryHasProperty                                               55809       1639403023
#10   fxOrdinaryGetProperty                                               55809       1553126385

We can also output formats compatible with various tools, like Chrome Event Viewer/Perfetto (chrome://tracing) to visualize as flame graphs:

llvm-xray convert xray-log.xsnap-worker.zUy3ve --instr_map ./xsnap-native/xsnap/build/bin/lin/debug/xsnap-worker --symbolize --output-format=trace_event | gzip > xsnap-test-trace.json.gz

image

@raphdev raphdev marked this pull request as draft March 15, 2023 17:10
@raphdev
Copy link
Author

raphdev commented Mar 15, 2023

Reverted back to draft. I'm working on an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant