Check this flow with a modified DSM node i did with the help of #cflurin. Best of all it's persistent across reboot, for that you have to modify your setting.js file to allow it.
[{"id":"f6bcc450.adfc18","type":"inject","z":"fffe22a.86fdbe","name":"inject me once","topic":"set","payload":"{\"triggerInput\":\"payload\",\"currentState\":\"stopped\",\"states\":{\"stopped\":{\"on\":\"started\"},\"started\":{\"inc\":\"counting\",\"off\":\"stopped\"},\"counting\":{\"inc\":\"counting\",\"off\":\"stopped\"}},\"data\":{\"prev_time\":null,\"time\":0,\"seconds\":0,\"interval\":5},\"methods\":{\"init\":[\"sm.calc_time = function () {\",\" var now = Date.now();\",\" sm.data.time += now - sm.data.prev_time;\",\" sm.data.prev_time = now;\",\" sm.data.seconds = Math.round(sm.data.time / 1000);\",\"};\",\"sm.sec2hhmmss = function(t) {\",\" var min = t/60;\",\" var t_h = pad(parseInt(min / 60));\",\" var t_m = pad(parseInt(min % 60));\",\" var t_s = pad(Math.round(t % 60));\",\" return t_h+':'+t_m+':'+t_s;\",\"};\"],\"on\":[\"if (sm.currentState === 'started') {\",\" sm.data.prev_time = Date.now();\",\" resume('inc', msg);\",\"}\",\"output = false;\"],\"inc\":[\"timeout.interval = setTimeout(function() {\",\" sm.calc_time();\",\" msg.data = sm.data;\",\" /* msg.payload = sm.sec2hhmmss(sm.data.seconds);\",\" node.send(msg); */\",\" resume('inc', msg);\",\"}, sm.data.interval*1000);\",\"output = false;\"],\"off\":[\"clearTimeout(timeout.interval);\",\"sm.calc_time();\",\"msg.payload = sm.sec2hhmmss(sm.data.seconds);\"],\"reset\":[\"sm.data.time = 0;\",\"sm.data.seconds = 0;\"],\"status\":{\"fill\":{\"get\":\"sm.currentState === 'counting' ? 'green' : 'grey';\"},\"shape\":\"dot\",\"text\":{\"get\":\"'time '+ sm.sec2hhmmss(sm.data.seconds);\"}}}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":380,"wires":[["b17dab3d.fe0408"]]},{"id":"3a5d5987.01a966","type":"inject","z":"fffe22a.86fdbe","name":"on","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":420,"wires":[["b17dab3d.fe0408"]]},{"id":"15f725b3.17c50a","type":"inject","z":"fffe22a.86fdbe","name":"off","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":460,"wires":[["b17dab3d.fe0408"]]},{"id":"b17dab3d.fe0408","type":"dsm","z":"fffe22a.86fdbe","name":"moteur","sm_config":"","x":560,"y":460,"wires":[["d3f9ceef.122a4"]]},{"id":"d3f9ceef.122a4","type":"debug","z":"fffe22a.86fdbe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":460,"wires":[]},{"id":"5c5d6cf.7d3ef94","type":"inject","z":"fffe22a.86fdbe","name":"Reset","topic":"reset","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":500,"wires":[["b17dab3d.fe0408"]]},{"id":"882b828f.104e8","type":"comment","z":"fffe22a.86fdbe","name":"time formated & persistent counter ","info":"","x":420,"y":340,"wires":[]}]
And with a Mysql node you insert start time and update with end time, and reupdate a second after with start minus stop time, that will give you one line in Mysql with start, stop, and duration for each cycle.