package org.jruby.internal.runtime.methods;
import org.jruby.RubyModule;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Block;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
public class ProfilingDynamicMethod extends DelegatingDynamicMethod implements IRMethodArgs {
public ProfilingDynamicMethod(DynamicMethod delegate) {
super(delegate);
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, arg0);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, arg0, arg1);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, arg0, arg1, arg2);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, args);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, block);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, arg0, block);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, arg0, arg1, block);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, arg0, arg1, arg2, block);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
int previousSerial = context.profileEnter(name, this.delegate.getRealMethod());
final long start = System.nanoTime();
try {
return delegate.call(context, self, clazz, name, args, block);
} finally {
context.profileExit(previousSerial, start);
}
}
@Override
public DynamicMethod dup() {
return new ProfilingDynamicMethod(delegate.dup());
}
public Signature getSignature() {
return delegate instanceof IRMethodArgs ?
((IRMethodArgs) delegate).getSignature() : Signature.from(delegate.getArity());
}
public ArgumentDescriptor[] getArgumentDescriptors() {
return delegate instanceof IRMethodArgs ?
((IRMethodArgs) delegate).getArgumentDescriptors() : Helpers.methodToArgumentDescriptors(delegate);
}
}