solaris-kstat 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.3 - 23-Jul-2007
2
+ * KstatError is now Kstat::Error.
3
+ * Documentation improvements and updates.
4
+ * Added a Rakefile with tasks for installation and testing.
5
+ * Added a dir_config('kstat') to the extconf.rb file in case you should need it.
6
+ * Internal project layout and code cleanup changes that you don't care about.
7
+
1
8
  == 0.2.2 - 10-Jul-2006
2
9
  * Updated the gemspec (and put a gem out on RubyForge).
3
10
 
data/MANIFEST CHANGED
@@ -1,12 +1,10 @@
1
- CHANGES
2
- MANIFEST
3
- README
4
- extconf.rb
5
- solaris-kstat.gemspec
6
-
7
- examples/test.rb
8
-
9
- lib/solaris/rkstat.c
10
- lib/solaris/rkstat.h
11
-
12
- test/tc_kstat.rb
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * solaris-kstat.gemspec
6
+ * examples/test.rb
7
+ * ext/extconf.rb
8
+ * ext/solaris/rkstat.c
9
+ * ext/solaris/rkstat.h
10
+ * test/tc_kstat.rb
data/README CHANGED
@@ -2,14 +2,17 @@
2
2
  Ruby extension for the Solaris kstat library.
3
3
 
4
4
  == Prerequisites
5
- Solaris 8 or later.
5
+ Solaris 8 (2.8) or later.
6
6
  Ruby 1.8.x
7
7
 
8
8
  == Installation
9
- ruby extconf.rb
10
- make
11
- ruby test/tc_kstat.rb (optional)
12
- make site-install
9
+ === Manual Installation
10
+ rake test (optional)
11
+ rake install
12
+
13
+ === Gem Installation
14
+ rake test (optional)
15
+ rake install_gem
13
16
 
14
17
  == Synopsis
15
18
  require "solaris/kstat"
@@ -48,7 +51,7 @@ Kstat#record
48
51
  The more specific your criterion, the less data you will receive.
49
52
 
50
53
  == Error Classes
51
- KstatError < StandardError
54
+ Kstat::Error < StandardError
52
55
  Raised if anything goes wrong. Typically, this will only occur if you
53
56
  pass bad arguments to the constructor (e.g. a module name that doesn't
54
57
  exist, etc).
@@ -68,8 +71,9 @@ KstatError < StandardError
68
71
  I have noticed that results from the cpu_stat module differ from the output
69
72
  of the 'kstat' command line tool. I am convinced that my code is correct and
70
73
  that there is a bug in the Solaris::Kstat Perl module. Unfortunately, the
71
- source for the version of Solaris::Kstat that works on Solaris 8 and later is
72
- not available (the version on CPAN only works on Solaris 6 and 7).
74
+ source for the version of the Solaris::Kstat Perl module that works on
75
+ Solaris 8 and later is not available (the version on CPAN only works on
76
+ Solaris 6 and 7).
73
77
 
74
78
  See http://tinyurl.com/karxw for more details.
75
79
 
@@ -77,13 +81,13 @@ KstatError < StandardError
77
81
  Thanks go to Charlie Mills for help with the 'volatile' issue.
78
82
 
79
83
  == Future Plans
80
- Eliminate warnings that occur during the build process.
84
+ Eliminate warnings that occur during the build process, if possible.
81
85
 
82
86
  == License
83
87
  Ruby's
84
88
 
85
89
  == Copyright
86
- (C) 2003-2006 Daniel J. Berger
90
+ (C) 2003-2007 Daniel J. Berger
87
91
  All Rights Reserved
88
92
 
89
93
  == Warranty
@@ -93,7 +97,7 @@ KstatError < StandardError
93
97
 
94
98
  == Author
95
99
  Daniel J. Berger
96
- djberg96 at gmail dot com
100
+ djberg96 at nospam at gmail dot com
97
101
  imperator on IRC (freenode)
98
102
 
99
103
  == See Also
@@ -0,0 +1,16 @@
1
+ require 'mkmf'
2
+ require 'fileutils'
3
+
4
+ dir_config('kstat')
5
+
6
+ FileUtils.cp('solaris/rkstat.c', '.')
7
+ FileUtils.cp('solaris/rkstat.h', '.')
8
+
9
+ # This package requires Solaris 2.8 or later
10
+ unless have_header('kstat.h')
11
+ STDERR.puts "The kstat.h header file was not found. Exiting."
12
+ exit
13
+ end
14
+
15
+ have_library('kstat')
16
+ create_makefile('solaris/kstat')
@@ -21,15 +21,15 @@ VALUE cKstatError;
21
21
 
22
22
  static VALUE ks_allocate(VALUE klass){
23
23
  KstatStruct* ptr;
24
- return Data_Make_Struct(klass,KstatStruct,0,ks_free,ptr);
24
+ return Data_Make_Struct(klass, KstatStruct, 0, ks_free, ptr);
25
25
  }
26
26
 
27
27
  /*
28
28
  * call-seq:
29
29
  * Kstat.new(module=nil, instance=-1, name=nil)
30
30
  *
31
- * Creates and returns a Kstat object. This does not traverse the kstat
32
- * chain. The Kstat#record method uses the values passed to actually
31
+ * Creates and returns a Kstat object. This does NOT traverse the kstat
32
+ * chain. The Kstat#record method uses the values passed to actually
33
33
  * retrieve data.
34
34
  *
35
35
  * You may specify a module, an instance and a name. The module defaults to
@@ -38,24 +38,24 @@ static VALUE ks_allocate(VALUE klass){
38
38
  */
39
39
  VALUE ks_init(int argc, VALUE* argv, VALUE self){
40
40
  KstatStruct* ptr;
41
- VALUE rbModule, rbInstance, rbName;
41
+ VALUE v_module, v_instance, v_name;
42
42
 
43
43
  Data_Get_Struct(self,KstatStruct,ptr);
44
44
 
45
- rb_scan_args(argc,argv,"03",&rbModule,&rbInstance,&rbName);
45
+ rb_scan_args(argc, argv, "03", &v_module, &v_instance, &v_name);
46
46
 
47
- if(!NIL_P(rbModule)){
48
- SafeStringValue(rbModule);
49
- rb_iv_set(self,"@module",rbModule);
47
+ if(!NIL_P(v_module)){
48
+ SafeStringValue(v_module);
49
+ rb_iv_set(self, "@module", v_module);
50
50
  }
51
51
 
52
- if(!NIL_P(rbName)){
53
- SafeStringValue(rbName);
54
- rb_iv_set(self,"@name",rbName);
52
+ if(!NIL_P(v_name)){
53
+ SafeStringValue(v_name);
54
+ rb_iv_set(self, "@name", v_name);
55
55
  }
56
56
 
57
- if(!NIL_P(rbInstance))
58
- rb_iv_set(self,"@instance",rbInstance);
57
+ if(!NIL_P(v_instance))
58
+ rb_iv_set(self, "@instance", v_instance);
59
59
 
60
60
  return self;
61
61
  }
@@ -66,7 +66,7 @@ VALUE ks_init(int argc, VALUE* argv, VALUE self){
66
66
  * The more specific your criterion, the less data you will receive.
67
67
  */
68
68
  VALUE ks_record(VALUE self){
69
- volatile VALUE rbMHash, rbIHash, rbNHash, rbSHash;
69
+ volatile VALUE v_m_hash, v_i_hash, v_n_hash, v_s_hash;
70
70
  KstatStruct* ptr;
71
71
  kstat_io_t kio;
72
72
  kstat_timer_t kt;
@@ -75,38 +75,33 @@ VALUE ks_record(VALUE self){
75
75
  char* name;
76
76
  int instance = -1; /* -1 represents all instances (the default) */
77
77
 
78
- VALUE rbModule, rbInstance, rbName;
78
+ VALUE v_module, v_instance, v_name;
79
79
 
80
80
  Data_Get_Struct(self,KstatStruct,ptr);
81
81
 
82
- rbMHash = rb_hash_new(); /* Module name is key, holds rbIHashes */
83
- rbIHash = rb_hash_new(); /* Instance name is key, holds rbNHashes */
84
- rbNHash = rb_hash_new(); /* Name is key, holds rbSHashes */
82
+ v_m_hash = rb_hash_new(); /* Module name is key, holds v_i_hashes */
83
+ v_i_hash = rb_hash_new(); /* Instance name is key, holds v_n_hashes */
84
+ v_n_hash = rb_hash_new(); /* Name is key, holds v_s_hashes */
85
85
 
86
- rbModule = rb_iv_get(self,"@module");
87
- rbInstance = rb_iv_get(self,"@instance");
88
- rbName = rb_iv_get(self,"@name");
86
+ v_module = rb_iv_get(self, "@module");
87
+ v_instance = rb_iv_get(self, "@instance");
88
+ v_name = rb_iv_get(self, "@name");
89
89
 
90
90
  /* Module is NULL by default (i.e. all modules are returned) */
91
- if(NIL_P(rbModule)){
91
+ if(NIL_P(v_module))
92
92
  module = NULL;
93
- }
94
- else{
95
- module = StringValuePtr(rbModule);
96
- }
93
+ else
94
+ module = StringValuePtr(v_module);
97
95
 
98
96
  /* Instance defaults to -1 (i.e. all instances are returned) */
99
- if(!NIL_P(rbInstance)){
100
- instance = NUM2INT(rbInstance);
101
- }
97
+ if(!NIL_P(v_instance))
98
+ instance = NUM2INT(v_instance);
102
99
 
103
100
  /* Name is NULL by default (i.e. all names are returned) */
104
- if(NIL_P(rbName)){
101
+ if(NIL_P(v_name))
105
102
  name = NULL;
106
- }
107
- else{
108
- name = StringValuePtr(rbName);
109
- }
103
+ else
104
+ name = StringValuePtr(v_name);
110
105
 
111
106
  /* A failure probably means the module, instance or name doesn't exist */
112
107
  if((ptr->kc = kstat_open()) == NULL)
@@ -145,62 +140,67 @@ VALUE ks_record(VALUE self){
145
140
  /* Call the appropriate data mapper based on ks_type */
146
141
  switch(ptr->ksp->ks_type){
147
142
  case KSTAT_TYPE_NAMED:
148
- kstat_read(ptr->kc,ptr->ksp,NULL);
149
- rbSHash = map_named_data_type(ptr->ksp);
143
+ kstat_read(ptr->kc, ptr->ksp, NULL);
144
+ v_s_hash = map_named_data_type(ptr->ksp);
150
145
  break;
151
146
  case KSTAT_TYPE_IO:
152
- kstat_read(ptr->kc,ptr->ksp,&kio);
153
- rbSHash = map_io_data_type(&kio);
147
+ kstat_read(ptr->kc, ptr->ksp, &kio);
148
+ v_s_hash = map_io_data_type(&kio);
154
149
  break;
155
150
  case KSTAT_TYPE_TIMER:
156
- kstat_read(ptr->kc,ptr->ksp,&kt);
157
- rbSHash = map_timer_data_type(&kt);
151
+ kstat_read(ptr->kc, ptr->ksp, &kt);
152
+ v_s_hash = map_timer_data_type(&kt);
158
153
  case KSTAT_TYPE_INTR:
159
- kstat_read(ptr->kc,ptr->ksp,NULL);
160
- rbSHash = map_intr_data_type(ptr->ksp);
154
+ kstat_read(ptr->kc, ptr->ksp, NULL);
155
+ v_s_hash = map_intr_data_type(ptr->ksp);
161
156
  break;
162
157
  case KSTAT_TYPE_RAW:
163
- kstat_read(ptr->kc,ptr->ksp,NULL);
164
- rbSHash = map_raw_data_type(ptr->ksp);
158
+ kstat_read(ptr->kc, ptr->ksp, NULL);
159
+ v_s_hash = map_raw_data_type(ptr->ksp);
165
160
  break;
166
161
  default:
167
162
  rb_raise(cKstatError,"Unknown data record type");
168
163
  }
169
164
 
170
- rb_hash_aset(rbNHash,rb_str_new2(ptr->ksp->ks_name),rbSHash);
171
- rb_hash_aset(rbIHash,INT2FIX(ptr->ksp->ks_instance), rbNHash);
172
- rb_hash_aset(rbMHash,rb_str_new2(ptr->ksp->ks_module),rbIHash);
165
+ rb_hash_aset(v_n_hash, rb_str_new2(ptr->ksp->ks_name), v_s_hash);
166
+ rb_hash_aset(v_i_hash, INT2FIX(ptr->ksp->ks_instance), v_n_hash);
167
+ rb_hash_aset(v_m_hash, rb_str_new2(ptr->ksp->ks_module), v_i_hash);
173
168
 
174
169
  ptr->ksp = ptr->ksp->ks_next;
175
170
  }
176
171
 
177
- return rbMHash;
172
+ return v_m_hash;
178
173
  }
179
174
 
180
- /*
181
- * Interface for Solaris kstat data.
182
- */
183
175
  void Init_kstat(){
184
176
  VALUE mSolaris, cKstat;
185
177
 
186
- /* Module and Class declarations */
187
- mSolaris = rb_define_module("Solaris");
188
- cKstat = rb_define_class_under(mSolaris,"Kstat",rb_cObject);
189
- cKstatError = rb_define_class_under(mSolaris,"KstatError",rb_eStandardError);
178
+ /* The Solaris module only serves as a toplevel namespace */
179
+ mSolaris = rb_define_module("Solaris");
180
+
181
+ /* The Kstat class encapsulates kstat (kernel statistics) information */
182
+ cKstat = rb_define_class_under(mSolaris, "Kstat", rb_cObject);
183
+
184
+ /* The Kstat::Error class is raised if any of the Kstat methods fail */
185
+ cKstatError = rb_define_class_under(cKstat, "Error", rb_eStandardError);
190
186
 
191
- rb_define_alloc_func(cKstat,ks_allocate);
187
+ rb_define_alloc_func(cKstat, ks_allocate);
192
188
 
193
189
  /* Instance Methods */
194
- rb_define_method(cKstat,"initialize",ks_init,-1);
195
- rb_define_method(cKstat,"record",ks_record,0);
190
+ rb_define_method(cKstat, "initialize", ks_init, -1);
191
+ rb_define_method(cKstat, "record", ks_record, 0);
192
+
193
+ /* Kernel module */
194
+ rb_define_attr(cKstat, "module", 1, 1);
195
+
196
+ /* Index of module entity */
197
+ rb_define_attr(cKstat, "instance", 1, 1);
196
198
 
197
- /* Attributes */
198
- rb_define_attr(cKstat,"module",1,1);
199
- rb_define_attr(cKstat,"instance",1,1);
200
- rb_define_attr(cKstat,"name",1,1);
199
+ /* Unique name within module */
200
+ rb_define_attr(cKstat, "name", 1, 1);
201
201
 
202
- /* Constants */
203
- rb_define_const(cKstat,"VERSION",rb_str_new2(SOLARIS_KSTAT_VERSION));
202
+ /* 0.2.3: The version of this package, returned as a String */
203
+ rb_define_const(cKstat, "VERSION", rb_str_new2(SOLARIS_KSTAT_VERSION));
204
204
  }
205
205
 
206
206
  #ifdef __cplusplus
@@ -2,7 +2,7 @@
2
2
  extern "C" {
3
3
  #endif
4
4
 
5
- #define SOLARIS_KSTAT_VERSION "0.2.2"
5
+ #define SOLARIS_KSTAT_VERSION "0.2.3"
6
6
 
7
7
  /* Function prototypes */
8
8
  static VALUE map_named_data_type(kstat_t* ksp);
@@ -1,17 +1,9 @@
1
1
  ###############################################################################
2
2
  # tc_kstat.rb
3
3
  #
4
- # Test suite for the solaris-kstat Ruby package.
4
+ # Test suite for the solaris-kstat Ruby package. You should run this via
5
+ # the 'rake test' task.
5
6
  ###############################################################################
6
- base = File.basename(Dir.pwd)
7
- if base == "test" || base =~ /solaris-kstat.*/
8
- require "ftools"
9
- Dir.chdir("..") if base == "test"
10
- Dir.mkdir("solaris") unless File.exists?("solaris")
11
- File.copy("kstat.so","solaris")
12
- $LOAD_PATH.unshift Dir.pwd
13
- end
14
-
15
7
  require "solaris/kstat"
16
8
  require "test/unit"
17
9
  require "set"
@@ -23,7 +15,7 @@ class TC_Kstat < Test::Unit::TestCase
23
15
  end
24
16
 
25
17
  def test_version
26
- assert_equal("0.2.2", Kstat::VERSION)
18
+ assert_equal("0.2.3", Kstat::VERSION)
27
19
  end
28
20
 
29
21
  def test_name
@@ -57,9 +49,9 @@ class TC_Kstat < Test::Unit::TestCase
57
49
  end
58
50
 
59
51
  def test_constructor_invalid_values
60
- assert_raises(KstatError){ Kstat.new("bogus").record }
61
- assert_raises(KstatError){ Kstat.new("cpu_info",99).record }
62
- assert_raises(KstatError){ Kstat.new("cpu_info",0,"bogus").record }
52
+ assert_raises(Kstat::Error){ Kstat.new("bogus").record }
53
+ assert_raises(Kstat::Error){ Kstat.new("cpu_info",99).record }
54
+ assert_raises(Kstat::Error){ Kstat.new("cpu_info",0,"bogus").record }
63
55
  assert_raises(TypeError){ Kstat.new("cpu_info","x").record }
64
56
  end
65
57
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: solaris-kstat
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.2
7
- date: 2006-07-11 00:00:00 -06:00
6
+ version: 0.2.3
7
+ date: 2007-07-24 00:00:00 -06:00
8
8
  summary: Interface for the Solaris kstat library
9
9
  require_paths:
10
10
  - lib
@@ -29,14 +29,15 @@ post_install_message:
29
29
  authors:
30
30
  - Daniel J. Berger
31
31
  files:
32
- - CHANGES
33
- - README
34
- - MANIFEST
35
- - extconf.rb
36
- - lib/solaris/rkstat.c
37
- - lib/solaris/rkstat.h
32
+ - ext/extconf.rb
33
+ - ext/solaris
34
+ - ext/solaris/rkstat.c
35
+ - ext/solaris/rkstat.h
38
36
  - test/tc_kstat.rb
39
37
  - examples/test.rb
38
+ - README
39
+ - CHANGES
40
+ - MANIFEST
40
41
  test_files:
41
42
  - test/tc_kstat.rb
42
43
  rdoc_options: []
@@ -44,10 +45,12 @@ rdoc_options: []
44
45
  extra_rdoc_files:
45
46
  - README
46
47
  - CHANGES
48
+ - MANIFEST
49
+ - ext/solaris/rkstat.c
47
50
  executables: []
48
51
 
49
52
  extensions:
50
- - extconf.rb
53
+ - ext/extconf.rb
51
54
  requirements: []
52
55
 
53
56
  dependencies: []
data/extconf.rb DELETED
@@ -1,14 +0,0 @@
1
- require "mkmf"
2
- require "ftools"
3
-
4
- File.copy("lib/solaris/rkstat.c",".")
5
- File.copy("lib/solaris/rkstat.h",".")
6
-
7
- # This package requires Solaris 2.8 or later
8
- unless have_header("kstat.h")
9
- STDERR.puts "The kstat.h header file was not found. Exiting."
10
- exit
11
- end
12
-
13
- have_library("kstat")
14
- create_makefile("solaris/kstat")