In Linux we have the time command to get the real, user and system time
that a command takes.
I know how to get the real time a method takes, but is there a way to
get the user and system time a method takes also?
On Sat, 18 Jul 2020 16:26:35 +0200, Cecil Westerhof wrote:
In Linux we have the time command to get the real, user and system timeThe only way I can think of, offhand would be the Stopwatch class, which appeared here some time ago. I won't include it as the (reasonably well- commented) copy I have is 118 lines. It has start(), stop() methods, so start/stop should be called to time a process and toString() to display
that a command takes.
I know how to get the real time a method takes, but is there a way to
get the user and system time a method takes also?
the elapsed time in seconds. Its resolution is to the nearest millisecond.
I've not included it because my copy is 118 lines, tolerably commented.
I can e-mail you a copy if it looks useful.
On 18-7-2020 22:59, Martin Gregorie wrote:
On Sat, 18 Jul 2020 16:26:35 +0200, Cecil Westerhof wrote:does it looks like this class: https://introcs.cs.princeton.edu/java/stdlib/Stopwatch.java.html
In Linux we have the time command to get the real, user and systemThe only way I can think of, offhand would be the Stopwatch class,
time that a command takes.
I know how to get the real time a method takes, but is there a way to
get the user and system time a method takes also?
which appeared here some time ago. I won't include it as the
(reasonably well- commented) copy I have is 118 lines. It has start(),
stop() methods, so start/stop should be called to time a process and
toString() to display the elapsed time in seconds. Its resolution is to
the nearest millisecond.
I've not included it because my copy is 118 lines, tolerably commented.
I can e-mail you a copy if it looks useful.
In Linux we have the time command to get the real, user and system
time that a command takes.
I know how to get the real time a method takes, but is there a way to
get the user and system time a method takes also?
1. Those are POSIX features, right? They don't have a ready equivalent
in other systems, right? Then Java, which is supposed to be platform-independent, won't have them built-in.
2. System and user time are process-level notions, aren't they?
I don't know the C world that well, but could you get them at the method-level if you limited the scope to native code on a
POSIX-compliant system? If not, you can be certain they won't
be available in Java.
3. How would even this work? What if the thread executing your method is suspended and another takes over for a few loops? What about parallel execution? How would you sort those out in terms of method-level user
and system time?
[...] Under UNIX/
Linux the JVM is a multi-threaded process with a single thread handling
user program execution: IIRC it spawns threads to handle garbage
collection and Swing/awt but nothing external to the JVM process will see either these or any user-defined threads that your program may execute.
This sounds like the "green threads" model used in Old-Time Original
Java of a quarter-century ago. Is Linux still stuck with that relic?
(IIRC there was a time when Linux sort of faked multi-threading by
running multiple processes, but I kind of thought "LinuxThreads" had
long since been replaced by "NPTL.")
Anyhow: If you're right, that would explain why nobody runs Java
on Linux multi-core servers ...
On Tue, 21 Jul 2020 08:42:32 -0400, Eric Sosman wrote:
This sounds like the "green threads" model used in Old-Time Original[...]
Java of a quarter-century ago. Is Linux still stuck with that relic?
AFAIK Java uses the standard thread module but I could be wrong: I
haven't examined its inner workings - just know that a running Java
program looks the same in 'top' as a threaded C program while multiple processes with with shared memory look quite different.
Anyhow: If you're right, that would explain why nobody runs JavaMore do that you may realise: my mail archive is Java and runs on a dual Athlon. I run a variety of Java applications on this Intel i5 based
on Linux multi-core servers ...
laptop. All my computers run Linux apart from one or two PIC-based
devices (PicAXE and Parallax STAMP) but those don't run Java.
I guess my intended ironic tone didn't survive transcription onto Usenet. Shoulda used a smiley ...
On Tue, 21 Jul 2020 01:40:05 +0200, Daniele Futtorovic wrote:
2. System and user time are process-level notions, aren't they?Yes.
I don't know the C world that well, but could you get them at theNo. UNIX/Linux only aggregates elapsed and mill time per process, so
method-level if you limited the scope to native code on a
POSIX-compliant system? If not, you can be certain they won't
be available in Java.
even for a multi-threaded process you only get process totals. Under UNIX/ Linux the JVM is a multi-threaded process with a single thread handling
user program execution: IIRC it spawns threads to handle garbage
collection and Swing/awt but nothing external to the JVM process will see either these or any user-defined threads that your program may execute.
- multiple, separately forked, processes that access one or more shared
memory modules.
These will look different when looked at by top and similar tools though
use the same basic tools (semaphores, locks, etc).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 286 |
Nodes: | 16 (2 / 14) |
Uptime: | 88:52:47 |
Calls: | 6,496 |
Calls today: | 7 |
Files: | 12,100 |
Messages: | 5,277,436 |