[前][次][番号順一覧][スレッド一覧]

ruby-changes:26969

From: nobu <ko1@a...>
Date: Sun, 3 Feb 2013 09:37:44 +0900 (JST)
Subject: [ruby-changes:26969] nobu:r39021 (trunk): profiler.rb: split PROFILE_PROC

nobu	2013-02-03 09:37:26 +0900 (Sun, 03 Feb 2013)

  New Revision: 39021

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39021

  Log:
    profiler.rb: split PROFILE_PROC
    
    * lib/profiler.rb (PROFILE_CALL_PROC, PROFILE_RETURN_PROC): split
      PROFILE_PROC for call and return events.

  Modified files:
    trunk/ChangeLog
    trunk/lib/profiler.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39020)
+++ ChangeLog	(revision 39021)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Feb  3 09:37:22 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/profiler.rb (PROFILE_CALL_PROC, PROFILE_RETURN_PROC): split
+	  PROFILE_PROC for call and return events.
+
 Sat Feb  2 14:32:00 2013  Zachary Scott  <zachary@z...>
 
 	* lib/minitest/mock.rb, lib/minitest/hell.rb: nodoc top-level module
Index: lib/profiler.rb
===================================================================
--- lib/profiler.rb	(revision 39020)
+++ lib/profiler.rb	(revision 39021)
@@ -76,25 +76,23 @@ module Profiler__ https://github.com/ruby/ruby/blob/trunk/lib/profiler.rb#L76
   @@start = nil # the start time that profiling began
   @@stacks = nil # the map of stacks keyed by thread
   @@maps = nil # the map of call data keyed by thread, class and id. Call data contains the call count, total time,
-  PROFILE_PROC = TracePoint.new(:call, :c_call, :return, :c_return) {|tp|
-    case tp.event
-    when :call, :c_call
-      now = Process.times[0]
-      stack = (@@stacks[Thread.current] ||= [])
-      stack.push [now, 0.0]
-    when :return, :c_return
-      now = Process.times[0]
-      key = Wrapper.new(tp.defined_class, tp.method_id)
-      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]
-      end
+  PROFILE_CALL_PROC = TracePoint.new(:call, :c_call) {|tp| # :nodoc:
+    now = Process.times[0]
+    stack = (@@stacks[Thread.current] ||= [])
+    stack.push [now, 0.0]
+  }
+  PROFILE_RETURN_PROC = TracePoint.new(:return, :c_return) {|tp| # :nodoc:
+    now = Process.times[0]
+    key = Wrapper.new(tp.defined_class, tp.method_id)
+    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]
     end
   }
 module_function
@@ -102,10 +100,12 @@ module_function https://github.com/ruby/ruby/blob/trunk/lib/profiler.rb#L100
     @@start = Process.times[0]
     @@stacks = {}
     @@maps = {}
-    PROFILE_PROC.enable
+    PROFILE_CALL_PROC.enable
+    PROFILE_RETURN_PROC.enable
   end
   def stop_profile
-    PROFILE_PROC.disable
+    PROFILE_CALL_PROC.disable
+    PROFILE_RETURN_PROC.disable
   end
   def print_profile(f)
     stop_profile

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]