Custom Probe class

Questions about YourKit Java Profiler
Post Reply
magnoyu
Posts: 2
Joined: Mon Aug 28, 2017 4:57 am

Custom Probe class

Post by magnoyu »

Hi, I have a newbie question and wonder how to debug. So I tried to write my first custom probe class:

public final class ProbeQuote {
public static final String TABLE_NAME = "L1QuoteListener onQuote";

private static final class TestsTable extends Table {
private final ClassNameColumn myClass = new ClassNameColumn("L1QuoteListener Class");
private final StringColumn myMethod = new StringColumn("onQuote");

public TestsTable() {
super(ProbeQuote.class, TABLE_NAME, Table.MASK_FOR_LASTING_EVENTS);
}
}
private static final TestsTable T_TESTS = new TestsTable();

@MethodPattern({
"L1QuoteListener:onQuote(*)",
})
public static final class Test_Probe {
public static int onEnter(
@ClassRef final Class testClass,
@MethodName final String methodName
) {
final int rowIndex = T_TESTS.createRow();
T_TESTS.myMethod.setValue(rowIndex, methodName);
T_TESTS.myClass.setValue(rowIndex, testClass);
return rowIndex;
}

public static void onExit(
@OnEnterResult final int rowIndex,
@ThrownException final Throwable e
) {
T_TESTS.closeRow(rowIndex, e);
}
}
}

And I run it with intellij plugin and I can see the yjp log, the probe class is registered.

....
Registered: com.totoro.yourkit.ProbeQuote
....

vm param:
...... dll"=sampling,probe_on=com.totoro.yourkit.ProbeQuote,......

However, it's not showing up in the profiler when I look at it. (ie if any of the method pattern is wrong, I would imagine table is just empty?) But in the profiler, events table, it's not showing up even in the left hand side in the types of events (ie Socket/File/Thread/etc). How do I go about checking what I'm missing?

Thanks,
- Mag
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Custom Probe class

Post by Anton Katilin »

Hello Mag

The table is created when your probe class is loaded. Bytecode instrumentation does not immediately load the class, it only parses its meta-information (annotations, signatures etc.) Instead, the probe class loads implicitly when one of its callbacks is accessed by one of instrumented methods for the first time. If the callbacks are not accessed e.g. because the pattern is incorrect, you won't see the table even an empty one.

So I suggest to check the pattern first. Your pattern is "L1QuoteListener:onQuote(*)". Is the class indeed in the default package?

You may specify the agent startup option "debug=bci" to see in the agent log which methods are instrumented by which probe. Please ensure that the methods of interest are instrumented.

Please also ensure the methods are actually called.

Best regards,
Anton
magnoyu
Posts: 2
Joined: Mon Aug 28, 2017 4:57 am

Re: Custom Probe class

Post by magnoyu »

Ya actually L1QuoteListener is a interface

public interface L1QuoteListener {
public void onQuote(long id, int bidSize, FixedPointNumber bidPrice, FixedPointNumber askPrice, int askSize);
}

Would it work?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Custom Probe class

Post by Anton Katilin »

No. The pattern should explicitly specify classes by name, which in your case means you need to specify implementing classes.
Post Reply