ReentrantLock not measured in sampling?

Questions about YourKit Java Profiler
Post Reply
sanderbos
Posts: 8
Joined: Tue Mar 01, 2016 4:14 pm

ReentrantLock not measured in sampling?

Post by sanderbos »

Hello,

if I run a take a sample using YourKit of the following sample code:

Code: Select all

  private void run() throws Exception {
    for (int index = 0; index < 1000; index++) {
      justSleep();
      waitForReentrantLock();
    }
  }

  private void justSleep() throws InterruptedException {
    System.out.println("Sleeping");
    Thread.sleep(1000);
  }

  private void waitForReentrantLock() throws InterruptedException {
    System.out.println("Waiting");
    long endTime = System.currentTimeMillis() + 1000;
    ReentrantLock lock = new ReentrantLock();
    lock.lock();
    synchronized (lock) {
      lock.newCondition().awaitUntil(new Date(endTime));
    }
    lock.unlock();
  }
with

Code: Select all

walltime=*
so that everything is measured as real time, then the time spent in awaitUntil, which should be half of the time (and I sampled this sample for about one minute), is not measured:
Image
I tried it in regular attach mode, and with the yourkit agent loaded, on both Linux and Windows.

I this a known issue? Is there a way in which I can sample this time? If I cannot, are there other calls like this that cannot be monitored?

I found another post about this here: viewtopic.php?f=2&t=3362
But that post is quite old. It also says it is a generic JVM issue, but that is not true, because when sampling from jvisualvm this the waitForReentrantLock is measured just fine.
sanderbos
Posts: 8
Joined: Tue Mar 01, 2016 4:14 pm

Re: ReentrantLock not measured in sampling?

Post by sanderbos »

A collegue of mine has now pointed out that to see this information, you actually have to add

-Dyjp.zero.time.methods=false
to
~/.yjp/ui.ini

to see it.
Which I think is quite a remarkable thing to have enable explicitly (because since my previous post I also found that the same thing also happens for regular Object::wait calls).
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: ReentrantLock not measured in sampling?

Post by Anton Katilin »

Yes, this option is intended to make such methods visible, which are invisible by default because a lot of users reported they wanted not to skip them instead. We have a feature request to make the switch more explicit.
Post Reply