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

[Plat 9771] Add wasm-opt pass to instrument functions #6

Merged
merged 8 commits into from
Jul 29, 2024

Conversation

MPurscheUnity
Copy link
Collaborator

@MPurscheUnity MPurscheUnity commented Jul 24, 2024

Purpose of this PR

This PR adds a pass to wasm-opt to add a configurable logging call to functions. This allows to profile which functions were called.
The log function will receive the id of the function(ordinal inside WASM file) and a label id. The label id is either an offset into the the global memory that allows to read a C-String or can be used to look up the label inside a external .json file.
A config file allows to define which functions should be instrumented and what label is assigned to which function.

Usage:

# Use with external config file and store labels in .json file
wasm-opt --instrument-functions="@instrument-config.txt" test.wasm --output test_instrumented.wasm

# Store labels in (data) section
wasm-opt --instrument-functions="@instrument-config.txt" test.wasm --pass-arg=instrument-functions-labels-in-data --output test_instrumented.wasm

# Configure instrumented functions and labels inline by using a ; seperated list
wasm-opt --instrument-functions="func_a;label_0;func_b;label_1;func_c;label_1" test.wasm --pass-arg=instrument-functions-labels-in-data --output test_instrumented.wasm

# Configure labels and functions .json file
wasm-opt --instrument-functions="@instrument-config.txt" test.wasm --pass-arg=instrument-functions-labels-file@labels_file.json --pass-arg=instrument-functions-map-file@function_names.json --output test_instrumented.wasm

# Configure name and import module of logging function to "wasmImports.foobar"
wasm-opt --instrument-functions="@instrument-config.txt" test.wasm --output test_instrumented.wasm --pass-arg=instrument-functions-logger-function@foobar --pass-arg=instrument-functions-logger-function-module@wasmImports

Example instrument-config.txt:

func_a;label_0
func_b;label_1
func_c;label_1

JIRA Ticket: PLAT-9771 Implement pass in binaryen that instruments an existing WASM file to profile used/unused submodules

Definition of Done

  • Binaryen has a pass that can add profiling function calls to functions
  • The function call receives function name/submodule name ( this is configurable)
  • Add a unit test in the binaryen repository

Testing

Manual testing done by running the tool as shown above.

Automated testing added to the binaryen test suite.

  • test/passes/instrument-functions=a;Submodule 1;b;Submodule 1;c;Submodule 1;d;Submodule 1;e;Submodule 1;f;Submodule 2;h;Submodule 3_pass-arg=instrument-functions-labels-in-data_enable-simd.txt
    Run binaryen tests locally with with:
# with compiled binaryen in ./bin
python 3 check.py

Test passed in CI: https://github.com/Unity-Technologies/binaryen/actions/runs/10078907940/job/27864951293?pr=6

Notes to reviewer

The failing tests can be ignored the jobs seem to be outdated.

@MPurscheUnity MPurscheUnity marked this pull request as ready for review July 25, 2024 11:02
Copy link

@irina-ishchenko irina-ishchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, Marcel! Just a minor thing, can you please add the link to PLAT-9771 (it's just easier than look for it in Jira)?

I'm not too familiar with this repository bur I think the performed testing adds enough coverage for the changes.

The only question I have is how do these changes affect the rest of the code? How confident are you that nothing else needs to be tested/sanity checked for possible regressions?

@MPurscheUnity
Copy link
Collaborator Author

Great PR, Marcel! Just a minor thing, can you please add the link to PLAT-9771 (it's just easier than look for it in Jira)?

I'm not too familiar with this repository bur I think the performed testing adds enough coverage for the changes.

The only question I have is how do these changes affect the rest of the code? How confident are you that nothing else needs to be tested/sanity checked for possible regressions?

I am pretty confident that the change does not have an effect on other parts of the code. The passes work independent from each other so if the pass is not used in the command line the code is never run. The existing test suite also runs the other passes so I am confident that my change did not break anything else.

@MPurscheUnity MPurscheUnity force-pushed the plat-9771/add-instrument-function-pass branch 2 times, most recently from 49d15fd to 2dcb034 Compare July 29, 2024 09:50
@MPurscheUnity MPurscheUnity force-pushed the plat-9771/add-instrument-function-pass branch from 2dcb034 to f5d7458 Compare July 29, 2024 09:53
Copy link

@irina-ishchenko irina-ishchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Marcel. In this case no additional testing is required.

Copy link
Collaborator

@alikamarainen alikamarainen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too familiar with the codebase but seems straightforward and solid 👍

@alikamarainen
Copy link
Collaborator

(not that it matters, but you example commands have --instrument-function but the arg is --instrument-functions)

@MPurscheUnity MPurscheUnity merged commit f73f787 into 3.1.38.2-unity Jul 29, 2024
7 of 12 checks passed
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.

3 participants