Skip to content

Commit 95928dd

Browse files
authored
Fix incorrect printing of runtime stats (#4620)
Some scheduler and actor runtime stat printing weren't properly gated by the "should print" check and thus would always print. Closes #4619
1 parent 453589f commit 95928dd

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

.release-notes/4620.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Fix incorrect printing of runtime stats
2+
3+
When the runtime was compiled with the runtime stats option on, some stats were being printed to standard out without them having been requested. We've fixed the issue so stats will only be printed if the option is turned on by the user.

src/libponyrt/actor/actor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,8 @@ void ponyint_actor_destroy(pony_actor_t* actor)
769769
ctx->schedulerstats.mem_used_actors -= actor->type->size;
770770
ctx->schedulerstats.mem_allocated_actors -= ponyint_pool_used_size(actor->type->size);
771771
ctx->schedulerstats.destroyed_actors_counter++;
772-
print_actor_stats(actor);
772+
if (ponyint_sched_print_stats())
773+
print_actor_stats(actor);
773774
#endif
774775

775776
// Free variable sized actors correctly.

src/libponyrt/sched/scheduler.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ void print_scheduler_stats(scheduler_t* sched)
110110
);
111111
}
112112

113+
/* Get whether stat printing is on */
114+
bool ponyint_sched_print_stats()
115+
{
116+
return print_stats;
117+
}
118+
113119
/** Get the static memory used by the scheduler subsystem.
114120
*/
115121
size_t ponyint_sched_static_mem_size()
@@ -1134,7 +1140,7 @@ static void run(scheduler_t* sched)
11341140
while(true)
11351141
{
11361142
#ifdef USE_RUNTIMESTATS
1137-
if(print_stats)
1143+
if(ponyint_sched_print_stats())
11381144
{
11391145
// convert to cycles for use with ponyint_cpu_tick()
11401146
// 1 second = 2000000000 cycles (approx.)
@@ -1219,7 +1225,8 @@ static void run(scheduler_t* sched)
12191225
#ifdef USE_RUNTIMESTATS
12201226
uint64_t used_cpu = ponyint_sched_cpu_used(&sched->ctx);
12211227
sched->ctx.schedulerstats.misc_cpu += used_cpu;
1222-
print_scheduler_stats(sched);
1228+
if(ponyint_sched_print_stats())
1229+
print_scheduler_stats(sched);
12231230
#endif
12241231

12251232
// Termination.
@@ -1427,7 +1434,7 @@ static void run_pinned_actors()
14271434
while(true)
14281435
{
14291436
#ifdef USE_RUNTIMESTATS
1430-
if(print_stats)
1437+
if(ponyint_sched_print_stats())
14311438
{
14321439
// convert to cycles for use with ponyint_cpu_tick()
14331440
// 1 second = 2000000000 cycles (approx.)
@@ -1454,8 +1461,9 @@ static void run_pinned_actors()
14541461
if(sched->terminate)
14551462
{
14561463
#ifdef USE_RUNTIMESTATS
1457-
uint64_t used_cpu = ponyint_sched_cpu_used(&sched->ctx);
1458-
sched->ctx.schedulerstats.misc_cpu += used_cpu;
1464+
uint64_t used_cpu = ponyint_sched_cpu_used(&sched->ctx);
1465+
sched->ctx.schedulerstats.misc_cpu += used_cpu;
1466+
if(ponyint_sched_print_stats())
14591467
print_scheduler_stats(sched);
14601468
#endif
14611469

@@ -1484,7 +1492,7 @@ static void run_pinned_actors()
14841492
uint64_t clocks_elapsed = tsc2 - tsc;
14851493

14861494
// We had an empty queue and no actor. need to suspend or sleep only if
1487-
// mutemap is empty as this thread doesn't participate in work stealing
1495+
// mutemap is empty as this thread doesn't participate in work stealing
14881496
if(ponyint_mutemap_size(&sched->mute_mapping) == 0 && clocks_elapsed > scheduler_suspend_threshold)
14891497
{
14901498
// suspend

src/libponyrt/sched/scheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ void ponyint_sched_maybe_wakeup(int32_t current_scheduler_id);
157157
void ponyint_sched_maybe_wakeup_if_all_asleep(int32_t current_scheduler_id);
158158

159159
#ifdef USE_RUNTIMESTATS
160+
bool ponyint_sched_print_stats();
161+
160162
uint64_t ponyint_sched_cpu_used(pony_ctx_t* ctx);
161163

162164
/** Get the static memory used by the scheduler subsystem.

0 commit comments

Comments
 (0)