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

Add combined monitor #2900

Merged
merged 3 commits into from
Jan 28, 2025
Merged

Conversation

Evian-Zhang
Copy link
Contributor

Related to issue #2895. Now we can create multiple monitors for one fuzzer instance.

Currently, the API of Monitor is not good enough to implement a zero-cost combined monitor, the client stats need to be synced to underline monitors in the right time (I choose to sync before each display call), which incurs some runtime overhead.

@tokatoka tokatoka merged commit f30b054 into AFLplusplus:main Jan 28, 2025
106 checks passed
@tokatoka
Copy link
Member

thank you

@domenukk
Copy link
Member

Yeah, we probably don't want to clone every time. We should probably "just" forward everything to each sub-monitor(?)

@Evian-Zhang
Copy link
Contributor Author

@domenukk Yes, but since the API of monitor could give user the mutable reference of client stat, we have no idea of when user changes the data, unless we make the underline client_stats of both sub-monitors point to the same vector, which is impossible using current Monitor API.

@Evian-Zhang
Copy link
Contributor Author

A possible solution may be returning a custom structure instead of bare mutable reference, which implements Drop trait, and notify the Monitor when it is dropped. But this is a breaking change, and if you think this is acceptable, I'm willing to write a PR when I have time:)

@domenukk
Copy link
Member

How about an abstraction that is more event-based?
Then we could even forward everything to monitors via socket or similar at some point

@Evian-Zhang
Copy link
Contributor Author

@domenukk In my understanding, a simple event-based API would look like

trait Monitor {
    fn on_stat_changed(&mut self, client_id: ClientId, stat: ClientStats);
}

Although this API is good for CombinedMonitor to work, however, since ClientStats is a relatively large structure, forwarding it around may be not a good idea for other normal monitors.

If we want to make the whole thing pure, just make it like a monad:

trait Monitor {
    fn on_stat_changed<F: Fn(&mut ClientStats)>(&mut self, client_id: ClientId, update: F);
}

This approach may be more efficient, and we can still forward everything to Monitors via socket using this API.

What's your advice?

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