For a detailed discussion of techniques for the last bit of advice in that topic, see this:
I recommend you not do this. Just store the timestamp, event value, and some kind of process/machine/component ID with S&F.
Databases are really good at delivering the actual durations after the fact using LEAD() or LAG(), without having to do anything special to account for system start/stop, scripting restarts, and/or tag restarts.