-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc_stat.f90
177 lines (152 loc) · 6.69 KB
/
proc_stat.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
!
! Copyright (c) 2012 Dimitar L Pashov
!
!
! Permission is hereby granted, free of charge, to any person
! obtaining a copy of this software and associated documentation files
! (the "Software"), to deal in the Software without restriction,
! including without limitation the rights to use, copy, modify, merge,
! publish, distribute, sublicense, and/or sell copies of the Software,
! and to permit persons to whom the Software is furnished to do so,
! subject to the following conditions:
!
! The above copyright notice and this permission notice shall be
! included in all copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
! CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
! TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
! SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module mod_proc_stat
! Get process stats from the Linux procfs.
! Needless to say this is only working in Linux and 'could' be useful
! for debugging rather than anything else.
use iso_c_binding, only : c_size_t
implicit none
private
integer, parameter ::lp = 8
type proc_stat
integer(lp) :: pid
character(len=100) :: comm
character :: state
real(lp) :: ppid
real(lp) :: pgrp
real(lp) :: session
real(lp) :: tty_nr
real(lp) :: tpgid
real(lp) :: flags
real(lp) :: minflt
real(lp) :: cminflt
real(lp) :: majflt
real(lp) :: cmajflt
real(lp) :: utime
real(lp) :: stime
real(lp) :: cutime
real(lp) :: cstime
real(lp) :: priority
real(lp) :: nice
real(lp) :: num_threads
real(lp) :: itrealvalue
real(lp) :: starttime
real(lp) :: vsize
real(lp) :: rss
real(lp) :: rsslim
real(lp) :: startcode
real(lp) :: endcode
real(lp) :: startstack
real(lp) :: kstkesp
real(lp) :: kstkeip
real(lp) :: signal
real(lp) :: blocked
real(lp) :: sigignore
real(lp) :: sigcatch
real(lp) :: wchan
real(lp) :: nswap
real(lp) :: cnswap
real(lp) :: exit_signal
real(lp) :: processor
real(lp) :: rt_priority
real(lp) :: policy
real(lp) :: delayacct_blkio_ticks
real(lp) :: guest_time
real(lp) :: cguest_time
end type
public :: proc_stat, read_proc_stat, print_proc_stat
contains
subroutine read_proc_stat(ps)
type(proc_stat), intent(inout) :: ps
integer :: u, ierr
! open(unit=u, file='/proc/self/stat', form='formatted', action='read')
open(newunit=u, file='/proc/self/stat', form='formatted', action='read')
read(u,*) ps%pid, ps%comm, ps%state, ps%ppid, ps%pgrp, ps%session, &
& ps%tty_nr, ps%tpgid, ps%flags, ps%minflt, ps%cminflt, ps%majflt, &
& ps%cmajflt, ps%utime, ps%stime, ps%cutime, ps%cstime, ps%priority, &
& ps%nice, ps%num_threads, ps%itrealvalue, ps%starttime, ps%vsize, ps%rss, &
& ps%rsslim, ps%startcode, ps%endcode, ps%startstack, ps%kstkesp, ps%kstkeip, &
& ps%signal, ps%blocked, ps%sigignore, ps%sigcatch, ps%wchan, ps%nswap, ps%cnswap, &
& ps%exit_signal, ps%processor, ps%rt_priority, ps%policy, ps%delayacct_blkio_ticks, &
& ps%guest_time, ps%cguest_time
close(u)
end subroutine read_proc_stat
subroutine print_proc_stat(u, ps)
integer, intent(in) :: u
type(proc_stat), intent(in) :: ps
write(u,*) 'pid : ', ps%pid
write(u,*) 'comm : ', ps%comm
write(u,*) 'state : ', ps%state
write(u,*) 'ppid : ', ps%ppid
write(u,*) 'pgrp : ', ps%pgrp
write(u,*) 'session : ', ps%session
write(u,*) 'tty_nr : ', ps%tty_nr
write(u,*) 'tpgid : ', ps%tpgid
write(u,*) 'flags : ', ps%flags
write(u,*) 'minflt : ', ps%minflt
write(u,*) 'cminflt : ', ps%cminflt
write(u,*) 'majflt : ', ps%majflt
write(u,*) 'cmajflt : ', ps%cmajflt
write(u,*) 'utime : ', ps%utime
write(u,*) 'stime : ', ps%stime
write(u,*) 'cutime : ', ps%cutime
write(u,*) 'cstime : ', ps%cstime
write(u,*) 'priority : ', ps%priority
write(u,*) 'nice : ', ps%nice
write(u,*) 'num_threads : ', ps%num_threads
write(u,*) 'itrealvalue : ', ps%itrealvalue
write(u,*) 'starttime : ', ps%starttime
write(u,*) 'vsize : ', ps%vsize
write(u,*) 'rss : ', ps%rss
write(u,*) 'rsslim : ', ps%rsslim
write(u,*) 'startcode : ', ps%startcode
write(u,*) 'endcode : ', ps%endcode
write(u,*) 'startstack : ', ps%startstack
write(u,*) 'kstkesp : ', ps%kstkesp
write(u,*) 'kstkeip : ', ps%kstkeip
write(u,*) 'signal : ', ps%signal
write(u,*) 'blocked : ', ps%blocked
write(u,*) 'sigignore : ', ps%sigignore
write(u,*) 'sigcatch : ', ps%sigcatch
write(u,*) 'wchan : ', ps%wchan
write(u,*) 'nswap : ', ps%nswap
write(u,*) 'cnswap : ', ps%cnswap
write(u,*) 'exit_signal : ', ps%exit_signal
write(u,*) 'processor : ', ps%processor
write(u,*) 'rt_priority : ', ps%rt_priority
write(u,*) 'policy : ', ps%policy
write(u,*) 'delayacct_blkio_ticks : ', ps%delayacct_blkio_ticks
write(u,*) 'guest_time : ', ps%guest_time
write(u,*) 'cguest_time : ', ps%cguest_time
end subroutine print_proc_stat
end module mod_proc_stat
!
! program try
! use mod_proc_stat
! implicit none
!
! type(proc_stat) :: ps
! call read_proc_stat(ps)
! call print_proc_stat(6, ps)
!
! end program try