⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (1.25 KB)
Bug #11101
ยป mem.rb
tkalmus (Thomas Kalmus)
, 04/27/2015 03:13 PM
#!/usr/local/ruby-2.1.3/bin/ruby
#### methods ####
def
time_step
(
n
)
while
Time
.
new
-
$start_time
<
n
sleep
(
0.1
)
end
end
def
memory_object
(
size
)
result
=
[]
count
=
size
/
20
count
.
times
do
result
<<
"%20.18f"
%
rand
end
return
result
end
def
memory_log
(
message
)
shared_memory
=
0
private_memory
=
0
lines
=
File
.
read
(
"/proc/
#{
$$
}
/smaps"
)
lines
.
scan
(
/.+?Shared_Dirty:\s+(\d+).+?Private_Dirty:\s+(\d+)/m
)
do
|
shared_dirty
,
private_dirty
|
shared_memory
+=
shared_dirty
.
to_i
private_memory
+=
private_dirty
.
to_i
end
time
=
Time
.
new
-
$start_time
puts
"%6.3fs %5d %-15s %10d %10d"
%
[
time
,
$$
,
message
,
shared_memory
/
1000
,
private_memory
/
1000
]
end
##### main #####
puts
"ruby version
#{
RUBY_VERSION
}
"
GC
.
disable
puts
" %6s %5s %-15s %10s %10s"
%
[
"time"
,
"pid"
,
"message"
,
"shared"
,
"private"
]
big_memory
=
memory_object
(
10_000_000
)
$start_time
=
Time
.
new
pid
=
fork
do
time_step
(
4
)
memory_log
(
"Child pre GC"
)
time_step
(
6
)
GC
.
enable
;
GC
.
start
;
GC
.
disable
time_step
(
8
)
memory_log
(
"Child post GC"
)
STDOUT
.
flush
exit!
end
time_step
(
4
)
memory_log
(
"Parent pre GC "
)
time_step
(
8
)
memory_log
(
"Parent post GC"
)
Process
.
wait
(
pid
)
(1-1/1)
Loading...