mincore 0.0.9.pre → 0.0.9.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.yardopts +7 -0
  4. data/README.md +56 -5
  5. data/lib/mincore.rb +24 -21
  6. data/mincore.gemspec +2 -2
  7. metadata +48 -71
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19f2d12d2696de6c950623e5de70a1f3263d99d4
4
+ data.tar.gz: 1e99083d29131d7fc9e224f98dfe4ada3970ddc1
5
+ SHA512:
6
+ metadata.gz: 55ef0831de1e5288af669766f250af6a04ef6ac224c688c1faae2d7e2936669c43b6b01e789a64689fa96c70e465f705423457d9197aba5cddf80b5c6cbf5dc3
7
+ data.tar.gz: 83cb92caf55e88c4d8d7bc0b3ad4e0ce7a44faa4bfc4a99fa372df82dcc26957b7547ca43e4e9a7f90d7b7f00a91d5bcfb40da50a5c126dc332df23cf92ca6ba
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ scratch
3
3
  *.gem
4
4
  Gemfile.lock
5
5
  gems/
6
+ .yardoc/
7
+ doc/
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --main README.md
2
+ --markup markdown
3
+ -
4
+ CHANGELOG.md
5
+ CONTRIBUTING.md
6
+ LICENSE.md
7
+ README.md
data/README.md CHANGED
@@ -1,19 +1,60 @@
1
- ruby-mincore
2
- ============
1
+ ruby-mincore - Ruby bindings for Linux cache manipulation
2
+ =========================================================
3
3
  [![Gem Version](https://badge.fury.io/rb/mincore.png)](http://badge.fury.io/rb/mincore)
4
- [![Build Status](https://travis-ci.org/noushi/ruby-mincore.png?branch=master)](https://travis-ci.org/noushi/ruby-mincore)
4
+ |
5
+ [![Build Status](https://travis-ci.org/noushi/ruby-mincore.png)](https://travis-ci.org/noushi/ruby-mincore)
6
+ |
5
7
  [![Code Climate](https://codeclimate.com/github/noushi/ruby-mincore.png)](https://codeclimate.com/github/noushi/ruby-mincore)
8
+ |
6
9
  [![Dependency Status](https://gemnasium.com/noushi/ruby-mincore.png)](https://gemnasium.com/noushi/ruby-mincore)
7
10
 
8
- Ruby bindings for Linux cache manipulation.
11
+ `mincore` provides Ruby bindings for Linux cache manipulation, including cache inspection and deletion for a specific file.
9
12
 
10
13
  This project is heavily inspired from [Feh/nocache](http://github.com/Feh/nocache).
11
14
 
15
+ Usage
16
+ =====
17
+
18
+ Currently, `mincore` features are implemented as class methods:
19
+
20
+ size=File.PAGESIZE
21
+ # 4096
22
+
23
+ File.open("/path/to/file").numpages #The only instance method
24
+ # 5
25
+
26
+ File.mincore("/path/to/file")
27
+ # [true, true, false, false, true]
28
+
29
+ File.cachedel("/path/to/file")
30
+ # 0
31
+
32
+ File.mincore("/path/to/file")
33
+ # [true, true, false, false, true]
34
+
35
+ File.cachedel("/path/to/file", 2)
36
+ # 0
37
+
38
+ File.mincore("/path/to/file")
39
+ # [true, true, false, false, true]
40
+
41
+ File.cachedel("/path/to/file", 2)
42
+ # 0
43
+
44
+ File.mincore("/path/to/file")
45
+ # [false, false, false, false, false]
46
+
47
+ This is an illustration of the fact that `cachedel` may or may not actually purge cached pages even if run multiple times (through the second parameter).
48
+
49
+ Full documentation available in the source code ^H^H, [Ruby Doc](http://rubydoc.info/gems/mincore/File).
50
+
51
+
12
52
 
13
53
  Status & Limitations
14
54
  ====================
15
55
 
16
56
  Currently, the File class is extended as such:
57
+
17
58
  - `mincore(filename)` is exported to Ruby in the form of an array of booleans corresponding to each page of the file.
18
59
  - `cachedel(filename, count=1)` calls `posix_fadvise(2)` to purge all file pages from the cache
19
60
  - `PAGESIZE` is a simple helper that returns the value of PAGESIZE (4KB on Intel)
@@ -22,9 +63,19 @@ The bindings are implemented using Ruby Inline, instead of the classic mkmf ext
22
63
 
23
64
  There is a gem module generated, and the code is still beta.
24
65
 
25
- Since `File.cachedel()` isn't guaranteed to work (no matter how many time you call it), the `test_cachedel_non_empty_file` most always succeeds without properly asserting that `posix_fadvise()` has worked.
66
+ Since `File.cachedel()` isn't guaranteed to work (no matter how many time you call it), the `test_cachedel_non_empty_file` most always succeeds without properly asserting that `posix_fadvise()` has worked.
26
67
 
27
68
  Also, the tests use a `./writable_tmp_dir/` directory to store the temporary test files. `/tmp` can't be used since it's
28
69
  usually a ramfs, and files will always be in cache, until they're deleted.
29
70
 
30
71
 
72
+
73
+ Contributing
74
+ ============
75
+ Contributions are most welcome, you know the drill:
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (git checkout -b my-new-feature)
79
+ 3. Commit your changes (git commit -am 'Add some feature')
80
+ 4. Push to the branch (git push origin my-new-feature)
81
+ 5. Create new Pull Request
data/lib/mincore.rb CHANGED
@@ -2,6 +2,7 @@ require 'inline'
2
2
 
3
3
  # The File mincore extension
4
4
  class File
5
+ private
5
6
  def self._common_code(builder)
6
7
  builder.include("<stdio.h>")
7
8
  builder.include("<stdlib.h>")
@@ -17,7 +18,6 @@ class File
17
18
  builder.prefix("#define exiterr(s) { perror(s); exit(-1); }")
18
19
  end
19
20
 
20
-
21
21
  inline do |builder|
22
22
  builder.include("<unistd.h>")
23
23
  builder.c_raw_singleton "
@@ -141,7 +141,13 @@ static VALUE _cachedel(char *filename, int count) {
141
141
  C_CODE
142
142
  end
143
143
 
144
+ public
145
+
144
146
  # Returns the number of system pages required to store file in memory
147
+ # @example Sample run - on a file of size 20KB
148
+ # File.open("/path/to/some/file").numpages #=> 5
149
+ #
150
+ # @return [Int] number of cacheable pages
145
151
  def numpages
146
152
  pagesize = self.class.PAGESIZE
147
153
  (self.stat.size + pagesize -1 ) / pagesize
@@ -150,14 +156,12 @@ C_CODE
150
156
 
151
157
  # Attempts to delete cached pages of a file, one or more times
152
158
  #
153
- # Example:
154
- # >> File.cachedel("/path/to/useless/file", 2)
155
- # => 0
159
+ # @example Sample run - file pages would or would not get flushed
160
+ # File.cachedel("/path/to/useless/file", 2) #=> 0
156
161
  #
157
- # Arguments:
158
- # filename: (String)
159
- # count: (Int)
160
- #
162
+ # @param filename [String] file name
163
+ # @param count [Int] times `posix_fadvise()` will be run
164
+ # @return [Int] execution status
161
165
  def self.cachedel(filename, count=1)
162
166
  self._cachedel(filename, count)
163
167
  end
@@ -166,22 +170,21 @@ C_CODE
166
170
  # Status is provided as a boolean array of size
167
171
  # ( filesize + PAGESIZE -1 ) / PAGESIZE
168
172
  #
169
- # Example:
170
- # >> File.mincore("/path/to/important/file")
171
- # => [true, true, true....]
172
- #
173
- # Arguments:
174
- # filename: (String)
175
- #
176
- def self.mincore(*args)
177
- self._mincore(*args)
173
+ # @example Sample run - on a file of size 20KB
174
+ # File.mincore("/path/to/important/file") #=> [true, true, true, false, false]
175
+ #
176
+ # @param filename [String] file name
177
+ # @return [Int] execution status
178
+ def self.mincore(filename)
179
+ self._mincore(filename)
178
180
  end
179
181
 
180
- # get system pagesize (4096 on Intel)
182
+ # get system page size (4096 on Intel)
181
183
  #
182
- # Example:
183
- # >> File.PAGESIZE
184
- # => 4096
184
+ # @example - On Intel machine
185
+ # File.PAGESIZE #=> 4096
186
+ #
187
+ # @return [Int] the page size
185
188
  def self.PAGESIZE
186
189
  self._PAGESIZE
187
190
  end
data/mincore.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mincore'
3
- s.version = '0.0.9.pre'
3
+ s.version = '0.0.9.1.pre'
4
4
  s.date = '2013-11-10'
5
5
 
6
6
  s.homepage = 'http://github.com/noushi/ruby-mincore'
7
7
  s.summary = "Ruby bindings for Linux cache manipulation"
8
8
  s.description = <<-DESC
9
- micore provides Ruby bindings for Linux cache manipulation,
9
+ mincore provides Ruby bindings for Linux cache manipulation,
10
10
  including cache inspection and deletion for a specific file.
11
11
  DESC
12
12
  s.license = 'GPL-2'
metadata CHANGED
@@ -1,66 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mincore
3
- version: !ruby/object:Gem::Version
4
- hash: -2045603333
5
- prerelease: 6
6
- segments:
7
- - 0
8
- - 0
9
- - 9
10
- - pre
11
- version: 0.0.9.pre
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9.1.pre
12
5
  platform: ruby
13
- authors:
6
+ authors:
14
7
  - Reda NOUSHI
15
8
  autorequire:
16
9
  bindir: bin
17
10
  cert_chain: []
18
-
19
- date: 2013-11-10 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2013-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: RubyInline
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 45
30
- segments:
31
- - 3
32
- - 10
33
- - 1
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
34
19
  version: 3.10.1
35
20
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: RubyInline
39
21
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 45
46
- segments:
47
- - 3
48
- - 10
49
- - 1
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.10.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: RubyInline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
50
33
  version: 3.10.1
51
34
  type: :development
52
- version_requirements: *id002
53
- description: " micore provides Ruby bindings for Linux cache manipulation, \n including cache inspection and deletion for a specific file.\n"
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.10.1
41
+ description: " mincore provides Ruby bindings for Linux cache manipulation, \n
42
+ \ including cache inspection and deletion for a specific file.\n"
54
43
  email: reda_noushi@yahoo.com
55
44
  executables: []
56
-
57
45
  extensions: []
58
-
59
46
  extra_rdoc_files: []
60
-
61
- files:
47
+ files:
62
48
  - .gitignore
63
49
  - .travis.yml
50
+ - .yardopts
64
51
  - Gemfile
65
52
  - README.md
66
53
  - Rakefile
@@ -72,41 +59,31 @@ files:
72
59
  - test/test_helper.rb
73
60
  - test/tinify_test.rb
74
61
  homepage: http://github.com/noushi/ruby-mincore
75
- licenses:
62
+ licenses:
76
63
  - GPL-2
64
+ metadata: {}
77
65
  post_install_message:
78
66
  rdoc_options: []
79
-
80
- require_paths:
67
+ require_paths:
81
68
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
- none: false
93
- requirements:
94
- - - ">"
95
- - !ruby/object:Gem::Version
96
- hash: 25
97
- segments:
98
- - 1
99
- - 3
100
- - 1
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>'
77
+ - !ruby/object:Gem::Version
101
78
  version: 1.3.1
102
79
  requirements: []
103
-
104
80
  rubyforge_project:
105
- rubygems_version: 1.8.15
81
+ rubygems_version: 2.1.10
106
82
  signing_key:
107
- specification_version: 3
83
+ specification_version: 4
108
84
  summary: Ruby bindings for Linux cache manipulation
109
- test_files:
85
+ test_files:
110
86
  - test/mincore_test.rb
111
87
  - test/test_helper.rb
112
88
  - test/tinify_test.rb
89
+ has_rdoc: