Programmatic use of CH_DBG_STATISTICS

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

Moderators: RoccoMarco, barthess

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: Programmatic use of CH_DBG_STATISTICS

Postby alex31 » Thu Apr 15, 2021 10:24 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Programmatic use of CH_DBG_STATISTICS

Postby Giovanni » Thu Apr 15, 2021 12:28 pm

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

Postby andypiper » Thu Apr 15, 2021 6:24 pm

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

Postby andypiper » Thu Apr 15, 2021 6:41 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Programmatic use of CH_DBG_STATISTICS

Postby Giovanni » Thu Apr 15, 2021 6:44 pm

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

Postby andypiper » Thu Apr 15, 2021 7:51 pm

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

Postby andypiper » Sun Apr 18, 2021 4:34 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Programmatic use of CH_DBG_STATISTICS

Postby Giovanni » Sun Apr 18, 2021 5:18 pm

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

Giovanni

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: Programmatic use of CH_DBG_STATISTICS

Postby alex31 » Fri Apr 30, 2021 9:33 am

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


Return to “STM32 Support”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests