我正在尝试测量bootloader计时,其中我需要测量SPL、U-Boot和总时间( SPL + U-Boot)。我的minicom控制台日志条目如下
$ cat u-boot-2017-01 | grep -e 'U-Boot SPL 2017' -e 'U-Boot 2017.01' -e 'Starting kernel ...'
[2018-10-11 15:05:11.021] U-Boot SPL 2017.01-05786-ge0aa2fcb13 (Oct 10 2018 - 13:53:01)
[2018-10-11 15:05:11.294] U-Boot 2017.01-05786-ge0aa2fcb13 (Oct 10 2018 - 13:53:01 -0400)
[2018-10-11 15:05:12.706] Starting kernel ...
现在
启动时间为:第1行和第2行的时间戳差异( SPL启动和U-启动启动)
U-Boot启动时间是:第2行和第3行的时间戳差异( U-Boot启动和启动内核)
总时间是:第1行和第3行的时间戳差异。
我看到python timedelta支持年、月、日、小时、分钟、秒、微秒、毫秒,但不确定如何将此时间戳转换为时间增量。我正在学习python,所以我想尝试一下。有没有人能建议一下该怎么做。我必须为多个产品和多个版本的bootloader做这些测量,所以编写脚本会更好。
发布于 2018-10-12 03:48:21
使用datetime.strptime
非常简单,只需要确保使用正确的格式即可。
请参阅可用的指令here。
from datetime import datetime
start_time = '2018-10-11 15:05:11.021'
end_time = '2018-10-11 15:05:11.294'
FORMAT = '%Y-%m-%d %H:%M:%S.%f'
print(datetime.strptime(end_time, FORMAT) - datetime.strptime(start_time, FORMAT))
# 0:00:00.273000
https://stackoverflow.com/questions/52767775
复制相似问题