Java Tip 92: Use the JVM Profiler Interface for accurate timing; Improve performance analysis by measuring Java thread CPU time
Summary - Most Java programs are multithreaded, either by design or becausethe garbage collector runs on its own thread. This makes performance analysis difficult because you can never be surehow much CPU time the thread scheduler actually allows a thread.Fortunately, Java 2's Java Virtual Mach...
Saved in:
| Published in: | Java world p. 1 |
|---|---|
| Main Authors: | , |
| Format: | Magazine Article |
| Language: | English |
| Published: |
San Francisco
Foundry
01.05.2000
|
| ISSN: | 1091-8906, 1091-8906 |
| Online Access: | Get full text |
| Tags: |
Add Tag
No Tags, Be the first to tag this record!
|
| Summary: | Summary - Most Java programs are multithreaded, either by design or becausethe garbage collector runs on its own thread. This makes performance analysis difficult because you can never be surehow much CPU time the thread scheduler actually allows a thread.Fortunately, Java 2's Java Virtual Machine Profiler Interface(JVMPI) provides the correct information on CPU time spent in the current thread accessed from within a Java program. (1,400 words) Programming languages like C and Pascalmust use operating system calls to getthe CPU time spent by a thread or process.Java applications can do this too, by using native,and therefore unportable, methods. Unfortunately,the results for an OS thread may not be directlyrelated to the executing Java thread. This isbecause the way Java threads are mapped to OS threads isentirely up to the JVM -- and different JVMs usedifferent strategies. Some JVMs use green threads, which run all theJava threads in one native OS thread (a so-called n-to-one mapping).The HotSpot JVM uses native threads, which may executein parallel on a multi-CPU machine. The fact that several threads are executing in parallel means that the sum of the CPU times may exceed the elapsed real time.On Solaris, Java threads are not bound permanentlyto the same native threads but are remapped by the scheduler(in an n-to-m mapping). So, getting the CPU time for the currentnative thread does not give you the time you want.Contrast this with the Blackdown port of the JDK 1.2 to Linux, wherea thread is akin to a process (one-to-one mapping). |
|---|---|
| ISSN: | 1091-8906 1091-8906 |