我正在尝试使用 mutrace 测量我的程序中的互斥锁争用,但我对如何使用它输出的报告感到困惑。
mutrace: Showing statistics for process test (PID: 5924).
mutrace: 1223 mutexes used.
Mutex #362 (0x0x1a23750) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test() [0x500042]
Mutex #390 (0x0x1a23ac0) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test() [0x500042]
Mutex #965 (0x0x1a3a600) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test() [0x500042]
Mutex #502 (0x0x1abbc90) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test() [0x500042]
Mutex #241 (0x0x7fb6af9019c0) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_lock+0x116) [0x7fb6b1412da6]
/lib/libgcc_s.so.1(_Unwind_Find_FDE+0x2a) [0x7fb6af6fe3ea]
[(nil)]
Mutex #704 (0x0x7fb6afe85020) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_lock+0x116) [0x7fb6b1412da6]
/usr/lib/libstdc++.so.6(_ZNSt6localeC1Ev+0x2f) [0x7fb6afbf021f]
Mutex #452 (0x0x1a240b0) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test() [0x500042]
Mutex #981 (0x0x1a3a770) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test() [0x500042]
Mutex #626 (0x0x73daa8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test(_ZN7threads5mutexC2Eb+0x5e) [0x50675e]
Mutex #801 (0x0x1ab6798) first referenced by:
/usr/local/lib/libmutrace.so(pthread_mutex_init+0x1b2) [0x7fb6b14129b4]
./test(_ZN7threads5mutexC1Eb+0x5e) [0x50643e]
mutrace: Showing 10 mutexes in order of (write) contention count:
Mutex # Locked Changed Cont. cont.Time[ms] tot.Time[ms] avg.Time[ms] Flags
362 517216 163871 70638 619.184 138.933 0.000 M-.--.
390 180589 61197 31681 5926.827 463.255 0.003 M-.--.
965 38679 24052 10646 661.639 718.836 0.019 M-.--.
502 35394 19012 1540 153.286 134.116 0.004 M-.--.
241 3481 2715 1378 135.624 1.189 0.000 M-.--.
704 20902 3879 70 0.594 6.702 0.000 M-.--.
452 892 158 49 21.401 125.918 0.141 M-.--.
981 2369 2361 12 0.229 12.984 0.005 M-.--.
626 598 270 4 0.139 8.417 0.014 Mx.r-.
801 125 2 1 0.012 0.270 0.002 Mx.r-.
... ... ... ... ... ... ... ||||||
/|||||
Object: M = Mutex, W = RWLock /||||
State: x = dead, ! = inconsistent /|||
Use: R = used in realtime thread /||
Mutex Type: r = RECURSIVE, e = ERRORCHECK, a = ADAPTIVE /|
Mutex Protocol: i = INHERIT, p = PROTECT /
RWLock Kind: r = PREFER_READER, w = PREFER_WRITER, W = PREFER_WRITER_NONREC
mutrace: Note that rwlocks are shown as two lines: write locks then read locks.
mutrace: Note that the flags column R is only valid in --track-rt mode!
mutrace: 275 condition variables used.
Condvar #235 (0x0x7fb6a039d5c8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #153 (0x0x7fb6a8259978) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #42 (0x0x7fb6a03e8188) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #222 (0x0x7fb6a019b7c8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #118 (0x0x7fb6a0223ca8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #8 (0x0x7fb6a820d748) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #171 (0x0x7fb69c04d9d8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #0 (0x0x7fb69c22a2e8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #75 (0x0x7fb6a81a65f8) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
Condvar #142 (0x0x7fb6a001c308) first referenced by:
/usr/local/lib/libmutrace.so(pthread_cond_init+0x120) [0x7fb6b14134be]
./test(_ZN7threads4condC1Ev+0x17) [0x5051b7]
mutrace: Showing 10 condition variables in order of wait contention count:
Cond # Waits Signals Cont. tot.Time[ms] cont.Time[ms] avg.Time[ms] Flags
235 271 0 0 1370.469 0.000 0.000 x.
153 190 0 0 960.142 0.000 0.000 x.
42 65 0 0 328.264 0.000 0.000 x.
222 52 0 0 262.584 0.000 0.000 x.
118 51 0 0 261.869 0.000 0.000 x.
8 48 0 0 242.422 0.000 0.000 x.
171 41 0 0 207.044 0.000 0.000 x.
0 38 0 0 191.881 0.000 0.000 x.
75 37 0 0 186.835 0.000 0.000 x.
142 35 0 0 176.704 0.000 0.000 x.
... ... ... ... ... ... ... ||
/|
State: x = dead, ! = inconsistent /
Use: R = used in realtime thread
mutrace: Note that the flags column R is only valid in --track-rt mode!
mutrace: Total runtime is 3701.228 ms.
mutrace: Results for SMP with 8 processors.
看来我肯定有互斥锁争用问题,但我不知道如何将其关联回我的源代码。我希望有比这更好的回溯。
可执行文件已根据 mutrace 的网站(以及 -g -gdb)使用 -rdynamic 编译。
我在 stackoverflow 上发现了 mutrace,所以希望有人有经验!
谢谢。
最佳答案
从未使用过 mutrace,但地址到符号的转换可以通过以下方式完成: addr2line
例如:
addr2line -e sysopview 0x5051b7
在此示例中,“sysopview”是地址应该位于的二进制文件的路径,0x5051b7 是示例地址。 Addr2line 然后将发出它认为应该映射到它的名称。也适用于回溯。
示例输出:
folkert@belle:~/Projects/entropybroker/trunk$ addr2line -e ./entropy_broker 0x0000000000406968 /home/folkert/Projects/entropybroker/trunk/handle_client.cpp:761
在此示例中,地址 0x406968 映射到文件 handle_client.cpp 的第 761 行。
在 Debian 上,这个程序可以在“binutils”包中找到。
关于c++ - 测量互斥量争用/解释互斥量输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11718997/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
这是一道面试题,我没有答对,但还是很好奇怎么解。你有N个人的大家庭,分别是1,2,3,...,N岁。你想给你的大家庭拍张照片。所有的家庭成员都排成一排。“我是家里的friend,建议家庭成员安排如下:”1岁的家庭成员坐在这一排的最左边。每两个坐在一起的家庭成员的年龄相差不得超过2岁。输入:整数N,1≤N≤55。输出:摄影师可以拍摄的照片数量。示例->输入:4,输出:4符合条件的数组:[1,2,3,4][1,2,4,3][1,3,2,4][1,3,4,2]另一个例子:输入:5输出:6符合条件的数组:[1,2,3,4,5][1,2,3,5,4][1,2,4,3,5][1,2,4,5,3][
我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法
我想使用spawn(针对多个并发子进程)在Ruby中执行一个外部进程,并将标准输出或标准错误收集到一个字符串中,其方式类似于使用Python的子进程Popen.communicate()可以完成的操作。我尝试将:out/:err重定向到一个新的StringIO对象,但这会生成一个ArgumentError,并且临时重新定义$stdxxx会混淆子进程的输出。 最佳答案 如果你不喜欢popen,这是我的方法:r,w=IO.pipepid=Process.spawn(command,:out=>w,:err=>[:child,:out])
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我想知道Ruby用来在命令行打印这些东西的输出流:irb(main):001:0>a="test"=>"test"irb(main):002:0>putsatest=>nilirb(main):003:0>a=>"test"$stdout是否用于irb(main):002:0>和irb(main):003:0>?而且,在这两次调用之间,$stdout的值是否有任何变化?另外,有人能告诉我打印/写入这些内容的Ruby源代码吗? 最佳答案 是的。而且很容易向自己测试/证明。在命令行试试这个:ruby-e'puts"foo"'>test.
我在使用自定义RailsFormBuilder时遇到了问题,从昨天晚上开始我就发疯了。基本上我想对我的构建器方法之一有一个可选block,以便我可以在我的主要content_tag中显示其他内容。:defform_field(method,&block)content_tag(:div,class:'field')doconcatlabel(method,"Label#{method}")concattext_field(method)capture(&block)ifblock_given?endend当我在我的一个Slim模板中调用该方法时,如下所示:=f.form_field:e
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我