This allows you to specify the memory scope amongst existing logging scopes, both in API and the CLI.
e.g for the CLI.
```bash
$ wazero run --hostlogging=memory,filesystem --mount=.:/:ro cat.wasm
```
e.g. for Go
```go
loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{},
logging.NewHostLoggingListenerFactory(&log, logging.LogScopeMemory|logging.LogScopeFilesystem))
```
This is helpful for emscripten and gojs which have memory reset
callbacks. This will be much more interesting once #1075 is implemented.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
33 lines
767 B
Go
33 lines
767 B
Go
package logging
|
|
|
|
import (
|
|
"github.com/tetratelabs/wazero/api"
|
|
. "github.com/tetratelabs/wazero/internal/assemblyscript"
|
|
"github.com/tetratelabs/wazero/internal/logging"
|
|
)
|
|
|
|
func isExitFunction(fnd api.FunctionDefinition) bool {
|
|
return fnd.ExportNames()[0] == AbortName
|
|
}
|
|
|
|
func isRandomFunction(fnd api.FunctionDefinition) bool {
|
|
return fnd.ExportNames()[0] == SeedName
|
|
}
|
|
|
|
// IsInLogScope returns true if the current function is in any of the scopes.
|
|
func IsInLogScope(fnd api.FunctionDefinition, scopes logging.LogScopes) bool {
|
|
if scopes.IsEnabled(logging.LogScopeExit) {
|
|
if isExitFunction(fnd) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
if scopes.IsEnabled(logging.LogScopeRandom) {
|
|
if isRandomFunction(fnd) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return scopes == logging.LogScopeAll
|
|
}
|