Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending prstat command with timestamp 2

Status
Not open for further replies.

naveenrt

Technical User
Mar 23, 2001
53
0
0
US
Hi
I am trying to run the prstat tool in Solaris to capture merics in production that would tell which PID is using high cpu .Apparently prstat do not have a inbuilt command argument i can pass on which would give me time stamp.So i am thinking of using prstat and then appending timestamp with a wrapper script.
I need help in appending each line of the output of prstat file with a timestamp at the beginning or End of the line

The TIME column indicates how long the process is running since it started

Any help is appreciated

prstat
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
12354 root 29M 28M sleep 29 10 9:23:53 4.2% emx_flist64/1
19708 root 13M 9720K sleep 59 0 0:06:08 0.3% dsmc/5
12892 oracle 2784M 2751M sleep 59 0 0:00:00 0.1% oracle/2
6554 root 18M 18M sleep 24 10 2:25:52 0.1% PatrolAgent/1
12860 oracle 2784M 2752M sleep 59 0 0:00:01 0.1% oracle/2
7456 patrol 7568K 5392K sleep 29 10 1:47:11 0.0% bgscollect/1
2992 root 7416K 6400K sleep 29 10 1:31:19 0.0% stat_daemon/1
 
Try this:

Code:
prstat -c 15 | nawk '$1=="PID" { system("date") } 1'

Annihilannic.
 
Annihilannic
Thanks for the response.The code prints timestamp at the begining of the prstat as shown below. What i was looking for is on every line you see there. The reason i am looking at them there is so that i can sort them by timestamp using excel to check on which process was consuming more mem/CPU during our Test

Wed Dec 16 15:17:20 PST 2009
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
1960 root 32M 26M sleep 29 10 40:47:26 2.3% emx_flist64/1
4111 patrol 24M 23M sleep 29 10 27:19:36 0.4% PatrolAgent/1
4932 oracle 2786M 2745M sleep 59 0 0:32:41 0.1% oracle/2
19223 oracle 2786M 2745M sleep 59 0 0:02:25 0.1% oracle/2
4934 oracle 2786M 2745M sleep 59 0 1:48:44 0.1% oracle/2
4823 oracle 514M 473M sleep 59 0 0:19:40 0.1% oracle/2
4821 oracle 370M 329M sleep 59 0 0:19:20 0.1% oracle/2
881 root 151M 120M sleep 59 0 3:57:23 0.0% EmxWatchdog/42
14855 ecpadm 5552K 4752K cpu0 59 0 0:00:00 0.0% prstat/1
19221 oracle 2787M 2746M sleep 59 0 0:01:25 0.0% oracle/12
5017 oracle 2784M 2749M sleep 59 0 1:02:26 0.0% oracle/2
8821 patrol 16M 11M sleep 59 0 0:00:00 0.0% sqlplus/1
806 root 7456K 7056K sleep 59 0 1:16:42 0.0% picld/11
8822 patrol 2784M 2749M sleep 59 0 0:00:00 0.0% oracle/2
14819 root 6824K 2952K sleep 59 0 0:00:00 0.0% sshd/1
Total: 169 processes, 771 lwps, load averages: 0.23, 0.14, 0.12
 
In that case, this should do it:

Code:
prstat -c 15 | nawk '$1=="PID" { "date" | getline d ; close("date") } { print d,$0 }'

Annihilannic.
 
AnniHalic
Kudos to you.I tried to write using for loop while etc not succesffull. Your one liner has helped me and the User community . I have googled and many of them have asked similar questions however there was no answer.

So I would like to give you 5 Stars ***** however only one star option was provided by Tek-tips


Thank You again
Naveen

Output for reference to others
==============================
$ prstat -c 15 | nawk '$1=="PID" { "date" | getline d ; close("date") } { print d,$0 }'
Thu Dec 17 20:51:54 PST 2009 PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
Thu Dec 17 20:51:54 PST 2009 12354 root 29M 28M sleep 29 10 11:49:52 4.2% emx_flist64/1
Thu Dec 17 20:51:54 PST 2009 600 oracle 2784M 2752M sleep 59 0 0:00:10 0.1% oracle/2
Thu Dec 17 20:51:54 PST 2009 1008 ecpadm 4488K 4336K cpu1 49 0 0:00:00 0.1% prstat/1
Thu Dec 17 20:51:54 PST 2009 915 root 6816K 2896K sleep 59 0 0:00:00 0.1% sshd/1
Thu Dec 17 20:51:54 PST 2009 881 root 155M 124M sleep 59 0 4:45:21 0.1% EmxWatchdog/42
Thu Dec 17 20:51:54 PST 2009 744 oracle 2784M 2751M sleep 59 0 0:00:00 0.0% oracle/2
Thu Dec 17 20:51:54 PST 2009 1009 ecpadm 1296K 1136K sleep 49 0 0:00:00 0.0% nawk/1
Thu Dec 17 20:51:54 PST 2009 21107 oracle 2790M 2744M sleep 59 0 0:06:18 0.0% oracle/2
Thu Dec 17 20:51:54 PST 2009 976 ecpadm 1904K 1440K sleep 39 0 0:00:00 0.0% ksh/1
Thu Dec 17 20:51:54 PST 2009 766 oracle 2784M 2750M sleep 59 0 0:00:00 0.0% oracle/2
Thu Dec 17 20:51:54 PST 2009 3909 root 9304K 8400K sleep 157 - 0:25:05 0.0% had/1
Thu Dec 17 20:51:54 PST 2009 7456 patrol 7568K 5392K sleep 29 10 1:49:13 0.0% bgscollect/1
Thu Dec 17 20:51:54 PST 2009 968 ecpadm 6368K 1920K sleep 59 0 0:00:00 0.0% sshd/1
Thu Dec 17 20:51:54 PST 2009 4250 oracle 18M 8712K sleep 59 0 0:11:25 0.0% tnslsnr/1
Thu Dec 17 20:51:54 PST 2009 994 root 2368K 1608K sleep 59 0 0:00:08 0.0% rpcbind/1
Thu Dec 17 20:51:54 PST 2009 Total: 322 processes, 940 lwps, load averages: 0.22, 0.37, 0.37


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top