Programmatic use of CH_DBG_STATISTICS

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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
andypiper
Posts: 65
Joined: Sat Oct 24, 2020 5:21 pm
Has thanked: 5 times
Been thanked: 4 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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)
andypiper
Posts: 65
Joined: Sat Oct 24, 2020 5:21 pm
Has thanked: 5 times
Been thanked: 4 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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
andypiper
Posts: 65
Joined: Sat Oct 24, 2020 5:21 pm
Has thanked: 5 times
Been thanked: 4 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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
andypiper
Posts: 65
Joined: Sat Oct 24, 2020 5:21 pm
Has thanked: 5 times
Been thanked: 4 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Programmatic use of CH_DBG_STATISTICS

Post by Giovanni »

Yes, in "ch.kernel_stats", see "struct ch_system" in chschd.h.

Giovanni
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Programmatic use of CH_DBG_STATISTICS

Post 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
Post Reply