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

ruby-changes:23027

From: ktsj <ko1@a...>
Date: Sun, 18 Mar 2012 10:03:48 +0900 (JST)
Subject: [ruby-changes:23027] ktsj:r35076 (trunk): * lib/profiler.rb: support calling singleton methods of

ktsj	2012-03-18 10:03:35 +0900 (Sun, 18 Mar 2012)

  New Revision: 35076

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

  Log:
    * lib/profiler.rb: support calling singleton methods of
      an instance of BasicObject.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35075)
+++ ChangeLog	(revision 35076)
@@ -1,3 +1,8 @@
+Sun Mar 18 10:01:02 2012  Kazuki Tsujimoto  <kazuki@c...>
+
+	* lib/profiler.rb: support calling singleton methods of
+	  an instance of BasicObject.
+
 Sat Mar 17 06:56:58 2012  Eric Hodel  <drbrain@s...>
 
 	* object.c:  Fix indentation of Class#inherited example.
Index: lib/profiler.rb
===================================================================
--- lib/profiler.rb	(revision 35075)
+++ lib/profiler.rb	(revision 35076)
@@ -59,7 +59,7 @@
 
 module Profiler__
   # internal values
-  @@start = @@stack = @@map = nil
+  @@start = @@stack = @@map = @@array = nil
   PROFILE_PROC = proc{|event, file, line, id, binding, klass|
     case event
     when "call", "c-call"
@@ -69,7 +69,11 @@
       now = Process.times[0]
       key = [klass, id]
       if tick = @@stack.pop
-        data = (@@map[key] ||= [0, 0.0, 0.0, key])
+        data = begin
+                 @@map[key] ||= [0, 0.0, 0.0, key]
+               rescue NoMethodError
+                 @@array.find{|i| i[3] == key} || (@@array << [0, 0.0, 0.0, key])[-1]
+               end
         data[0] += 1
         cost = now - tick[0]
         data[1] += cost
@@ -83,6 +87,7 @@
     @@start = Process.times[0]
     @@stack = []
     @@map = {}
+    @@array = []
     set_trace_func PROFILE_PROC
   end
   def stop_profile
@@ -92,7 +97,7 @@
     stop_profile
     total = Process.times[0] - @@start
     if total == 0 then total = 0.01 end
-    data = @@map.values
+    data = @@map.values + @@array
     data = data.sort_by{|x| -x[2]}
     sum = 0
     f.printf "  %%   cumulative   self              self     total\n"
@@ -113,6 +118,9 @@
       name += "."
     end
     name + id.id2name
+  rescue NoMethodError => e
+    name = e.message.slice(/#<.*?:0x[0-9a-f]+>/) || ""
+    name + "." + id.id2name
   end
   private :get_name
 end

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

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