I agree with Dan's answer - here are some additions / improvements:
(1) Window based calculations. , since there is apparently no periodicity by default, you will need to calculate its execution time in terms of the percentage spent on this task on a certain window (say, 1000 ms), you will need to determine the static variable used to accumulate clicks a timer. Once your window has expired (that is: 1000 ms has passed), you can calculate the time spent on default compared to 1000 ms, which will be the percentage spent on default. Since I am reading your description, it seems that the default state is basically a state of inactivity - this means that this percentage is approximately your available micro-consumption.
(2) one survey per hour. . If you can use a 32-bit counter, and you capture usec timestamps, you can do this 1 hour before the rollover occurs. If you use this for a home project, you have the option to ignore rollovers. This will contribute to a single distorted window of 1000 ms, and that’s it. If, on the other hand, you will monitor the maximum use and install an error or diagnosis because of this ... then you want to consider it.
(3) ISR skew. Determining whether to handle the time spent on the ISR other than the time spent on another task depends on how your RTOS handles the context switch. As Dan points out, most RTOS have a kind of callback or hook that fires when a task is switched. Some RTOS have a separate hook for ISR only. I’m not quite sure that the motivation for this is different from the general theory that users are less likely to care about the time spent (apparently) on short ISRs than about the user's tasks themselves. In any case, check how your RTOS handles this switch from there.
If you do not handle this correctly, the time spent on the ISR will be assigned to any task that was performed at the time the ISR was launched. If you find yourself in the "Default" section, then your default task has "consumed" the ISR time. If you do not have many ISRs running, I will completely ignore this.
Good luck I did this with the PowerPC 551X family, and it was for the production of automotive software, so it had to be perfect! It should be much easier for you :)
source share