启动数据打点通过使用一下两种方法打点获取的到的时差的差值最高有800多毫秒
import process from '@ohos.process';
let a1= process.getPastCpuTime()
let a2= Date.now();
....
let b1= process.getPastCpuTime()
let b2= Date.now();
启动数据打点通过使用一下两种方法打点获取的到的时差的差值最高有800多毫秒
import process from '@ohos.process';
let a1= process.getPastCpuTime()
let a2= Date.now();
....
let b1= process.getPastCpuTime()
let b2= Date.now();
在OpenHarmony(OHOS)或类似的操作系统中,process.getPastCpuTime()
和 Date.now()
这两个API的用途和行为是有显著差异的,这可能导致你观察到的时差差异较大。
process.getPastCpuTime()
getPastCpuTime()
的值可能不会增加。Date.now()
Date.now()
方法返回自1970年1月1日 00:00:00 UTC到当前时间的毫秒数。它测量的是“墙钟时间”(wall-clock time),即系统实际运行的时间,与CPU的使用情况无关。由于这两个API测量的是完全不同的时间维度,因此它们之间的差值可能非常大,尤其是在涉及I/O操作或系统负载较高的情况下。例如:
getPastCpuTime()
的值可能几乎没有变化,而Date.now()
会反映出这段时间的实际流逝。getPastCpuTime()
会显著增加,而Date.now()
同样会反映出这段时间的流逝,但两者之间的差值将主要反映CPU使用时间的增加。Date.now()
。综上所述,如果你观察到process.getPastCpuTime()
和 Date.now()
之间的差值很大,这通常是正常的,因为它们测量的不是相同的时间维度。选择哪个API取决于你的具体需求。
1 回答662 阅读✓ 已解决
1 回答626 阅读
1 回答635 阅读
1 回答628 阅读
1 回答525 阅读
584 阅读
Date.now()是系统时间,实时的,这个比较准确。process.getPastCpuTime()是CPU时间,进程启动阶段不是一直在运行,可能存在休眠。所有会有差异。 process.getPastCpuTime详细可以看一下clock_gettime函数的CLOCK_PROCESS_CPUTIME_ID类型。