lsof counterpart for a JVM?
Asked Answered
B

1

6

lsof is a nice tool for Unix, showing all currently open file handles.

Does anyone know a similar tool that would show all open files inside a running JVM (via JVMTI or any similar interface)?

In this particular case, it would be sufficient for me to know which class has a handle open. Method/line or even an entire chain to GC root would be fantastic, but handler owner class is already a good start.

I know I could make a heap dump, open it in a profiler and find this out, but this is a tedious task, especially for the big heaps.

Bingle answered 22/6, 2011 at 14:48 Comment(3)
I would suggest you use a better profiler. ;) In YourKit I can see all the open files while the application is running.Berrios
I use YourKit, but you rarely have profiling enabled on live environments. Or does YourKit support showing file handles from dumps?Bingle
It supports showing FileDescriptor from a dump by searching by class which is used for all open files. You can see where references to any file are being held.Berrios
C
1

The JVMTI option sounds like it wouldn't be a bad choice. The big issue would be ensuring you wrap everything that may open a file handle: you would basically have to go through the JDK source code and find every native function that did a file open (littered throughout java.io., java.nio., I'd think java.net.* as well if you consider sockets as file handles, and just about everywhere else that a file handle may be opened by a native function) and then wrap them all with the SetNativeMethodPrefix call.

I'm assuming that is what some of the profiling folks do: however if you're not required to do this listing in real time then I'd think it would be WAY easier to use lsof or handle (on Windows platforms) and filter for your JVM's process id.

Clareta answered 22/6, 2011 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.