-
Notifications
You must be signed in to change notification settings - Fork 935
Exposing raw heap stats for threads. #995
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
base: dev
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
I support this idea, I would love to see it merged. Some notes as I tried to add this to my own codebase:
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
const mi_stats_t* mi_global_stats(void) mi_attr_noexcept {
mi_stats_merge();
return &_mi_subproc()->stats;
} |
@SasLuca I have fixes for the globals in a local branch that I need to add to this. I initially didn't realize those metrics are collected separately from the other thread local metrics. Will try to push those today or tomorrow. |
Here are the patches (includes globals) I'm using for the 3.0.1 release. I just need them ported to the latest dev branch edition of code. |
Hi @jm4games -- thank you for the work you put into these patches. However, I recently worked on providing this and there is an initial API now that is in |
@daanx That is no problem, as long as we expose the stats I am happy. I do see some potential things the current checked in code does not cover. The goal of my provided patch was to expose metrics at runtime so that they can be sampled/monitored during the applications lifetime. With the current implementation we will only be able to see the separate thread level stats on application exit as the stats from typedef struct mi_os_stats_s {
mi_stat_count_t reserved;
mi_stat_count_t committed;
mi_stat_count_t reset;
mi_stat_count_t purged;
mi_stat_counter_t mmap_calls;
mi_stat_counter_t commit_calls;
mi_stat_counter_t reset_calls;
mi_stat_counter_t purge_calls;
} mi_os_stats_t;
mi_os_stats_t mi_os_stats(void) mi_attr_noexcept {
mi_os_stats_t stats;
memset(&stats, 0, sizeof(mi_os_stats_t));
mi_subproc_t* subproc = _mi_subproc();
mi_stat_atomic_copy(&stats.reserved, &subproc->stats.reserved);
mi_stat_atomic_copy(&stats.committed, &subproc->stats.committed);
mi_stat_atomic_copy(&stats.reset, &subproc->stats.reset);
mi_stat_atomic_copy(&stats.purged, &subproc->stats.purged);
mi_stat_counter_atomic_copy(&stats.mmap_calls, &subproc->stats.mmap_calls);
mi_stat_counter_atomic_copy(&stats.commit_calls, &subproc->stats.commit_calls);
mi_stat_counter_atomic_copy(&stats.reset_calls, &subproc->stats.reset_calls);
mi_stat_counter_atomic_copy(&stats.purge_calls, &subproc->stats.purge_calls);
return stats;
} I'd be happy to rework my current work to address the above if desired. |
Updated with latest from dev branch |
b82606f
to
495f2c7
Compare
@daanx I have updated my PR with my previously described changes. |
…s memory subsystem stats.
Hi @jm4games -- you are so fast :-) Thanks for the updates.
The latest releases now call Also note we cannot directly return statistics (as The |
That all sounds reasonable, the mi_stats_merge is the new piece I was missing. If the stats are a little behind that is totally fine, cause I was also trying to minimize the performance impact of the stats. When I get some time I will do some sanity checking to make sure this is doing what I think its doing and should be able to close this PR. Thanks for getting all this done @dannx! |
Thanks! Let me know how it goes. The |
An implementation of exposing the thread local statistics for heaps.
Not sure if project maintainers are open to this, but thought I give it a go. Also not 100% the stats I am returning are the best stats to return. Basically I want to open a pr to start a discussion around this.
This could help address issue 558