tiny_mem 1.0.0
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.
- checksums.yaml +7 -0
- data/lib/tiny_mem.rb +52 -0
- metadata +41 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 86d1b1c882d9d7a03aa77b23e8e217dbf234a1f3872fd4fbe80f00a199444cda
|
4
|
+
data.tar.gz: 1389b27193ae7e730a1a23a8cb335719ab102a9703de0265717b030626e77009
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a5ad2536b22b46c8fe5a2b5f606fb1764775d763a67377caac3146c1856d174b5a5edf1614d775bae7565ca64a115e49dc6c48ddbd5276fb697ccdf63f1fb8f
|
7
|
+
data.tar.gz: 192e48a1adb9ca321e8ef5641899a93ceb94b070dae4ef484e0de73f3a1a73278bde8662b90675eb4e3385c6f740b662369209beceaa743e13692a68b9b436bd
|
data/lib/tiny_mem.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# a tiny memory measurement tool for linux and macos, measuring resident set
|
2
|
+
# size (rss) (i.e. total memory allocated and still in use).
|
3
|
+
#
|
4
|
+
# ex:
|
5
|
+
# mem = TinyMem.new
|
6
|
+
# mem.measure 'array_alloc' do
|
7
|
+
# Array.new(100_000) { 'hello' }
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# mem.measure 'nothing'
|
11
|
+
#
|
12
|
+
# pp mem.stats
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# this would output something like:
|
16
|
+
#
|
17
|
+
# [
|
18
|
+
# ["array_alloc", 70568, 72732, 2164 ],
|
19
|
+
# ["nothing", 72744, 72744, 0 ]
|
20
|
+
# ] ^label ^before ^after ^change ... in kilobytes
|
21
|
+
class TinyMem
|
22
|
+
attr_reader :stats
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@stats = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def measure(label)
|
29
|
+
pid = Process.pid
|
30
|
+
before = _mem
|
31
|
+
yield if block_given?
|
32
|
+
after = _mem
|
33
|
+
|
34
|
+
@stats << [label, before, after, after-before]
|
35
|
+
end
|
36
|
+
|
37
|
+
def _mem
|
38
|
+
case RUBY_PLATFORM
|
39
|
+
when /linux/
|
40
|
+
begin
|
41
|
+
line = File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)\s*/)
|
42
|
+
line ? line[1].to_i : 'unknown'
|
43
|
+
rescue Errno::ENOENT
|
44
|
+
'error'
|
45
|
+
end
|
46
|
+
when /darwin/
|
47
|
+
`ps -o rss= -p #{Process.pid}`.to_i
|
48
|
+
else
|
49
|
+
"#{RUBY_PLATFORM} not supported"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny_mem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Lunt
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: a small utility for measuring memory consumed by little bits of your
|
13
|
+
code
|
14
|
+
email: jefflunt@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tiny_mem.rb
|
20
|
+
homepage: https://github.com/jefflunt/tiny_mem
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubygems_version: 3.6.7
|
39
|
+
specification_version: 4
|
40
|
+
summary: a small utility for measuring memory consumed by little bits of your code
|
41
|
+
test_files: []
|