Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZEO
Commits
5cfea0a2
Commit
5cfea0a2
authored
Sep 06, 2002
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored to make the simulation a class. Tweaked output formatting,
report overall statistics for all columns.
parent
f6c5cc13
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
143 additions
and
71 deletions
+143
-71
src/ZEO/simul.py
src/ZEO/simul.py
+143
-71
No files found.
src/ZEO/simul.py
View file @
5cfea0a2
...
@@ -51,103 +51,175 @@ def main():
...
@@ -51,103 +51,175 @@ def main():
print
"can't open %s: %s"
%
(
filename
,
msg
)
print
"can't open %s: %s"
%
(
filename
,
msg
)
return
1
return
1
# Set up statistics
# Create simulation object
flips
=
0
sim
=
ZEOCacheSimulation
(
cachelimit
)
loads
=
0
hits
=
0
# Print output header
invals
=
0
sim
.
printheader
()
writes
=
0
ts0
=
None
total_loads
=
0
total_hits
=
0
# Set up simulation data
filelimit
=
cachelimit
/
2
filesize
=
[
4
,
4
]
# account for magic number
fileoids
=
[{},
{}]
current
=
0
# index into filesize, fileoids
# Print header
print
"%12s %12s %6s %6s %6s %6s %6s %6s"
%
(
"__START_TIME"
,
"___STOP_TIME"
,
"LOADS"
,
"HITS"
,
"INVALS"
,
"WRITES"
,
"FLIPS"
,
"HIT%"
)
# Read trace file, simulating cache behavior
# Read trace file, simulating cache behavior
while
1
:
while
1
:
# Read a re
a
cord
# Read a record
r
=
f
.
read
(
24
)
r
=
f
.
read
(
24
)
if
len
(
r
)
<
24
:
if
len
(
r
)
<
24
:
break
break
# Decode it
# Decode it
ts
,
code
,
oid
,
serial
=
struct
.
unpack
(
">ii8s8s"
,
r
)
ts
,
code
,
oid
,
serial
=
struct
.
unpack
(
">ii8s8s"
,
r
)
dlen
,
version
,
code
,
ignored
=
(
code
&
0x7fffff00
,
dlen
,
version
,
code
,
current
=
(
code
&
0x7fffff00
,
code
&
0x80
,
code
&
0x80
,
code
&
0x7e
,
code
&
0x7e
,
code
&
0x01
)
code
&
0x01
)
if
ts0
is
None
:
# And pass it to the simulation
ts0
=
ts
sim
.
event
(
ts
,
dlen
,
version
,
code
,
current
,
oid
,
serial
)
# Finish simulation
sim
.
finish
()
# Exit code from main()
return
0
class
Simulation
:
"""Abstract base class to define simulation interface.
These are the only methods that the driver program calls.
The constructor signature is not part of the interface.
"""
def
event
(
self
,
ts
,
dlen
,
version
,
code
,
current
,
oid
,
serial
):
pass
def
printheader
(
self
):
pass
def
finish
(
self
):
pass
class
ZEOCacheSimulation
(
Simulation
):
"""Simulate the current (ZEO 1.0 and 2.0) ZEO cache behavior."""
def
__init__
(
self
,
cachelimit
):
# Store simulation parameters
self
.
filelimit
=
cachelimit
/
2
# Initialize global statistics
self
.
epoch
=
None
self
.
total_flips
=
0
self
.
total_loads
=
0
self
.
total_hits
=
0
self
.
total_invals
=
0
self
.
total_writes
=
0
# Reset per-run statistics and simulation data
self
.
restart
()
def
restart
(
self
):
# Set up statistics
self
.
flips
=
0
self
.
loads
=
0
self
.
hits
=
0
self
.
invals
=
0
self
.
writes
=
0
self
.
ts0
=
None
# Set up simulation data
self
.
filesize
=
[
4
,
4
]
# account for magic number
self
.
fileoids
=
[{},
{}]
self
.
current
=
0
# index into filesize, fileoids
def
event
(
self
,
ts
,
dlen
,
_version
,
code
,
_current
,
oid
,
_serial
):
# Record first and last timestamp seen
if
self
.
ts0
is
None
:
self
.
ts0
=
ts
if
self
.
epoch
is
None
:
self
.
epoch
=
ts
self
.
ts1
=
ts
# Simulate cache behavior. Use load hits, updates and stores
# Simulate cache behavior. Use load hits, updates and stores
# only (each load miss is followed immediately by a store
# only (each load miss is followed immediately by a store
# unless the object in fact did not exist). Updates always write.
# unless the object in fact did not exist). Updates always write.
if
dlen
and
code
&
0x70
in
(
0x20
,
0x30
,
0x50
):
if
dlen
and
code
&
0x70
in
(
0x20
,
0x30
,
0x50
):
if
code
==
0x3A
:
if
code
==
0x3A
:
writes
+=
1
self
.
writes
+=
1
self
.
total_writes
+=
1
else
:
else
:
loads
+=
1
self
.
loads
+=
1
total_loads
+=
1
self
.
total_loads
+=
1
if
code
!=
0x3A
and
(
fileoids
[
current
].
get
(
oid
)
or
if
code
!=
0x3A
and
(
self
.
fileoids
[
self
.
current
].
get
(
oid
)
or
fileoids
[
1
-
current
].
get
(
oid
)):
self
.
fileoids
[
1
-
self
.
current
].
get
(
oid
)):
hits
+=
1
self
.
hits
+=
1
total_hits
+=
1
self
.
total_hits
+=
1
else
:
else
:
# Simulate a miss+store. Fudge because dlen is
# Simulate a miss+store. Fudge because dlen is
# rounded up to multiples of 256. (31 is header
# rounded up to multiples of 256. (31 is header
# overhead per cache record; 8 is min data size.)
# overhead per cache record; 127 is to compensate for
dlen
=
max
(
31
+
8
,
dlen
+
31
-
128
)
# rounding up to multiples of 256.)
if
filesize
[
current
]
+
dlen
>
filelimit
:
dlen
=
dlen
+
31
-
127
if
self
.
filesize
[
self
.
current
]
+
dlen
>
self
.
filelimit
:
# Cache flip
# Cache flip
flips
+=
1
self
.
flips
+=
1
current
=
1
-
current
self
.
total_flips
+=
1
filesize
[
current
]
=
4
self
.
current
=
1
-
self
.
current
fileoids
[
current
]
=
{}
self
.
filesize
[
self
.
current
]
=
4
filesize
[
current
]
+=
dlen
self
.
fileoids
[
self
.
current
]
=
{}
fileoids
[
current
][
oid
]
=
1
self
.
filesize
[
self
.
current
]
+=
dlen
self
.
fileoids
[
self
.
current
][
oid
]
=
1
elif
code
&
0x70
==
0x10
:
elif
code
&
0x70
==
0x10
:
# Invalidate
# Invalidate
if
fileoids
[
current
].
get
(
oid
):
if
self
.
fileoids
[
self
.
current
].
get
(
oid
):
invals
+=
1
self
.
invals
+=
1
del
fileoids
[
current
][
oid
]
self
.
total_invals
+=
1
elif
fileoids
[
1
-
current
].
get
(
oid
):
del
self
.
fileoids
[
self
.
current
][
oid
]
invals
+=
1
elif
self
.
fileoids
[
1
-
self
.
current
].
get
(
oid
):
del
fileoids
[
1
-
current
][
oid
]
self
.
invals
+=
1
self
.
total_invals
+=
1
del
self
.
fileoids
[
1
-
self
.
current
][
oid
]
elif
code
==
0x00
:
elif
code
==
0x00
:
# Restart
# Restart
if
loads
:
self
.
report
()
report
(
ts0
,
ts
,
loads
,
hits
,
invals
,
writes
,
flips
)
self
.
restart
()
loads
=
0
hits
=
0
format
=
"%12s %9s %8s %8s %6s %6s %5s %6s"
flips
=
0
invals
=
0
def
printheader
(
self
):
writes
=
0
print
self
.
format
%
(
ts0
=
None
"START TIME"
,
"DURATION"
,
"LOADS"
,
"HITS"
,
filesize
=
[
4
,
4
]
# account for magic number
"INVALS"
,
"WRITES"
,
"FLIPS"
,
"HITRATE"
)
fileoids
=
[{},
{}]
current
=
0
# index into filesize, fileoids
def
report
(
self
):
if
self
.
loads
:
if
loads
:
print
self
.
format
%
(
report
(
ts0
,
ts
,
loads
,
hits
,
invals
,
writes
,
flips
)
time
.
ctime
(
self
.
ts0
)[
4
:
-
8
],
duration
(
self
.
ts1
-
self
.
ts0
),
if
total_loads
:
self
.
loads
,
self
.
hits
,
self
.
invals
,
self
.
writes
,
self
.
flips
,
print
"Overall: %d loads, %d hits, hit rate %.1f%%"
%
(
hitrate
(
self
.
loads
,
self
.
hits
))
total_loads
,
total_hits
,
100.0
*
total_hits
/
total_loads
)
def
finish
(
self
):
def
report
(
ts0
,
ts
,
loads
,
hits
,
invals
,
writes
,
flips
):
if
self
.
loads
:
hr
=
100.0
*
hits
/
max
(
loads
,
1
)
self
.
report
()
print
"%s %s %6d %6d %6d %6d %6d %6.1f%%"
%
(
if
self
.
total_loads
:
time
.
ctime
(
ts0
)[
4
:
-
8
],
time
.
ctime
(
ts
)[
4
:
-
8
],
print
(
self
.
format
+
" OVERALL"
)
%
(
loads
,
hits
,
invals
,
writes
,
flips
,
hr
)
time
.
ctime
(
self
.
epoch
)[
4
:
-
8
],
duration
(
self
.
ts1
-
self
.
epoch
),
self
.
total_loads
,
self
.
total_hits
,
self
.
total_invals
,
self
.
total_writes
,
self
.
total_flips
,
hitrate
(
self
.
total_loads
,
self
.
total_hits
))
def
hitrate
(
loads
,
hits
):
return
"%5.1f%%"
%
(
100.0
*
hits
/
max
(
1
,
loads
))
def
duration
(
secs
):
mm
,
ss
=
divmod
(
secs
,
60
)
hh
,
mm
=
divmod
(
mm
,
60
)
if
hh
:
return
"%d:%02d:%02d"
%
(
hh
,
mm
,
ss
)
if
mm
:
return
"%d:%02d"
%
(
mm
,
ss
)
return
"%d"
%
ss
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
sys
.
exit
(
main
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment