sys-proctable 0.9.1-universal-mingw32 → 0.9.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,209 +1,209 @@
1
- require 'win32ole'
2
- require 'socket'
3
- require 'date'
4
-
5
- # The Sys module serves as a namespace only
6
- module Sys
7
-
8
- # The ProcTable class encapsulates process table information
9
- class ProcTable
10
-
11
- # There is no constructor
12
- private_class_method :new
13
-
14
- # Error typically raised if one of the Sys::ProcTable methods fails
15
- class Error < StandardError; end
16
-
17
- # The version of the sys-proctable library
18
- VERSION = '0.9.1'
19
-
20
- # The comm field corresponds to the 'name' field. The 'cmdline' field
21
- # is the CommandLine attribute on Windows XP or later, or the
22
- # 'executable_path' field on Windows 2000 or earlier.
23
- #
24
- @fields = %w[
25
- caption
26
- cmdline
27
- comm
28
- creation_class_name
29
- creation_date
30
- cs_creation_class_name
31
- cs_name
32
- description
33
- executable_path
34
- execution_state
35
- handle
36
- handle_count
37
- install_date
38
- kernel_mode_time
39
- maximum_working_set_size
40
- minimum_working_set_size
41
- name
42
- os_creation_class_name
43
- os_name
44
- other_operation_count
45
- other_transfer_count
46
- page_faults
47
- page_file_usage
48
- ppid
49
- peak_page_file_usage
50
- peak_virtual_size
51
- peak_working_set_size
52
- priority
53
- private_page_count
54
- pid
55
- quota_non_paged_pool_usage
56
- quota_paged_pool_usage
57
- quota_peak_non_paged_pool_usage
58
- quota_peak_paged_pool_usage
59
- read_operation_count
60
- read_transfer_count
61
- session_id
62
- status
63
- termination_date
64
- thread_count
65
- user_mode_time
66
- virtual_size
67
- windows_version
68
- working_set_size
69
- write_operation_count
70
- write_transfer_count
71
- ]
72
-
73
- ProcTableStruct = Struct.new("ProcTableStruct", *@fields)
74
-
75
- # call-seq:
76
- # ProcTable.fields
77
- #
78
- # Returns an array of fields that each ProcTableStruct will contain. This
79
- # may be useful if you want to know in advance what fields are available
80
- # without having to perform at least one read of the /proc table.
81
- #
82
- def self.fields
83
- @fields
84
- end
85
-
86
- # call-seq:
87
- # ProcTable.ps(pid=nil)
88
- # ProcTable.ps(pid=nil){ |ps| ... }
89
- #
90
- # In block form, yields a ProcTableStruct for each process entry that you
91
- # have rights to. This method returns an array of ProcTableStruct's in
92
- # non-block form.
93
- #
94
- # If a +pid+ is provided, then only a single ProcTableStruct is yielded or
95
- # returned, or nil if no process information is found for that +pid+.
96
- #
97
- def self.ps(pid=nil, host=Socket.gethostname)
98
- if pid
99
- raise TypeError unless pid.kind_of?(Fixnum)
100
- end
101
-
102
- array = block_given? ? nil : []
103
- struct = nil
104
-
105
- begin
106
- wmi = WIN32OLE.connect("winmgmts://#{host}/root/cimv2")
107
- rescue WIN32OLERuntimeError => e
108
- raise Error, e # Re-raise as ProcTable::Error
109
- else
110
- wmi.InstancesOf("Win32_Process").each{ |wproc|
111
- if pid
112
- next unless wproc.ProcessId == pid
113
- end
114
-
115
- # Some fields are added later, and so are nil initially
116
- struct = ProcTableStruct.new(
117
- wproc.Caption,
118
- nil, # Added later, based on OS version
119
- wproc.Name,
120
- wproc.CreationClassName,
121
- self.parse_ms_date(wproc.CreationDate),
122
- wproc.CSCreationClassName,
123
- wproc.CSName,
124
- wproc.Description,
125
- wproc.ExecutablePath,
126
- wproc.ExecutionState,
127
- wproc.Handle,
128
- wproc.HandleCount,
129
- self.parse_ms_date(wproc.InstallDate),
130
- self.convert(wproc.KernelModeTime),
131
- wproc.MaximumWorkingSetSize,
132
- wproc.MinimumWorkingSetSize,
133
- wproc.Name,
134
- wproc.OSCreationClassName,
135
- wproc.OSName,
136
- self.convert(wproc.OtherOperationCount),
137
- self.convert(wproc.OtherTransferCount),
138
- wproc.PageFaults,
139
- wproc.PageFileUsage,
140
- wproc.ParentProcessId,
141
- self.convert(wproc.PeakPageFileUsage),
142
- self.convert(wproc.PeakVirtualSize),
143
- self.convert(wproc.PeakWorkingSetSize),
144
- wproc.Priority,
145
- self.convert(wproc.PrivatePageCount),
146
- wproc.ProcessId,
147
- wproc.QuotaNonPagedPoolUsage,
148
- wproc.QuotaPagedPoolUsage,
149
- wproc.QuotaPeakNonPagedPoolUsage,
150
- wproc.QuotaPeakPagedPoolUsage,
151
- self.convert(wproc.ReadOperationCount),
152
- self.convert(wproc.ReadTransferCount),
153
- wproc.SessionId,
154
- wproc.Status,
155
- self.parse_ms_date(wproc.TerminationDate),
156
- wproc.ThreadCount,
157
- self.convert(wproc.UserModeTime),
158
- self.convert(wproc.VirtualSize),
159
- wproc.WindowsVersion,
160
- self.convert(wproc.WorkingSetSize),
161
- self.convert(wproc.WriteOperationCount),
162
- self.convert(wproc.WriteTransferCount)
163
- )
164
-
165
- ###############################################################
166
- # On Windows XP or later, set the cmdline to the CommandLine
167
- # attribute. Otherwise, set it to the ExecutablePath
168
- # attribute.
169
- ###############################################################
170
- if wproc.WindowsVersion.to_f < 5.1
171
- struct.cmdline = wproc.ExecutablePath
172
- else
173
- struct.cmdline = wproc.CommandLine
174
- end
175
-
176
- struct.freeze # This is read-only data
177
-
178
- if block_given?
179
- yield struct
180
- else
181
- array << struct
182
- end
183
- }
184
- end
185
-
186
- pid ? struct : array
187
- end
188
-
189
- private
190
-
191
- #######################################################################
192
- # Converts a string in the format '20040703074625.015625-360' into a
193
- # Ruby Time object.
194
- #######################################################################
195
- def self.parse_ms_date(str)
196
- return if str.nil?
197
- return Date.parse(str.split('.').first)
198
- end
199
-
200
- #####################################################################
201
- # There is a bug in win32ole where uint64 types are returned as a
202
- # String instead of a Fixnum. This method deals with that for now.
203
- #####################################################################
204
- def self.convert(str)
205
- return nil if str.nil? # Return nil, not 0
206
- return str.to_i
207
- end
208
- end
209
- end
1
+ require 'win32ole'
2
+ require 'socket'
3
+ require 'date'
4
+
5
+ # The Sys module serves as a namespace only
6
+ module Sys
7
+
8
+ # The ProcTable class encapsulates process table information
9
+ class ProcTable
10
+
11
+ # There is no constructor
12
+ private_class_method :new
13
+
14
+ # Error typically raised if one of the Sys::ProcTable methods fails
15
+ class Error < StandardError; end
16
+
17
+ # The version of the sys-proctable library
18
+ VERSION = '0.9.2'
19
+
20
+ # The comm field corresponds to the 'name' field. The 'cmdline' field
21
+ # is the CommandLine attribute on Windows XP or later, or the
22
+ # 'executable_path' field on Windows 2000 or earlier.
23
+ #
24
+ @fields = %w[
25
+ caption
26
+ cmdline
27
+ comm
28
+ creation_class_name
29
+ creation_date
30
+ cs_creation_class_name
31
+ cs_name
32
+ description
33
+ executable_path
34
+ execution_state
35
+ handle
36
+ handle_count
37
+ install_date
38
+ kernel_mode_time
39
+ maximum_working_set_size
40
+ minimum_working_set_size
41
+ name
42
+ os_creation_class_name
43
+ os_name
44
+ other_operation_count
45
+ other_transfer_count
46
+ page_faults
47
+ page_file_usage
48
+ ppid
49
+ peak_page_file_usage
50
+ peak_virtual_size
51
+ peak_working_set_size
52
+ priority
53
+ private_page_count
54
+ pid
55
+ quota_non_paged_pool_usage
56
+ quota_paged_pool_usage
57
+ quota_peak_non_paged_pool_usage
58
+ quota_peak_paged_pool_usage
59
+ read_operation_count
60
+ read_transfer_count
61
+ session_id
62
+ status
63
+ termination_date
64
+ thread_count
65
+ user_mode_time
66
+ virtual_size
67
+ windows_version
68
+ working_set_size
69
+ write_operation_count
70
+ write_transfer_count
71
+ ]
72
+
73
+ ProcTableStruct = Struct.new("ProcTableStruct", *@fields)
74
+
75
+ # call-seq:
76
+ # ProcTable.fields
77
+ #
78
+ # Returns an array of fields that each ProcTableStruct will contain. This
79
+ # may be useful if you want to know in advance what fields are available
80
+ # without having to perform at least one read of the /proc table.
81
+ #
82
+ def self.fields
83
+ @fields
84
+ end
85
+
86
+ # call-seq:
87
+ # ProcTable.ps(pid=nil)
88
+ # ProcTable.ps(pid=nil){ |ps| ... }
89
+ #
90
+ # In block form, yields a ProcTableStruct for each process entry that you
91
+ # have rights to. This method returns an array of ProcTableStruct's in
92
+ # non-block form.
93
+ #
94
+ # If a +pid+ is provided, then only a single ProcTableStruct is yielded or
95
+ # returned, or nil if no process information is found for that +pid+.
96
+ #
97
+ def self.ps(pid=nil, host=Socket.gethostname)
98
+ if pid
99
+ raise TypeError unless pid.kind_of?(Fixnum)
100
+ end
101
+
102
+ array = block_given? ? nil : []
103
+ struct = nil
104
+
105
+ begin
106
+ wmi = WIN32OLE.connect("winmgmts://#{host}/root/cimv2")
107
+ rescue WIN32OLERuntimeError => e
108
+ raise Error, e # Re-raise as ProcTable::Error
109
+ else
110
+ wmi.InstancesOf("Win32_Process").each{ |wproc|
111
+ if pid
112
+ next unless wproc.ProcessId == pid
113
+ end
114
+
115
+ # Some fields are added later, and so are nil initially
116
+ struct = ProcTableStruct.new(
117
+ wproc.Caption,
118
+ nil, # Added later, based on OS version
119
+ wproc.Name,
120
+ wproc.CreationClassName,
121
+ self.parse_ms_date(wproc.CreationDate),
122
+ wproc.CSCreationClassName,
123
+ wproc.CSName,
124
+ wproc.Description,
125
+ wproc.ExecutablePath,
126
+ wproc.ExecutionState,
127
+ wproc.Handle,
128
+ wproc.HandleCount,
129
+ self.parse_ms_date(wproc.InstallDate),
130
+ self.convert(wproc.KernelModeTime),
131
+ wproc.MaximumWorkingSetSize,
132
+ wproc.MinimumWorkingSetSize,
133
+ wproc.Name,
134
+ wproc.OSCreationClassName,
135
+ wproc.OSName,
136
+ self.convert(wproc.OtherOperationCount),
137
+ self.convert(wproc.OtherTransferCount),
138
+ wproc.PageFaults,
139
+ wproc.PageFileUsage,
140
+ wproc.ParentProcessId,
141
+ self.convert(wproc.PeakPageFileUsage),
142
+ self.convert(wproc.PeakVirtualSize),
143
+ self.convert(wproc.PeakWorkingSetSize),
144
+ wproc.Priority,
145
+ self.convert(wproc.PrivatePageCount),
146
+ wproc.ProcessId,
147
+ wproc.QuotaNonPagedPoolUsage,
148
+ wproc.QuotaPagedPoolUsage,
149
+ wproc.QuotaPeakNonPagedPoolUsage,
150
+ wproc.QuotaPeakPagedPoolUsage,
151
+ self.convert(wproc.ReadOperationCount),
152
+ self.convert(wproc.ReadTransferCount),
153
+ wproc.SessionId,
154
+ wproc.Status,
155
+ self.parse_ms_date(wproc.TerminationDate),
156
+ wproc.ThreadCount,
157
+ self.convert(wproc.UserModeTime),
158
+ self.convert(wproc.VirtualSize),
159
+ wproc.WindowsVersion,
160
+ self.convert(wproc.WorkingSetSize),
161
+ self.convert(wproc.WriteOperationCount),
162
+ self.convert(wproc.WriteTransferCount)
163
+ )
164
+
165
+ ###############################################################
166
+ # On Windows XP or later, set the cmdline to the CommandLine
167
+ # attribute. Otherwise, set it to the ExecutablePath
168
+ # attribute.
169
+ ###############################################################
170
+ if wproc.WindowsVersion.to_f < 5.1
171
+ struct.cmdline = wproc.ExecutablePath
172
+ else
173
+ struct.cmdline = wproc.CommandLine
174
+ end
175
+
176
+ struct.freeze # This is read-only data
177
+
178
+ if block_given?
179
+ yield struct
180
+ else
181
+ array << struct
182
+ end
183
+ }
184
+ end
185
+
186
+ pid ? struct : array
187
+ end
188
+
189
+ private
190
+
191
+ #######################################################################
192
+ # Converts a string in the format '20040703074625.015625-360' into a
193
+ # Ruby Time object.
194
+ #######################################################################
195
+ def self.parse_ms_date(str)
196
+ return if str.nil?
197
+ return DateTime.parse(str)
198
+ end
199
+
200
+ #####################################################################
201
+ # There is a bug in win32ole where uint64 types are returned as a
202
+ # String instead of a Fixnum. This method deals with that for now.
203
+ #####################################################################
204
+ def self.convert(str)
205
+ return nil if str.nil? # Return nil, not 0
206
+ return str.to_i
207
+ end
208
+ end
209
+ end
@@ -1,39 +1,38 @@
1
- require 'rubygems'
2
- require 'rbconfig'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = 'sys-proctable'
6
- spec.version = '0.9.1'
7
- spec.author = 'Daniel J. Berger'
8
- spec.license = 'Artistic 2.0'
9
- spec.email = 'djberg96@gmail.com'
10
- spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
11
- spec.platform = Gem::Platform::CURRENT # Probably altered by Rake task
12
- spec.summary = 'An interface for providing process table information'
13
- spec.test_files = ['test/test_sys_proctable_all.rb']
14
-
15
- # Additional files for your platform are added by the 'rake gem' task.
16
- spec.files = [
17
- 'benchmarks/bench_ps.rb',
18
- 'examples/example_ps.rb',
19
- 'lib/sys/top.rb',
20
- 'CHANGES',
21
- 'MANIFEST',
22
- 'Rakefile',
23
- 'README',
24
- 'sys-proctable.gemspec'
25
- ]
26
-
27
- spec.rubyforge_project = 'sysutils'
28
- spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
29
-
30
- spec.add_development_dependency('test-unit', '>= 2.1.2')
31
-
32
- spec.description = <<-EOF
33
- The sys-proctable library provides an interface for gathering information
34
- about processes on your system, i.e. the process table. Most major
35
- platforms are supported and, while different platforms may return
36
- different information, the external interface is identical across
37
- platforms.
38
- EOF
39
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sys-proctable'
5
+ spec.version = '0.9.2'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
10
+ spec.platform = Gem::Platform::CURRENT # Probably altered by Rake task
11
+ spec.summary = 'An interface for providing process table information'
12
+ spec.test_files = ['test/test_sys_proctable_all.rb']
13
+
14
+ # Additional files for your platform are added by the 'rake gem' task.
15
+ spec.files = [
16
+ 'benchmarks/bench_ps.rb',
17
+ 'examples/example_ps.rb',
18
+ 'lib/sys/top.rb',
19
+ 'CHANGES',
20
+ 'MANIFEST',
21
+ 'Rakefile',
22
+ 'README',
23
+ 'sys-proctable.gemspec'
24
+ ]
25
+
26
+ spec.rubyforge_project = 'sysutils'
27
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
28
+
29
+ spec.add_development_dependency('test-unit', '>= 2.4.0')
30
+
31
+ spec.description = <<-EOF
32
+ The sys-proctable library provides an interface for gathering information
33
+ about processes on your system, i.e. the process table. Most major
34
+ platforms are supported and, while different platforms may return
35
+ different information, the external interface is identical across
36
+ platforms.
37
+ EOF
38
+ end