Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexander Emmerich
erp5
Commits
570d5737
Commit
570d5737
authored
Mar 14, 2013
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support csv output by '-c' or '--csv'.
parent
91e7c5cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
12 deletions
+57
-12
erp5/util/zodbanalyze/__init__.py
erp5/util/zodbanalyze/__init__.py
+57
-12
No files found.
erp5/util/zodbanalyze/__init__.py
View file @
570d5737
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Based on a transaction analyzer by Matt Kromer.
# Based on a transaction analyzer by Matt Kromer.
import
sys
import
sys
import
os
import
getopt
from
ZODB.FileStorage
import
FileStorage
from
ZODB.FileStorage
import
FileStorage
from
ZODB.utils
import
get_pickle_metadata
from
ZODB.utils
import
get_pickle_metadata
...
@@ -39,18 +41,24 @@ def shorten(s, n):
...
@@ -39,18 +41,24 @@ def shorten(s, n):
l
=
len
(
s
)
l
=
len
(
s
)
return
"..."
+
s
return
"..."
+
s
def
report
(
rep
):
def
report
(
rep
,
csv
=
False
):
if
not
csv
:
print
"Processed %d records in %d transactions"
%
(
rep
.
OIDS
,
rep
.
TIDS
)
print
"Processed %d records in %d transactions"
%
(
rep
.
OIDS
,
rep
.
TIDS
)
print
"Average record size is %7.2f bytes"
%
(
rep
.
DBYTES
*
1.0
/
rep
.
OIDS
)
print
"Average record size is %7.2f bytes"
%
(
rep
.
DBYTES
*
1.0
/
rep
.
OIDS
)
print
(
"Average transaction size is %7.2f bytes"
%
print
(
"Average transaction size is %7.2f bytes"
%
(
rep
.
DBYTES
*
1.0
/
rep
.
TIDS
))
(
rep
.
DBYTES
*
1.0
/
rep
.
TIDS
))
print
"Types used:"
print
"Types used:"
if
csv
:
fmt
=
"%s,%s,%s,%s,%s,%s,%s,%s,%s"
fmtp
=
"%s,%d,%d,%f%%,%f,%d,%d,%d,%d"
# per-class format
else
:
fmt
=
"%-46s %7s %9s %6s %7s %7s %9s %7s %9s"
fmt
=
"%-46s %7s %9s %6s %7s %7s %9s %7s %9s"
fmtp
=
"%-46s %7d %9d %5.1f%% %7.2f %7d %9d %7d %9d"
# per-class format
fmtp
=
"%-46s %7d %9d %5.1f%% %7.2f %7d %9d %7d %9d"
# per-class format
fmts
=
"%46s %7d %8dk %5.1f%% %7.2f"
# summary format
fmts
=
"%46s %7d %8dk %5.1f%% %7.2f"
# summary format
print
fmt
%
(
"Class Name"
,
"T.Count"
,
"T.Bytes"
,
"Pct"
,
"AvgSize"
,
print
fmt
%
(
"Class Name"
,
"T.Count"
,
"T.Bytes"
,
"Pct"
,
"AvgSize"
,
"C.Count"
,
"C.Bytes"
,
"O.Count"
,
"O.Bytes"
)
"C.Count"
,
"C.Bytes"
,
"O.Count"
,
"O.Bytes"
)
if
not
csv
:
print
fmt
%
(
'-'
*
46
,
'-'
*
7
,
'-'
*
9
,
'-'
*
5
,
'-'
*
7
,
'-'
*
7
,
'-'
*
9
,
'-'
*
7
,
'-'
*
9
)
print
fmt
%
(
'-'
*
46
,
'-'
*
7
,
'-'
*
9
,
'-'
*
5
,
'-'
*
7
,
'-'
*
7
,
'-'
*
9
,
'-'
*
7
,
'-'
*
9
)
typemap
=
rep
.
TYPEMAP
.
keys
()
typemap
=
rep
.
TYPEMAP
.
keys
()
typemap
.
sort
(
key
=
lambda
a
:
rep
.
TYPESIZE
[
a
])
typemap
.
sort
(
key
=
lambda
a
:
rep
.
TYPESIZE
[
a
])
...
@@ -58,11 +66,18 @@ def report(rep):
...
@@ -58,11 +66,18 @@ def report(rep):
for
t
in
typemap
:
for
t
in
typemap
:
pct
=
rep
.
TYPESIZE
[
t
]
*
100.0
/
rep
.
DBYTES
pct
=
rep
.
TYPESIZE
[
t
]
*
100.0
/
rep
.
DBYTES
cumpct
+=
pct
cumpct
+=
pct
print
fmtp
%
(
shorten
(
t
,
46
),
rep
.
TYPEMAP
[
t
],
rep
.
TYPESIZE
[
t
],
if
csv
:
t_display
=
t
else
:
t_display
=
shorten
(
t
,
46
)
print
fmtp
%
(
t_display
,
rep
.
TYPEMAP
[
t
],
rep
.
TYPESIZE
[
t
],
pct
,
rep
.
TYPESIZE
[
t
]
*
1.0
/
rep
.
TYPEMAP
[
t
],
pct
,
rep
.
TYPESIZE
[
t
]
*
1.0
/
rep
.
TYPEMAP
[
t
],
rep
.
COIDSMAP
[
t
],
rep
.
CBYTESMAP
[
t
],
rep
.
COIDSMAP
[
t
],
rep
.
CBYTESMAP
[
t
],
rep
.
FOIDSMAP
.
get
(
t
,
0
),
rep
.
FBYTESMAP
.
get
(
t
,
0
))
rep
.
FOIDSMAP
.
get
(
t
,
0
),
rep
.
FBYTESMAP
.
get
(
t
,
0
))
if
csv
:
return
print
fmt
%
(
'='
*
46
,
'='
*
7
,
'='
*
9
,
'='
*
5
,
'='
*
7
,
'='
*
7
,
'='
*
9
,
'='
*
7
,
'='
*
9
)
print
fmt
%
(
'='
*
46
,
'='
*
7
,
'='
*
9
,
'='
*
5
,
'='
*
7
,
'='
*
7
,
'='
*
9
,
'='
*
7
,
'='
*
9
)
print
"%46s %7d %9s %6s %6.2fk"
%
(
'Total Transactions'
,
rep
.
TIDS
,
' '
,
print
"%46s %7d %9s %6s %6.2fk"
%
(
'Total Transactions'
,
rep
.
TIDS
,
' '
,
' '
,
rep
.
DBYTES
*
1.0
/
rep
.
TIDS
/
1024.0
)
' '
,
rep
.
DBYTES
*
1.0
/
rep
.
TIDS
/
1024.0
)
...
@@ -127,6 +142,36 @@ def analyze_rec(report, record):
...
@@ -127,6 +142,36 @@ def analyze_rec(report, record):
except
Exception
,
err
:
except
Exception
,
err
:
print
err
print
err
__doc__
=
"""%(program)s: Data.fs analyzer
usage: %(program)s [options] /path/to/Data.fs
Options:
-h, --help this help screen
-c, --csv output CSV
"""
def
usage
(
stream
,
msg
=
None
):
if
msg
:
print
>>
stream
,
msg
print
>>
stream
program
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
print
>>
stream
,
__doc__
%
{
"program"
:
program
}
def
main
():
def
main
():
path
=
sys
.
argv
[
1
]
try
:
report
(
analyze
(
path
))
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'hc'
,
[
'help'
,
'csv'
])
path
=
args
[
0
]
except
(
getopt
.
GetoptError
,
IndexError
),
msg
:
usage
(
sys
.
stderr
,
msg
)
sys
.
exit
(
2
)
csv
=
False
for
opt
,
args
in
opts
:
if
opt
in
(
'-c'
,
'--csv'
):
csv
=
True
elif
opt
in
(
'-h'
,
'--help'
):
usage
(
sys
.
stdout
)
sys
.
exit
()
report
(
analyze
(
path
),
csv
)
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