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

feat(gnovm/std): Add Alloc Usage features to std #2211

Closed

Conversation

thinhnx-var
Copy link
Contributor

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

As mentioned in #2070, because it's possible to pull various things from MachineState, this PR will:

  1. Expose functions to get Allocator Status from the contracts.
  2. Contract developers can create an AllocTracker to monitor memory allocation. This tracker utilizes the Allocator.Status() function and leverages the Register() and Finish() functions defined within the AllocTracker interface. Additionally, I've exposed a GetResult() function that internally calls Finish() and returns the resulting Allocated Usage information.

Simple contract example:

func DemoGetUsage() int64 {
	a := std.CreateATInstance()
	des := "test description"
	a.Register(des)

	// --- Do some stuffs ---

	a.Finish()
	return a.GetAllocUsage()
}

func DemoGetUsage2() int64 {
	a := std.CreateATInstance()
	des := "test description"
	a.Register(des)

	// --- Do some stuffs ---

	return a.GetResult()
}

I will update examples for this later if this PR is good enough to go.

I propose moving both std.GasUsed() (introduced in issue #1998 and implemented in pull request #2148) and this new function, std.AllocatedMem(), to the runtime package. This would facilitate the development of PProf-like profiling tools within Gno. I'll provide a more detailed proposal soon with the specific implementation details.

@thinhnx-var thinhnx-var requested a review from thehowl as a code owner May 27, 2024 08:35
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label May 27, 2024
@thinhnx-var thinhnx-var changed the title Feat(gnovm/std): Add Alloc Usage features to std feat(gnovm/std): Add Alloc Usage features to std May 27, 2024
@thinhnx-var
Copy link
Contributor Author

@thehowl
I'd appreciate your feedback on this pull request at your earliest convenience.

@moul
Copy link
Member

moul commented May 27, 2024

I would recommend:

  • Not adding the new helpers and instead focusing on adding ways to measure performance without requiring userland solutions, such as using gno test -cover, gno test -profile, or a debugger.
  • Alternatively, adding the new helpers but only for unit tests, such as std.TestXXX....

The advantages of exposing these helpers for non-test runtime are not immediately clear.

@thinhnx-var
Copy link
Contributor Author

thinhnx-var commented May 28, 2024

@moul
I am thinking about gno test -profile. I will push a proposal for discussing about the output more to make it clearer.

@thinhnx-var
Copy link
Contributor Author

related proposal here #2222

@thinhnx-var
Copy link
Contributor Author

Closed due to adding -print-runtime-metrics flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants