gpt4 book ai didi

Haskell 分析 - clock_gettime

转载 作者:行者123 更新时间:2023-12-04 16:09:48 34 4
gpt4 key购买 nike

我正在运行一个进行长时间计算的 Haskell 程序。经过一些分析和跟踪后,我注意到以下内容:

$ /usr/bin/time -v ./hl test.hl
9000045000050000
Command being timed: "./hl test.hl +RTS"
User time (seconds): 1.43
System time (seconds): 1.15

即使我的代码没有显式调用任何系统调用(它读取一个文件并解释其中的一些代码),它也使用了大量的系统时间。

使用 strace -ttT 运行它会显示对计时器的大量调用:
17:04:52.454513 clock_gettime(CLOCK_THREAD_CPUTIME_ID, {1, 282721271}) = 0 <0.000529>
17:04:52.456223 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 <0.000720>
17:04:52.458749 rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 <0.000239>
17:04:52.460288 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {1, 285126436}) = 0 <0.000255>
17:04:52.461650 --- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_pid=0, si_uid=0, si_value=0} ---
17:04:52.462242 rt_sigreturn() = 0 <0.000458>

我认为它可能是 RTS clock ,所以我禁用它并重新运行:
$ /usr/bin/time -v ./hl test.hl +RTS -V0
9000045000050000
Command being timed: "./hl test.hl +RTS -V0"
User time (seconds): 1.73
System time (seconds): 0.85

除了实际的 SIGVTALRM 之外,strace 输出看起来几乎相同:
17:05:16.409729 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 155881514}) = 0 <0.000378>
17:05:16.410746 clock_gettime(CLOCK_MONOTONIC, {2184631, 597586194}) = 0 <0.000432>
17:05:16.412724 clock_gettime(CLOCK_THREAD_CPUTIME_ID, {0, 156994988}) = 0 <0.000290>
17:05:16.413832 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 <0.000245>
17:05:16.415017 rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 <0.000305>

我有几个问题:
  • 为什么 Haskell 反复调用clock_gettime?
  • 有什么方法可以禁用此功能?
  • 最佳答案

    我看了一下clock_gettime在GHC RTS中调用,发现在调用getMonotonicTime中使用这又是 TimerManager 中超时的基础。的GHC.Event IO 管理器用于轮询句柄、文件、系统调用等的库。MIO论文是关于 IO 管理器的一个很好的相对较新的资源。无论如何,我不认为您将能够消除这些电话。

    另请注意,虽然您看到很多这样的时钟调用,但这并不意味着它们是花费最多时间的系统调用,我想这更多地与 GC、实际执行 IO 等有关。

    关于Haskell 分析 - clock_gettime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23438791/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com