[#22684] [Bug #1247] YAML::load converts some dates into strings — Matthew Wilson <redmine@...>

Bug #1247: YAML::load converts some dates into strings

10 messages 2009/03/05

[#22725] [Bug #1253] Fix MSVC Build Issues — Charlie Savage <redmine@...>

Bug #1253: Fix MSVC Build Issues

13 messages 2009/03/07

[#22727] Moving ruby 1.9.1 forward on windows — Charlie Savage <cfis@...>

Hi everyone,

14 messages 2009/03/08

[#22731] [Bug #1255] += for large strings egrigiously slow — James Lee <redmine@...>

Bug #1255: += for large strings egrigiously slow

11 messages 2009/03/08

[#22736] Ruby 1.9.1 and tail recursion optimization — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Moin, moin!

13 messages 2009/03/08
[#22739] Re: Ruby 1.9.1 and tail recursion optimization — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...> 2009/03/08

Wolfgang N疆asi-Donner schrieb:

[#22748] [Feature #1256] Add constant TAILRECURSION to let a program recognize if tail recursion optimization is implemented — Wolfgang Nádasi-Donner <redmine@...>

Feature #1256: Add constant TAILRECURSION to let a program recognize if tail recursion optimization is implemented

7 messages 2009/03/08

[#22803] Relegate 1.8.6 to Engine Yard, part II — Urabe Shyouhei <shyouhei@...>

Hello and sorry for my being slow for this issue. It's OK now for me to pass

21 messages 2009/03/10

[#22812] [Bug #1261] cross-compiling Ruby extensions using mkmf doesn't fully respect DESTDIR — Daniel Golle <redmine@...>

Bug #1261: cross-compiling Ruby extensions using mkmf doesn't fully respect DESTDIR

8 messages 2009/03/10

[#22892] Ruby Time — valodzka <valodzka@...>

Got tired of current ruby Time limitation, I have written this -

24 messages 2009/03/14
[#22949] Re: Ruby Time — Tanaka Akira <akr@...> 2009/03/19

In article <9e19ed87-9d12-4f98-af3c-bd49a71b0bd4@p11g2000yqe.googlegroups.com>,

[#22974] Re: Ruby Time — valodzka <valodzka@...> 2009/03/20

[#22977] Re: Ruby Time — Urabe Shyouhei <shyouhei@...> 2009/03/20

valodzka wrote:

[#22981] Re: Ruby Time — valodzka <valodzka@...> 2009/03/21

> I bet you'll get tired of updating that database. There's a major difference

[#22893] [Feature #1291] O_CLOEXEC flag missing for Kernel::open — David Martin <redmine@...>

Feature #1291: O_CLOEXEC flag missing for Kernel::open

10 messages 2009/03/15

[#22939] [Bug #1303] A name considered a local variable on RHS of an assignment that defines it — Tomas Matousek <redmine@...>

Bug #1303: A name considered a local variable on RHS of an assignment that defines it

8 messages 2009/03/19

[#23063] [Bug #1332] Reading file on Windows is 500x slower then with previous Ruby version — Damjan Rems <redmine@...>

Bug #1332: Reading file on Windows is 500x slower then with previous Ruby version

11 messages 2009/03/30

[#23075] [Bug #1336] Change in string representation of Floats — Brian Ford <redmine@...>

Bug #1336: Change in string representation of Floats

37 messages 2009/03/31
[#23179] [Bug #1336] Change in string representation of Floats — Roger Pack <redmine@...> 2009/04/11

Issue #1336 has been updated by Roger Pack.

[#23181] Re: [Bug #1336] Change in string representation of Floats — Brent Roman <brent@...> 2009/04/11

[#23186] Re: [Bug #1336] Change in string representation of Floats — Yukihiro Matsumoto <matz@...> 2009/04/12

Hi,

[#23187] Re: [Bug #1336] Change in string representation of Floats — Brent Roman <brent@...> 2009/04/13

[#23188] Re: [Bug #1336] Change in string representation of Floats — Yukihiro Matsumoto <matz@...> 2009/04/13

Hi,

[ruby-core:22789] 1152: profiler.rb is not thread-safe

From: James Abley <james.abley@...>
Date: 2009-03-09 22:25:48 UTC
List: ruby-core #22789
Hi,

Sample patch attached for discussion. There are style and best
practice issues with this patch due to my lack of ruby experience.
Please forgive and be so kind as to suggest improvements.

It is intended to highlight some of the areas that must be considered
when making the change to provide thread-safe profiling.

The patch alters the code to make the capture of the data thread-safe
AFAICT. There may be some issues with the data fields / calculations.
I wasn't completely clear what each field in the array was supposed to
be storing. The main issue unresolved by this patch is how best to
present the information.

I've opted for showing information per-thread and a summary as well.

* Should there be a version number outputted, in case downstream tools
are doing something with this information?
* Any comments on how the information is being presented??
* Should profiling be configurable, so that it may not show output per
thread, etc.

Cheers,

James

Attachments (1)

1152-2009-03-09.patch (3.58 KB, text/x-diff)
Index: lib/profiler.rb
===================================================================
--- lib/profiler.rb	(revision 22866)
+++ lib/profiler.rb	(working copy)
@@ -1,29 +1,34 @@
 module Profiler__
   # internal values
-  @@start = @@stack = @@map = nil
+  @@start = nil # the start time that profiling began
+  @@stacks = nil # the map of stack arrays keyed by thread
+  @@maps = nil # the map of map of call data keyed by thread, then by class and id. Call data arrays contains the call count, total time, 
   PROFILE_PROC = proc{|event, file, line, id, binding, klass|
     case event
     when "call", "c-call"
       now = Process.times[0]
-      @@stack.push [now, 0.0]
+      stack = (@@stacks[Thread.current] ||= [])
+      stack.push [now, 0.0]
     when "return", "c-return"
       now = Process.times[0]
       key = [klass, id]
-      if tick = @@stack.pop
-        data = (@@map[key] ||= [0, 0.0, 0.0, key])
+      stack = @@stacks[Thread.current]
+      if tick = stack.pop
+        threadMap = (@@maps[Thread.current] ||= {})
+        data = (threadMap[key] ||= [0, 0.0, 0.0, key])
         data[0] += 1
         cost = now - tick[0]
         data[1] += cost
         data[2] += cost - tick[1]
-        @@stack[-1][1] += cost if @@stack[-1]
+        stack[-1][1] += cost if stack[-1]
       end
     end
   }
 module_function
   def start_profile
     @@start = Process.times[0]
-    @@stack = []
-    @@map = {}
+    @@stacks = {}
+    @@maps = {}
     set_trace_func PROFILE_PROC
   end
   def stop_profile
@@ -33,27 +38,62 @@
     stop_profile
     total = Process.times[0] - @@start
     if total == 0 then total = 0.01 end
-    data = @@map.values
+    totals = {}
+    @@maps.each { |thread, threadMap|
+      threadMap.each {|key, data|
+        total_data = (totals[key] ||= [0, 0.0, 0.0, key])
+        total_data[0] += data[0]
+        total_data[1] += data[1] #TODO summing this field doesn't make much sense? Needs discussion on ruby-core
+        total_data[2] += data[2] 
+      }
+      # Print the thread output
+      print_thread(f, thread, threadMap.values, total) if @@maps.length > 1
+    }
+
+    data = totals.values
     data = data.sort_by{|x| -x[2]}
-    sum = 0
+
+    f.printf "Summary\n" if @@maps.length > 1
+    print_header(f)
+    print_call_sites(f, data, total)
+    print_footer(f, total)
+  end
+  def get_name(klass, id)
+    name = klass.to_s || ""
+    if klass.kind_of? Class
+      name += "#"
+    else
+      name += "."
+    end
+    name + id.id2name
+  end
+  def print_thread(f, thread, data, total)
+    data = data.sort_by{|x| -x[2]}
+    f.printf " %s\n", thread
+    print_header(f)
+    print_call_sites(f, data, total)
+    print_footer(f, total)
+    f.printf "\n"
+  end
+  def print_header(f)
     f.printf "  %%   cumulative   self              self     total\n"
     f.printf " time   seconds   seconds    calls  ms/call  ms/call  name\n"
+  end
+  def print_call_sites(f, data, total)
+    sum = 0
     for d in data
       sum += d[2]
       f.printf "%6.2f %8.2f  %8.2f %8d ", d[2]/total*100, sum, d[2], d[0]
       f.printf "%8.2f %8.2f  %s\n", d[2]*1000/d[0], d[1]*1000/d[0], get_name(*d[3])
     end
+  end
+  def print_footer(f, total)
     f.printf "%6.2f %8.2f  %8.2f %8d ", 0.0, total, 0.0, 1     # ???
     f.printf "%8.2f %8.2f  %s\n", 0.0, total*1000, "#toplevel" # ???
   end
-  def get_name(klass, id)
-    name = klass.to_s || ""
-    if klass.kind_of? Class
-      name += "#"
-    else
-      name += "."
-    end
-    name + id.id2name
-  end
   private :get_name
+  private :print_thread
+  private :print_header
+  private :print_call_sites
+  private :print_footer
 end

In This Thread

Prev Next