Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
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
Xiaowu Zhang
apachedex
Commits
64dcab76
Commit
64dcab76
authored
Apr 07, 2013
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move output generation out of main.
To plug more output formats.
parent
24b0a51c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
78 deletions
+109
-78
apachedex/__init__.py
apachedex/__init__.py
+109
-78
No files found.
apachedex/__init__.py
View file @
64dcab76
...
@@ -634,6 +634,99 @@ period_parser = {
...
@@ -634,6 +634,99 @@ period_parser = {
),
),
}
}
def
asHTML
(
out
,
per_site
,
args
,
period_parameter_dict
,
stats
):
period
=
period_parameter_dict
[
'period'
]
decimator
=
period_parameter_dict
[
'decimator'
]
date_format
=
period_parameter_dict
[
'date_format'
]
placeholder_delta
=
period_parameter_dict
[
'placeholder_delta'
]
graph_period
=
period_parameter_dict
[
'graph_period'
]
out
.
write
(
'<!DOCTYPE html>
\
n
<html><head><meta charset="utf-8">'
'<title>Stats</title>'
)
js_embed
=
getattr
(
args
,
'js_embed'
,
True
)
js_path
=
getattr
(
args
,
'js'
,
None
)
if
js_embed
:
out
.
write
(
'<style>'
)
out
.
write
(
getResource
(
'apachedex.css'
))
out
.
write
(
'</style>'
)
else
:
out
.
write
(
'<link rel="stylesheet" type="text/css" '
'href="%s/apachedex.css"/>'
%
js_path
)
for
script
in
(
'jquery.js'
,
'jquery.flot.js'
,
'jquery.flot.time.js'
,
'jquery.flot.axislabels.js'
,
'jquery-ui.js'
,
'apachedex.js'
):
if
js_embed
:
out
.
write
(
'<script type="text/javascript">//<![CDATA[
\
n
'
)
out
.
write
(
getResource
(
script
))
out
.
write
(
'
\
n
//]]></script>'
)
else
:
out
.
write
(
'<script type="text/javascript" src="%s/%s"></script>'
%
(
js_path
,
script
))
out
.
write
(
'</head><body><h1>Overall</h1><h2>Parameters</h2>'
'<table class="stats">'
)
for
caption
,
value
in
(
(
'apdex threshold'
,
'%.2fs'
%
args
.
apdex
),
(
'period'
,
args
.
period
or
(
period
+
' (auto)'
)),
):
out
.
write
(
'<tr><th class="text">%s</th><td>%s</td></tr>'
%
(
caption
,
value
))
out
.
write
(
'</table><h2>Hits per period</h2><table class="stats">'
'<tr><th>date</th><th>hits</th></tr>'
)
hit_per_day
=
defaultdict
(
int
)
for
site_data
in
per_site
.
itervalues
():
for
date
,
_
,
hit
in
site_data
.
getApdexData
():
hit_per_day
[
decimator
(
date
)]
+=
hit
for
date
,
hit
in
sorted
(
hit_per_day
.
iteritems
(),
key
=
ITEMGETTER0
):
out
.
write
(
'<tr><td>%s</td><td>%s</td></tr>'
%
(
date
,
hit
))
out
.
write
(
'</table>'
)
for
site_id
,
data
in
per_site
.
iteritems
():
out
.
write
(
'<h1>Site: %s</h1>'
%
site_id
)
out
.
write
(
graphPair
(
prepareDataForGraph
(
data
.
getApdexData
(),
date_format
,
placeholder_delta
,
),
date_format
,
graph_period
,
)
)
out
.
write
(
data
.
asHTML
(
date_format
,
placeholder_delta
,
graph_period
,
decimator
))
end_stat_time
=
time
.
time
()
if
args
.
stats
:
out
.
write
(
'<h1>Parsing stats</h1><table class="stats">'
)
buildno
,
builddate
=
platform
.
python_build
()
end_parsing_time
=
stats
[
'end_parsing_time'
]
parsing_time
=
end_parsing_time
-
stats
[
'start_time'
]
all_lines
=
stats
[
'all_lines'
]
for
caption
,
value
in
(
(
'Execution date'
,
datetime
.
now
().
isoformat
()),
(
'Interpreter'
,
'%s %s build %s (%s)'
%
(
platform
.
python_implementation
(),
platform
.
python_version
(),
buildno
,
builddate
,
)),
(
'File count'
,
stats
[
'file_count'
]),
(
'Lines'
,
all_lines
),
(
'... malformed'
,
stats
[
'malformed_lines'
]),
(
'... URL-less'
,
stats
[
'no_url_lines'
]),
(
'... skipped (URL)'
,
stats
[
'skipped_lines'
]),
(
'... skipped (user agent)'
,
stats
[
'skipped_user_agent'
]),
(
'Parsing time'
,
timedelta
(
seconds
=
parsing_time
)),
(
'Parsing rate'
,
'%i line/s'
%
(
all_lines
/
parsing_time
)),
(
'Rendering time'
,
timedelta
(
seconds
=
(
end_stat_time
-
end_parsing_time
))),
):
out
.
write
(
'<tr><th class="text">%s</th><td>%s</td></tr>'
%
(
caption
,
value
))
out
.
write
(
'</table>'
)
out
.
write
(
'</body></html>'
)
format_generator
=
{
'html'
:
asHTML
,
}
def
main
():
def
main
():
global
abs_file_container
global
abs_file_container
parser
=
argparse
.
ArgumentParser
(
description
=
'Compute Apdex out of '
parser
=
argparse
.
ArgumentParser
(
description
=
'Compute Apdex out of '
...
@@ -846,84 +939,22 @@ def main():
...
@@ -846,84 +939,22 @@ def main():
else
:
else
:
out
=
open
(
args
.
out
,
'w'
)
out
=
open
(
args
.
out
,
'w'
)
with
out
:
with
out
:
out
.
write
(
'<!DOCTYPE html>
\
n
<html><head><meta charset="utf-8">'
format_generator
[
args
.
format
](
out
,
per_site
,
args
,
{
'<title>Stats</title>'
)
'period'
:
period
,
if
getattr
(
args
,
'js_embed'
,
True
):
'decimator'
:
decimator
,
out
.
write
(
'<style>'
)
'date_format'
:
date_format
,
out
.
write
(
getResource
(
'apachedex.css'
))
'placeholder_delta'
:
placeholder_delta
,
out
.
write
(
'</style>'
)
'graph_period'
:
graph_period
,
else
:
},
{
out
.
write
(
'<link rel="stylesheet" type="text/css" '
'start_time'
:
start_time
,
'href="%s/apachedex.css"/>'
%
args
.
js
)
'end_parsing_time'
:
end_parsing_time
,
for
script
in
(
'jquery.js'
,
'jquery.flot.js'
,
'jquery.flot.time.js'
,
'file_count'
:
file_count
,
'jquery.flot.axislabels.js'
,
'jquery-ui.js'
,
'apachedex.js'
):
'all_lines'
:
all_lines
,
if
getattr
(
args
,
'js_embed'
,
True
):
'malformed_lines'
:
malformed_lines
,
out
.
write
(
'<script type="text/javascript">//<![CDATA[
\
n
'
)
'no_url_lines'
:
no_url_lines
,
out
.
write
(
getResource
(
script
))
'skipped_lines'
:
skipped_lines
,
out
.
write
(
'
\
n
//]]></script>'
)
'skipped_user_agent'
:
skipped_user_agent
,
else
:
})
out
.
write
(
'<script type="text/javascript" src="%s/%s"></script>'
%
(
args
.
js
,
script
))
out
.
write
(
'</head><body><h1>Overall</h1><h2>Parameters</h2>'
'<table class="stats">'
)
for
caption
,
value
in
(
(
'apdex threshold'
,
'%.2fs'
%
args
.
apdex
),
(
'period'
,
args
.
period
or
(
period
+
' (auto)'
)),
):
out
.
write
(
'<tr><th class="text">%s</th><td>%s</td></tr>'
%
(
caption
,
value
))
out
.
write
(
'</table><h2>Hits per period</h2><table class="stats">'
'<tr><th>date</th><th>hits</th></tr>'
)
hit_per_day
=
defaultdict
(
int
)
for
site_data
in
per_site
.
itervalues
():
for
date
,
_
,
hit
in
site_data
.
getApdexData
():
hit_per_day
[
decimator
(
date
)]
+=
hit
for
date
,
hit
in
sorted
(
hit_per_day
.
iteritems
(),
key
=
ITEMGETTER0
):
out
.
write
(
'<tr><td>%s</td><td>%s</td></tr>'
%
(
date
,
hit
))
out
.
write
(
'</table>'
)
for
site_id
,
data
in
per_site
.
iteritems
():
out
.
write
(
'<h1>Site: %s</h1>'
%
site_id
)
out
.
write
(
graphPair
(
prepareDataForGraph
(
data
.
getApdexData
(),
date_format
,
placeholder_delta
,
),
date_format
,
graph_period
,
)
)
out
.
write
(
data
.
asHTML
(
date_format
,
placeholder_delta
,
graph_period
,
decimator
))
end_stat_time
=
time
.
time
()
if
args
.
stats
:
out
.
write
(
'<h1>Parsing stats</h1><table class="stats">'
)
buildno
,
builddate
=
platform
.
python_build
()
parsing_time
=
end_parsing_time
-
start_time
for
caption
,
value
in
(
(
'Execution date'
,
datetime
.
now
().
isoformat
()),
(
'Interpreter'
,
'%s %s build %s (%s)'
%
(
platform
.
python_implementation
(),
platform
.
python_version
(),
buildno
,
builddate
,
)),
(
'File count'
,
file_count
),
(
'Lines'
,
all_lines
),
(
'... malformed'
,
malformed_lines
),
(
'... URL-less'
,
no_url_lines
),
(
'... skipped (URL)'
,
skipped_lines
),
(
'... skipped (user agent)'
,
skipped_user_agent
),
(
'Parsing time'
,
timedelta
(
seconds
=
parsing_time
)),
(
'Parsing rate'
,
'%i line/s'
%
(
all_lines
/
parsing_time
)),
(
'Rendering time'
,
timedelta
(
seconds
=
(
end_stat_time
-
end_parsing_time
))),
):
out
.
write
(
'<tr><th class="text">%s</th><td>%s</td></tr>'
%
(
caption
,
value
))
out
.
write
(
'</table>'
)
out
.
write
(
'</body></html>'
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
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