Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found <a href="http://oprofile.sourceforge.net" rel="nofollow noreferrer">oprofile</a> to be a lot better option than gprof for profiling, in this situation. The <a href="http://oprofile.sourceforge.net/examples/" rel="nofollow noreferrer">reports from oprofile</a> are much more comprehensive. I compiled out the ruby portions which were causing the seg-faults (not all of them were), from the C extension using #ifndef PROFILE, and replaced them with non-ruby code. I wrote a main() routine within the extension itself, to call the functions in the extension. Then I set up a makefile to compile the extension as a C program with PROFILE defined. Then I <a href="http://lbrandy.com/blog/2008/11/oprofile-profiling-in-linux-for-fun-and-profit/" rel="nofollow noreferrer">installed oprofile on Ubuntu</a>. Wrote this script.</p> <pre><code>#!/bin/bash sudo opcontrol --reset sudo opcontrol --start ./a.out Rome Damascus NewYork Delhi Bangalore sudo opcontrol --shutdown opreport -lt1 </code></pre> <p>Compiled my program, and executed the above script, which gives output like this from the "opreport" command:</p> <pre><code>... ... Killing daemon. warning: /no-vmlinux could not be found. warning: [vdso] (tgid:10675 range:0x920000-0x921000) could not be found. warning: [vdso] (tgid:1270 range:0xba1000-0xba2000) could not be found. warning: [vdso] (tgid:1675 range:0x973000-0x974000) could not be found. warning: [vdso] (tgid:1711 range:0x264000-0x265000) could not be found. warning: [vdso] (tgid:1737 range:0x990000-0x991000) could not be found. warning: [vdso] (tgid:2477 range:0xa53000-0xa54000) could not be found. warning: [vdso] (tgid:5658 range:0x7ae000-0x7af000) could not be found. CPU: Core Solo / Duo, speed 1000 MHz (estimated) Counted CPU_CLK_UNHALTED events (Unhalted clock cycles) with a unit mask of 0x00 (Unhalted core cycles) count 100000 samples % app name symbol name 12731 32.8949 a.out levenshtein 11958 30.8976 a.out corpora_pass2 5231 13.5161 no-vmlinux /no-vmlinux 4021 10.3896 a.out corpora_pass1 1733 4.4778 libc-2.10.1.so /lib/tls/i686/cmov/libc-2.10.1.so 542 1.4004 ld-2.10.1.so /lib/ld-2.10.1.so 398 1.0284 a.out method_top_matches </code></pre> <p>There it is: the top consumer is the function levenshtein(). I followed this by another command to generate disassembled output annotated with source code and execution count/time of each line. This looks like this (counts/times are on the left of each executed line):</p> <pre><code>&gt; opannotate --source --assembly ./a.out &gt; report.as.handcoded.1 &gt; cat report.as.handcoded.1 ... ... ... : __asm__ ( 2 0.0069 : 804918a: mov -0x50(%ebp),%ecx 4 0.0137 : 804918d: mov -0x54(%ebp),%ebx : 8049190: mov -0x4c(%ebp),%eax 12 0.0412 : 8049193: cmp %eax,%ecx 10 0.0344 : 8049195: cmovbe %ecx,%eax 8 0.0275 : 8049198: cmp %eax,%ebx 11 0.0378 : 804919a: cmovbe %ebx,%eax 16 0.0550 : 804919d: mov %eax,-0x4c(%ebp) : "cmp %0, %2\n\t" : "cmovbe %2, %0\n\t" : : "+r"(a) : : "%r"(b), "r"(c) : ); : return a; ... ... ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload