Page 2 of 2

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Thu Apr 15, 2021 10:24 am
by alex31
Hello,

what is the difference between statistic module (CH_DBG_STATISTICS) and profiling module (CH_DBG_THREADS_PROFILING) ?

do they offer same kind of service ?
CH_DBG_THREADS_PROFILING is not compatible with tickless mode, so is it only there for legacy, and new development should use STATISTICS instead ?

Alexandre

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Thu Apr 15, 2021 12:28 pm
by Giovanni
Profiling uses the system tick interrupt to increase a counter in threads, it is only meaningful after a long runtime. It is a legacy mechanism, it could be removed in future versions.

Giovanni

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Thu Apr 15, 2021 6:24 pm
by andypiper
Giovanni wrote:There should not be weird values for "cumulative", that is an uint64_t variable that is only increased until it wraps.

Giovanni


Ok eliminating 0 and 0xFFFFFFFF makes things a bit better, but I still have this:

stats.best=0x151 stats.worst=0x88887DCB stats.cumulative=0x899038D8 stats.n=16898
FTP PRI= 58 sp=0x30023D40 STACK=1488/2896 MIN= 43 AVG=17073 MAX=286330810 TOT=25.0%

So the cumulative/worst value is totally unbelievable. This also happens to be the calling thread - is there some possibility that the stats are messed up if you are in the thread concerned? (the first line is the raw values, the second via unsigned(RTC2US(STM32_HSECLK, stats.worst)) for instance)

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Thu Apr 15, 2021 6:41 pm
by andypiper
andypiper wrote:
Ok eliminating 0 and 0xFFFFFFFF makes things a bit better, but I still have this:

stats.best=0x151 stats.worst=0x88887DCB stats.cumulative=0x899038D8 stats.n=16898
FTP PRI= 58 sp=0x30023D40 STACK=1488/2896 MIN= 43 AVG=17073 MAX=286330810 TOT=25.0%

So the cumulative/worst value is totally unbelievable. This also happens to be the calling thread - is there some possibility that the stats are messed up if you are in the thread concerned? (the first line is the raw values, the second via unsigned(RTC2US(STM32_HSECLK, stats.worst)) for instance)



Solved it! It's not safe to call chTMObjectInit(&tp->stats) when tp is the current thread!

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Thu Apr 15, 2021 6:44 pm
by Giovanni
Hi,

You should not change anything in a thread structure, why are you initializing that? it is done already when the thread is created.

Giovanni

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Thu Apr 15, 2021 7:51 pm
by andypiper
Giovanni wrote:Hi,

You should not change anything in a thread structure, why are you initializing that? it is done already when the thread is created.

Giovanni


I need to reset the statistics so that the data is not skewed by transient initial conditions

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Sun Apr 18, 2021 4:34 pm
by andypiper
Giovanni wrote:Hi,

You should not change anything in a thread structure, why are you initializing that? it is done already when the thread is created.

Giovanni


Another question - is it possible to get the stats for the ISRs?

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Sun Apr 18, 2021 5:18 pm
by Giovanni
Yes, in "ch.kernel_stats", see "struct ch_system" in chschd.h.

Giovanni

Re: Programmatic use of CH_DBG_STATISTICS

Posted: Fri Apr 30, 2021 9:33 am
by alex31
Hi,

This topics make me discover STATISTICS module.

This module fulfills all my needs, ChibiOS is full of gems that are sometime hard to discover.

Perhaps the thread command in the shell examples should use it and display thread and ISR cpu %

Alexandre