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

Initial commit to log functions in Wasm. #12764

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

awtcode
Copy link

@awtcode awtcode commented Nov 12, 2020

Initial code to allow the user to log functions in Wasm. He will have to set -s INSTRUMENT=1 and provide a Javascript log_function to implement the logging. FYI @sbc100 and @tlively .

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Nice and simple. Obviously would want some kind of test too, once the binaryen side lands.

I wonder if it should be called something a little more specific. INSTRUMENT_FUNCTION_CALLS? The name of the callback should probably more specific too to avoid colliding with user symbols. Perhaps it should even be configurable? -s INSTRUMENT_FUNCTION_CALLS=myfunc ?

@@ -650,6 +650,9 @@ def check_human_readable_list(items):
extras = shared.Settings.BINARYEN_EXTRA_PASSES.split(',')
passes += [('--' + p) if p[0] != '-' else p for p in extras if p]

if shared.Settings.INSTRUMENT:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this BINARYEN_EXTRA_PASSES should comes last go maybe move this up a few lines

Copy link
Author

@awtcode awtcode Nov 18, 2020

Choose a reason for hiding this comment

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

From our discussion last week, I believe the logging function will be hard-coded in Wasm so this will no longer be necessary. The instrumentation phase will also be executed from wasm-split so I think the code will be something like:

if shared.Settings.INSTRUMENT:
wasm-split instrument a.wasm ...
if shared.Settings.INSTRUMENT:
wasm-split split a.wasm ...

And the wasm-split tool should preferably be run at the end so that both instrumentation and splitting will run on the same binary?

@@ -661,6 +661,9 @@ def add_standard_wasm_imports(send_items_map):
return value;
}'''

if shared.Settings.INSTRUMENT:
send_items_map['log_function'] = '''log_function'''
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for triple quotes here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is log_function getting defined? Can we avoid needing to specify a special/dedicated mechanism to import this, but could instead use a regular JS library function for that?

I would be interested in overriding this log_function for my own debugging/tooling, and also perhaps the ones that AUTODEBUG provides, but it looks like overriding the functionality is not currently possible.

JS libraries have the convenience that if one specifies a --js-library file on the command line, it can override system JS library defined symbols, so one can override default behavior for the "I know what I'm doing" scenarios. That would be cool to support for this feature!

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

A simpler option might be to have the user do -s BINARYEN_EXTRA_PASSES=--log-function. That would use an existing setting instead of adding a new one.

That leaves getting the asmLibraryArg import added. I think we can add a new option for that in a generic way (we already have various other options in this area, just not that specifically), EXTRA_WASM_IMPORTS perhaps?

@sbc100
Copy link
Collaborator

sbc100 commented Nov 12, 2020

I'm not sure how useful EXTRA_WASM_IMPORTS in general since it would only be useful for imports that were added by wasm-opt after wasm-emscripten-finalize. Maybe there are more such cases? Actually maybe we could convert our exists uses to this new option internally? That might actually clean up the code there..

@kripken
Copy link
Member

kripken commented Nov 12, 2020

Actually maybe we could convert our exists uses to this new option internally? That might actually clean up the code there..

Yes, that's what I'm thinking. I'll start a PR.

@awtcode
Copy link
Author

awtcode commented Nov 18, 2020

@sbc100 and @kripken , I don't think the Instrumentation phase will use EXTRA_WASM_IMPORTS anymore now that we are writing the "log_function" in Wasm?

@awtcode
Copy link
Author

awtcode commented Nov 18, 2020

Nice and simple. Obviously would want some kind of test too, once the binaryen side lands.

I wonder if it should be called something a little more specific. INSTRUMENT_FUNCTION_CALLS? The name of the callback should probably more specific too to avoid colliding with user symbols. Perhaps it should even be configurable? -s INSTRUMENT_FUNCTION_CALLS=myfunc ?

We would want to instrument at the block level in the future so I guess INSTRUMENT_FUNCTION_CALLS would not reflect that. Maybe something along the lines of -s INSTRUMENT=block,func? The logging function will be hard-coded in Wasm anyway.

@kripken
Copy link
Member

kripken commented Nov 24, 2020

Given the activity in @tlively 's work, do we still need this PR?

@awtcode
Copy link
Author

awtcode commented Nov 25, 2020

Given the activity in @tlively 's work, do we still need this PR?

I was thinking we don't need the code to import a JS function anymore but we still need to provide a way for users to use the wasm-split tool through the settings? @sbc100 and @tlively , any comments?

@tlively
Copy link
Member

tlively commented Nov 25, 2020

I think we probably don't need this specific PR any more, but yes, I think we should still add Emscripten options to make wasm-split easier to use for Emscripten users and to automatically load the second module in the Emscripten runtime code. @sbc100, do you still want to do that integration work?

Base automatically changed from master to main March 8, 2021 23:49
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants