这个统计输出的含义是什么?

时间:2016-06-08 07:56:18

标签: haskell ghc

所以我有一个基于io-streams的管道,我刚刚运行(解释)并使用-s转储统计信息:

    123,680 bytes allocated in the heap
       3,464 bytes copied during GC
      68,912 bytes maximum residency (1 sample(s))
      13,008 bytes maximum slop
           1 MB total memory in use (0 MB lost due to fragmentation)

                                 Tot time (elapsed)  Avg pause  Max pause
Gen  0         0 colls,     0 par    0.000s   0.000s     0.0000s    0.0000s
Gen  1         1 colls,     0 par    0.000s   0.000s     0.0002s    0.0002s

INIT    time    0.000s  (  0.000s elapsed)
MUT     time    0.001s  (299.935s elapsed)
GC      time    0.000s  (  0.000s elapsed)
EXIT    time    0.000s  (  0.000s elapsed)
Total   time    0.134s  (299.936s elapsed)

%GC     time       0.2%  (0.0% elapsed) 

Alloc rate    106,371,724 bytes per MUT second

Productivity  99.7% of total user, 0.0% of total elapsed

所以基本上没有时间花在垃圾收集上。但令我困惑的是括号中的时间。从the docs来看,括号中的时间和时间之间的差异并不明显。任何人都可以对此有所了解吗?

1 个答案:

答案 0 :(得分:1)

括号中的时间是挂钟时间。这是人类(你)在程序运行时遇到的时间,如果你看一下墙上的时钟。 CPU时间是程序遇到的时间:

  

如果您使用-s标志,那么当您的程序完成后,您将看到类似的内容(确切的详细信息将根据您拥有的RTS类型而有所不同,例如,您只会看到分析数据,如果您的编译RTS用于分析):

    36,169,392 bytes allocated in the heap
     4,057,632 bytes copied during GC
     1,065,272 bytes maximum residency (2 sample(s))
        54,312 bytes maximum slop
             3 MB total memory in use (0 MB lost due to fragmentation)

Generation 0:    67 collections,     0 parallel,  0.04s,  0.03s elapsed
Generation 1:     2 collections,     0 parallel,  0.03s,  0.04s elapsed

SPARKS: 359207 (557 converted, 149591 pruned)

INIT  time    0.00s  (  0.00s elapsed)
MUT   time    0.01s  (  0.02s elapsed)
GC    time    0.07s  (  0.07s elapsed)
EXIT  time    0.00s  (  0.00s elapsed)
Total time    0.08s  (  0.09s elapsed)

%GC time      89.5%  (75.3% elapsed)

Alloc rate    4,520,608,923 bytes per MUT second

Productivity  10.5% of total user, 9.1% of total elapsed
     

[...]

     

接下来是运行时系统正在执行的操作所分解的CPU时间和挂钟时间。 INIT是......

挂钟时间通常大于CPU时间,除非您一次使用多个核心。使用getLinesleepecho可以实现CPU时间非常低且挂钟时间很长的简单示例:

$ {sleep 10; echo 1} | ghc -e 'getLine' +RTS -s > /dev/null

      32,006,664 bytes allocated in the heap
      20,644,024 bytes copied during GC
       5,813,624 bytes maximum residency (6 sample(s))
         156,360 bytes maximum slop
              12 MB total memory in use (0 MB lost due to fragmentation)

                                     Tot time (elapsed)  Avg pause  Max pause
  Gen  0        37 colls,     0 par    0.011s   0.011s     0.0003s    0.0009s
  Gen  1         6 colls,     0 par    0.052s   0.052s     0.0087s    0.0105s

  TASKS: 5 (1 bound, 4 peak workers (4 total), using -N1)

  SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)

  INIT    time    0.001s  (  0.001s elapsed)
  MUT     time    0.016s  (  9.903s elapsed) <------------
  GC      time    0.063s  (  0.063s elapsed)
  EXIT    time    0.010s  (  0.010s elapsed)
  Total   time    0.125s  (  9.977s elapsed)

  Alloc rate    1,956,305,120 bytes per MUT second

  Productivity  48.7% of total user, 0.6% of total elapsed

正如您所看到的,MUT CPU时间很短,而MUT挂钟时间很长,因为应用程序等待输入。