-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Enhance runtime stats tracking #4144
Conversation
I'd like to see the new ponyint_ functions exposed via the runtime_info package. And changed from being ponyint_ to being PONY_API functions. In the runtime_info, there should be an auth for memory tracking that is required. |
When you say Also, do you like the |
I was referring to the ones you added but really, any that we expose via the runtime info primitive. I think memstats is better. For the primitive, perhaps AllocatorInfo ? |
Also, if we're going to expose this stuff via |
I think off by default is the right approach with documentation on the primitive pointing to build instructions to turn on. |
okey dokey.. makes sense.. |
this needs a rebase |
7a16066
to
6fef040
Compare
rebased onto latest |
needs another rebase |
This has outstanding changes requested. During sync, Joe gave this a thumbs up. |
Also needs a rebase against main |
@dipinhora drop me a note when we should check this out again. |
@SeanTAllen yes, i'll drop a note when ready.. this took a bit of a back seat to the backpressure/systematic testing stuff (and in general i'd prefer to get those merged first anyways and then rebase/update this one accounting for all those changes).. |
argh, looks like a new comment automagically adds in the |
Runtime allocation tracking now also tracks the number of heap allocations, the number of freed heap allocations and the number of GC iterations via counters. Additionally, there is now a way to check if runtime memory allocation tracking is enabled or not via `ifdef` statements in Pony code. This allows for some useful validations for those folks concerned about heap allocations in the critical path (i.e. if they rely on the compiler's `HeapToStack` optimization pass to convert heap allocations to stack allocations and want to validate it is working correctly).
This commit enhances the runtime stats tracking that was previously implemented under the `USE_MEMTRACK` and `USED_MEMTRACK_MESSAGES` defines. The new defines are called `USE_RUNTIMESTATS` and `USE_RUNTIMESTATS_MESSAGES`. Runtime stats tracking tracks the following actor info: * heap memory allocated * heap memory used * heap num allocated * heap realloc counter * heap alloc counter * heap free counter * heap gc counter * system message processing cpu usage * app message processing cpu usage * garbage collection cpu usage * messages sent counter * system messages processed counter * app messages processed counter Runtime tracking tracks the following scheduler info: * mutemap memory used * mutemap memory allocated * memory used for gc acquire/release actormaps and actors created * memory allocated for gc acquire/release actormaps and actors created * created actors counter * destroyed actors counter * actor system message processing cpu for all actor runs on the scheduler * actor app message processing cpu for all actor runs on the scheduler * actor garbage collection cpu for all actor runs on the scheduler * scheduler message processing cpu usage * scheduler misc cpu usage while waiting to do work * memory used by inflight messages * memory allocated by inflight messages * number of inflight messages This runtime stats tracking info has been exposed to pony programs as part of the `runtime_info` package and an example `runtime_info` program has been added to the `examples` directory.
6fef040
to
12dd8cd
Compare
@SeanTAllen This is ready for review. |
static void platform_runtimestats(compile_t* c, reach_type_t* t, token_id cap) | ||
{ | ||
FIND_METHOD("runtimestats", cap); | ||
start_function(c, t, m, c->i1, &c_t->use_type, 1); | ||
|
||
#if defined(USE_RUNTIMESTATS) || defined(USE_RUNTIMESTATS_MESSAGES) | ||
bool runtimestats_enabled = true; | ||
#else | ||
bool runtimestats_enabled = false; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a comment in the sync call today that I'd eventually like to see this happen differently.
That is, the way this is written, it assumes that the USE_RUNTIMESTATS
define is synchronized on both ponyc
and libponyrt
. What this implies is that in order to compile a program with runtime stats you need to use a completely different compiler instead of just linking to a different runtime.
I'd eventually like us to get to a place where we bundle both versions of the runtime (with and without stats) such that when compiling a program you can use a flag to switch it on or off.
Doesn't need to happen in this PR - we just want to make sure we create a followup ticket to capture that intended direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Ideally all of the various use
options (
Lines 117 to 143 in a3b3bdf
$$(info Enabling use option: $1) | |
ifeq ($1,valgrind) | |
PONY_USES += -DPONY_USE_VALGRIND=true | |
else ifeq ($1,thread_sanitizer) | |
PONY_USES += -DPONY_USE_THREAD_SANITIZER=true | |
else ifeq ($1,address_sanitizer) | |
PONY_USES += -DPONY_USE_ADDRESS_SANITIZER=true | |
else ifeq ($1,undefined_behavior_sanitizer) | |
PONY_USES += -DPONY_USE_UNDEFINED_BEHAVIOR_SANITIZER=true | |
else ifeq ($1,coverage) | |
PONY_USES += -DPONY_USE_COVERAGE=true | |
else ifeq ($1,pooltrack) | |
PONY_USES += -DPONY_USE_POOLTRACK=true | |
else ifeq ($1,dtrace) | |
DTRACE ?= $(shell which dtrace) | |
ifeq (, $$(DTRACE)) | |
$$(error No dtrace compatible user application static probe generation tool found) | |
endif | |
PONY_USES += -DPONY_USE_DTRACE=true | |
else ifeq ($1,scheduler_scaling_pthreads) | |
PONY_USES += -DPONY_USE_SCHEDULER_SCALING_PTHREADS=true | |
else ifeq ($1,systematic_testing) | |
PONY_USES += -DPONY_USE_SYSTEMATIC_TESTING=true | |
else ifeq ($1,memtrack) | |
PONY_USES += -DPONY_USE_MEMTRACK=true | |
else ifeq ($1,memtrack_messages) | |
PONY_USES += -DPONY_USE_MEMTRACK_MESSAGES=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not easy to imagine at this time how we'd get all of those to be individually tweakable at Pony-program-compile-time unless we change how things work significantly in order to compile the runtime alongside the Pony program.
What I was thinking of in my previous comment would be to ship two versions of the runtime - one with extra stats enabled, and one without. We couldn't use that kind of approach with individually tweakable options unless we shipped an exponential number of runtimes with the Pony compiler releases.
A lot of those USE_*
defines are more geared toward troubleshooting of the runtime by runtime developers (valgrind, sanitizers, etc), whereas I think a few of them (runtime stats, memtrack, pooltrack, dtrace) could be more helpful to application developers to instrument their application.
So I'm thinking it may be worthwhile to just lump a group of them together as a "with stats" version of the runtime and ship that. Then if some people really end up needing more granularity than that, they can custom build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach I've thought about in the past for this is seeing if it's possible to refactor these things such that they can be tweaked in the runtime bitcode individually, by rewriting certain instructions in the LLVM IR for the runtime bitcode, based on ponyc invocation flags. I did some brief work on this, but it got tricky because it's not enough to simply effect execution paths - a lot of these stats-related features also have an impact on memory layout (i.e. C ifdefs around struct field declarations), so I haven't worked further on that idea at this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i understand and agree with everything you've said the re: making use
options controllable via ponyc and that it is not an easy or trivial thing to accomplish. i was simply stating that in an ideal scenario, they would all be selectable via ponyc
as they can be useful for "power users" (along with folks working on/troubleshooting the runtime). Your idea around shipping multiple versions of the runtime and selecting between them based on compiler flags sounds like a great next step.
@dipinhora Can you add a note about the new |
@ergl added |
@SeanTAllen - do you want to review again before we merge? |
I'm ok with no more review from me. |
This PR enhances the runtime stats tracking that was previously
implemented under the
USE_MEMTRACK
andUSED_MEMTRACK_MESSAGES
defines. The new defines are called
USE_RUNTIMESTATS
andUSE_RUNTIMESTATS_MESSAGES
.Runtime stats tracking tracks the following actor info:
Runtime tracking tracks the following scheduler info:
This runtime stats tracking info has been exposed to pony programs as
part of the
runtime_info
package and an exampleruntime_info
programhas been added to the
examples
directory.The runtime stats tracking in a pony program can be used for some
useful validations for those folks concerned about
heap allocations in the critical path (i.e. if they
rely on the compiler's
HeapToStack
optimization passto convert heap allocations to stack allocations and
want to validate it is working correctly).
Example of possible use to validate number of heap allocations: