How to measure how long linux takes to shutdown

I need to calculate how long linux takes to shutdown. I am running an embedded busybox linux on ARM i.MX7. I looked in /var/volatile/log/messages but that only shows the last startup. I need to know how long the system takes to shutdown after eg shutdown -h -P now.

How can I get a reasonably precise measurement?

Asked By: arcomber

||

There is an obvious problem: Shutting down the system requires at some point to close filesystems, so log files can never catch the last bit.

Typically, you have some serial console on such a system and if you enable kernel logging to the console, you have all output with time stamp until immediately before the kernel stops.

On the other hand, the last action of most embedded systems I know is to »pull the plug« by switching off the PMIC to make sure the system is really powered off, so the linux is not really completely driven down.

If the cause of your question is to optimize system shutdown, it’s neither easy nor necessary to cleanly stop all system components. After closing network connections and unmounting and syncing file systems, simply switch off the power. Cleanly unmounting all drivers and the like is very likely superfluous.

Finally, if you really have no serial console for some strange reason, I recommend to use an oscillograph on the power supply: Do something to change the current immediately before shutting down, like changing backlight intensity, then you should be able to calculate the time between this change and the final breath of the system.

Answered By: Philippos