@@ -407,6 +407,7 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
407407 s -> buffer_wait .target = s ;
408408 s -> buffer_wait .wakeup_cb = stream_buf_available ;
409409
410+ s -> lat_time = s -> cpu_time = 0 ;
410411 s -> call_rate .curr_tick = s -> call_rate .curr_ctr = s -> call_rate .prev_ctr = 0 ;
411412 s -> pcli_next_pid = 0 ;
412413 s -> pcli_flags = 0 ;
@@ -1556,6 +1557,17 @@ static void stream_update_both_sc(struct stream *s)
15561557 }
15571558}
15581559
1560+ /* if the current task's wake_date was set, it's being profiled, thus we may
1561+ * report latencies and CPU usages in logs, so it's desirable to update the
1562+ * latency when entering process_stream().
1563+ */
1564+ static void stream_cond_update_cpu_latency (struct stream * s )
1565+ {
1566+ uint32_t lat = th_ctx -> sched_call_date - th_ctx -> sched_wake_date ;
1567+
1568+ s -> lat_time += lat ;
1569+ }
1570+
15591571/* if the current task's wake_date was set, it's being profiled, thus we may
15601572 * report latencies and CPU usages in logs, so it's desirable to do that before
15611573 * logging in order to report accurate CPU usage. In this case we count that
@@ -1573,11 +1585,23 @@ static void stream_cond_update_cpu_usage(struct stream *s)
15731585 return ;
15741586
15751587 cpu = (uint32_t )now_mono_time () - th_ctx -> sched_call_date ;
1576- s -> task -> cpu_time += cpu ;
1588+ s -> cpu_time += cpu ;
15771589 HA_ATOMIC_ADD (& th_ctx -> sched_profile_entry -> cpu_time , cpu );
15781590 th_ctx -> sched_wake_date = 0 ;
15791591}
15801592
1593+ /* this functions is called directly by the scheduler for tasks whose
1594+ * ->process points to process_stream(), and is used to keep latencies
1595+ * and CPU usage measurements accurate.
1596+ */
1597+ void stream_update_timings (struct task * t , uint64_t lat , uint64_t cpu )
1598+ {
1599+ struct stream * s = t -> context ;
1600+ s -> lat_time += lat ;
1601+ s -> cpu_time += cpu ;
1602+ }
1603+
1604+
15811605/* This macro is very specific to the function below. See the comments in
15821606 * process_stream() below to understand the logic and the tests.
15831607 */
@@ -1649,6 +1673,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
16491673 DBG_TRACE_ENTER (STRM_EV_STRM_PROC , s );
16501674
16511675 activity [tid ].stream_calls ++ ;
1676+ stream_cond_update_cpu_latency (s );
16521677
16531678 req = & s -> req ;
16541679 res = & s -> res ;
@@ -3376,14 +3401,13 @@ static int stats_dump_full_strm_to_buffer(struct stconn *sc, struct stream *strm
33763401 }
33773402 else if ((tmpctx = sc_appctx (scf )) != NULL ) {
33783403 chunk_appendf (& trash ,
3379- " app0=%p st0=%d st1=%d applet=%s tid=%d nice=%d calls=%u rate=%u cpu=%llu lat=%llu \n" ,
3404+ " app0=%p st0=%d st1=%d applet=%s tid=%d nice=%d calls=%u rate=%u\n" ,
33803405 tmpctx ,
33813406 tmpctx -> st0 ,
33823407 tmpctx -> st1 ,
33833408 tmpctx -> applet -> name ,
33843409 tmpctx -> t -> tid ,
3385- tmpctx -> t -> nice , tmpctx -> t -> calls , read_freq_ctr (& tmpctx -> call_rate ),
3386- (unsigned long long )tmpctx -> t -> cpu_time , (unsigned long long )tmpctx -> t -> lat_time );
3410+ tmpctx -> t -> nice , tmpctx -> t -> calls , read_freq_ctr (& tmpctx -> call_rate ));
33873411 }
33883412
33893413 scb = strm -> scb ;
@@ -3419,14 +3443,13 @@ static int stats_dump_full_strm_to_buffer(struct stconn *sc, struct stream *strm
34193443 }
34203444 else if ((tmpctx = sc_appctx (scb )) != NULL ) {
34213445 chunk_appendf (& trash ,
3422- " app1=%p st0=%d st1=%d applet=%s tid=%d nice=%d calls=%u rate=%u cpu=%llu lat=%llu \n" ,
3446+ " app1=%p st0=%d st1=%d applet=%s tid=%d nice=%d calls=%u rate=%u\n" ,
34233447 tmpctx ,
34243448 tmpctx -> st0 ,
34253449 tmpctx -> st1 ,
34263450 tmpctx -> applet -> name ,
34273451 tmpctx -> t -> tid ,
3428- tmpctx -> t -> nice , tmpctx -> t -> calls , read_freq_ctr (& tmpctx -> call_rate ),
3429- (unsigned long long )tmpctx -> t -> cpu_time , (unsigned long long )tmpctx -> t -> lat_time );
3452+ tmpctx -> t -> nice , tmpctx -> t -> calls , read_freq_ctr (& tmpctx -> call_rate ));
34303453 }
34313454
34323455 chunk_appendf (& trash ,
@@ -3682,7 +3705,7 @@ static int cli_io_handler_dump_sess(struct appctx *appctx)
36823705 curr_strm -> task -> state , curr_strm -> stream_epoch ,
36833706 human_time (now .tv_sec - curr_strm -> logs .tv_accept .tv_sec , 1 ),
36843707 curr_strm -> task -> calls , read_freq_ctr (& curr_strm -> call_rate ),
3685- (unsigned long long )curr_strm -> task -> cpu_time , (unsigned long long )curr_strm -> task -> lat_time );
3708+ (unsigned long long )curr_strm -> cpu_time , (unsigned long long )curr_strm -> lat_time );
36863709
36873710 chunk_appendf (& trash ,
36883711 " rq[f=%06xh,i=%u,an=%02xh,rx=%s" ,
0 commit comments