]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
track currently running / yielded instructions
authorAlan T. DeKok <aland@freeradius.org>
Mon, 26 Sep 2022 16:20:49 +0000 (12:20 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 26 Sep 2022 16:20:49 +0000 (12:20 -0400)
src/lib/unlang/compile.c
src/lib/unlang/unlang_priv.h

index 6fb32f2a57849345ebc25f1680884cddd785a13a..fa585f83031b7ab0f09e02e8761abfca2f0fa0e6 100644 (file)
@@ -4438,6 +4438,7 @@ void unlang_frame_perf_init(unlang_stack_frame_t *frame)
        t = &unlang_thread_array[instruction->number];
 
        t->use_count++;
+       t->yielded++;                   // everything starts off as yielded
        now = fr_time();
 
        fr_time_tracking_start(NULL, &frame->tracking, now);
@@ -4447,27 +4448,37 @@ void unlang_frame_perf_init(unlang_stack_frame_t *frame)
 void unlang_frame_perf_yield(unlang_stack_frame_t *frame)
 {
        unlang_t const *instruction = frame->instruction;
+       unlang_thread_t *t;
 
        if (!instruction->number || !unlang_thread_array) return;
 
+       t = &unlang_thread_array[instruction->number];
+       t->yielded++;
+       t->running--;
+
        fr_time_tracking_yield(&frame->tracking, fr_time());
 }
 
 void unlang_frame_perf_resume(unlang_stack_frame_t *frame)
 {
        unlang_t const *instruction = frame->instruction;
+       unlang_thread_t *t;
 
        if (!instruction->number || !unlang_thread_array) return;
 
        if (frame->tracking.state != FR_TIME_TRACKING_YIELDED) return;
 
+       t = &unlang_thread_array[instruction->number];
+       t->running++;
+       t->yielded--;
+
        fr_time_tracking_resume(&frame->tracking, fr_time());
 }
 
 void unlang_frame_perf_cleanup(unlang_stack_frame_t *frame)
 {
-       unlang_thread_t *t;
        unlang_t const *instruction = frame->instruction;
+       unlang_thread_t *t;
 
        if (!instruction || !instruction->number || !unlang_thread_array) return;
 
@@ -4475,7 +4486,12 @@ void unlang_frame_perf_cleanup(unlang_stack_frame_t *frame)
 
        t = &unlang_thread_array[instruction->number];
 
-       if (frame->tracking.state == FR_TIME_TRACKING_YIELDED) fr_time_tracking_resume(&frame->tracking, fr_time());
+       if (frame->tracking.state == FR_TIME_TRACKING_YIELDED) {
+               t->yielded--;
+               fr_time_tracking_resume(&frame->tracking, fr_time());
+       } else {
+               t->running--;
+       }
 
        fr_time_tracking_end(NULL, &frame->tracking, fr_time());
        t->tracking.running_total = fr_time_delta_add(t->tracking.running_total, frame->tracking.running_total);
index c0ddbc01094b9e58e6dc60b75c08d9895d32b01f..b5025aa85c9d57cb9ca237c2bfd84daaef551d8b 100644 (file)
@@ -229,7 +229,9 @@ typedef struct {
        unlang_t const          *instruction;                   //!< instruction which we're executing
        void                    *thread_inst;                   //!< thread-specific instance data
 #ifdef WITH_PERF
-       uint64_t                use_count;
+       uint64_t                use_count;                      //!< how many packets it has processed
+       uint64_t                running;                        //!< currently running this instruction
+       uint64_t                yielded;                        //!< currently yielded
        fr_time_tracking_t      tracking;                       //!< tracking cpu time
 #endif
 } unlang_thread_t;