Thread.times in jruby/core_ext feature reports a cpu times as a system times
----------------------------------------------------------------------------

                 Key: JRUBY-5296
                 URL: http://jira.codehaus.org/browse/JRUBY-5296
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
         Environment: jruby 1.6.0.dev (ruby 1.8.7 patchlevel 330) (2011-01-03 
45c7e9f) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
            Reporter: Hiroshi Nakamura
            Priority: Trivial


If I understand correctly, CPU times = system times + user times.

Anyway, who is using this feature?
{noformat}
diff --git a/src/org/jruby/RubyJRuby.java b/src/org/jruby/RubyJRuby.java
index f7fd9a9..bbe293f 100644
--- a/src/org/jruby/RubyJRuby.java
+++ b/src/org/jruby/RubyJRuby.java
@@ -597,11 +597,19 @@ public class RubyJRuby {
         @JRubyMethod(name = "times", module = true)
         public static IRubyObject times(IRubyObject recv, Block unusedBlock) {
             Ruby runtime = recv.getRuntime();
-            double system = threadBean.getCurrentThreadCpuTime() / 
1000000000.0;
-            double user = threadBean.getCurrentThreadUserTime() / 1000000000.0;
+            long cpu = threadBean.getCurrentThreadCpuTime();
+            long user = threadBean.getCurrentThreadUserTime();
+            if (cpu == -1) {
+                cpu = 0L;
+            }
+            if (user == -1) {
+                user = 0L;
+            }
+            double system_d = (cpu - user) / 1000000000.0;
+            double user_d = user / 1000000000.0;
             RubyFloat zero = runtime.newFloat(0.0);
             return RubyStruct.newStruct(runtime.getTmsStruct(),
-                    new IRubyObject[] { RubyFloat.newFloat(runtime, user), 
RubyFloat.newFloat(runtime, system), zero, zero },
+                    new IRubyObject[] { RubyFloat.newFloat(runtime, user_d), 
RubyFloat.newFloat(runtime, system_d), zero, zero },
                     Block.NULL_BLOCK);
         }
     }
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to