1

我计划很快购买新的 Mac 桌面,我想知道 CPU、RAM 还是我的硬盘驱动器是我的脚本的瓶颈。

我在 Ubuntu 12.04 上使用 Ruby 1.9.3 运行了我的主要单元测试,并获得了以下信息:

$ date; /usr/bin/time --verbose ruby1.9.1 test/test_all.rb ; date
Mon May  7 15:04:38 EST 2012
Run options: 

# Running tests:

[snip 705 dots]

Finished tests in 50.672999s, 13.9127 tests/s, 49.1781 assertions/s.

705 tests, 2492 assertions, 0 failures, 0 errors, 0 skips
    Command being timed: "ruby1.9.1 test/test_all.rb"
    User time (seconds): 29.25
    System time (seconds): 5.26
    Percent of CPU this job got: 67%
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:51.01
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Maximum resident set size (kbytes): 238592
    Average resident set size (kbytes): 0
    Major (requiring I/O) page faults: 0
    Minor (reclaiming a frame) page faults: 4180160
    Voluntary context switches: 31187
    Involuntary context switches: 12397
    Swaps: 0
    File system inputs: 0
    File system outputs: 224
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 0
Mon May  7 15:05:29 EST 2012

由于用户加系统所花费的时间少于挂墙时间,我认为 CPU 不是唯一的瓶颈。我怎样才能弄清楚还有什么瓶颈?

4

1 回答 1

2

您可以使用valgrind 的cachegrind 工具来分析您的程序的内存性能(即它如何利用缓存) 。

$ valgrind --tool=cachegrind ruby ./hello.rb
==7082== Cachegrind, a cache and branch-prediction profiler.
==7082== Copyright (C) 2002-2008, and GNU GPL'd, by Nicholas Nethercote et al.
==7082== Using LibVEX rev 1884, a library for dynamic binary translation.
==7082== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==7082== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==7082== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==7082== For more details, rerun with: -v
==7082== 
hello world
==7082== 
==7082== I   refs:      14,529,000
==7082== I1  misses:        24,856
==7082== L2i misses:         6,707
==7082== I1  miss rate:       0.17%
==7082== L2i miss rate:       0.04%
==7082== 
==7082== D   refs:       7,110,663  (4,572,482 rd   + 2,538,181 wr)
==7082== D1  misses:        48,207  (   33,427 rd   +    14,780 wr)
==7082== L2d misses:        16,350  (    3,821 rd   +    12,529 wr)
==7082== D1  miss rate:        0.6% (      0.7%     +       0.5%  )
==7082== L2d miss rate:        0.2% (      0.0%     +       0.4%  )
==7082== 
==7082== L2 refs:           73,063  (   58,283 rd   +    14,780 wr)
==7082== L2 misses:         23,057  (   10,528 rd   +    12,529 wr)
==7082== L2 miss rate:         0.1% (      0.0%     +       0.4%  )

关于磁盘性能,我相信没有磁盘/io 使用的程序几乎可以完全在用户时间内运行,这让我相信您的硬盘驱动器可能至少是您的瓶颈之一。也许有人可以推荐一个好的工具来分析程序的磁盘使用情况?

于 2012-05-08T02:50:48.447 回答