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

Support unshared vars #135

Open
ejrgilbert opened this issue Aug 21, 2024 · 1 comment · Fixed by #168 · May be fixed by #176
Open

Support unshared vars #135

ejrgilbert opened this issue Aug 21, 2024 · 1 comment · Fixed by #168 · May be fixed by #176
Labels
enhancement New feature or request

Comments

@ejrgilbert
Copy link
Owner

ejrgilbert commented Aug 21, 2024

Justification

There can be cases where you want a variable that is replicated for every matched event, but is not initialized every time the probe body is executed. This requires that you have global state that is only reference-able locally for a probe body.

Enter the unshared variable.

Use Case

Consider the following use case for this variable:

wasm:opcode:memory_grow {
    unshared int count;
    if count <= 0 {
        ...
        count = rand() % 1000; // some random number between 0 and 1000
    }
    count--;
}

This effectively samples the execution of each memory_grow operation using random sampling. Continuing on this idea, you could use a global count to sample memory.grow at a random interval for the entire application, e.g.:

int count;
wasm:opcode:memory_grow {
    if count <= 0 {
        ...
        count = rand() % 1000; // some random number between 0 and 1000
    }
    count--;
}

Implementation Details

Basically implement a report variable that is not reported at the end of program execution.

Make It Fast (Wizard)

  1. The JIT could put the if count <= 0 check inline (~3 opcodes) and then call out to the probe body callback if the predicate is true
  2. See Issue Really cool wizard integration features #137, the sampling logic is just a check on global state, factor this out to a dynamic check matches function.
@ejrgilbert ejrgilbert added the enhancement New feature or request label Oct 8, 2024
@ejrgilbert
Copy link
Owner Author

New name idea: stable?

@ejrgilbert ejrgilbert reopened this Nov 5, 2024
@ejrgilbert ejrgilbert changed the title Support local vars Support unshared vars Nov 6, 2024
@ejrgilbert ejrgilbert linked a pull request Nov 21, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant