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
Arnaud Fontaine
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 = {
),
}
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
():
global
abs_file_container
parser
=
argparse
.
ArgumentParser
(
description
=
'Compute Apdex out of '
...
...
@@ -846,84 +939,22 @@ def main():
else
:
out
=
open
(
args
.
out
,
'w'
)
with
out
:
out
.
write
(
'<!DOCTYPE html>
\
n
<html><head><meta charset="utf-8">'
'<title>Stats</title>'
)
if
getattr
(
args
,
'js_embed'
,
True
):
out
.
write
(
'<style>'
)
out
.
write
(
getResource
(
'apachedex.css'
))
out
.
write
(
'</style>'
)
else
:
out
.
write
(
'<link rel="stylesheet" type="text/css" '
'href="%s/apachedex.css"/>'
%
args
.
js
)
for
script
in
(
'jquery.js'
,
'jquery.flot.js'
,
'jquery.flot.time.js'
,
'jquery.flot.axislabels.js'
,
'jquery-ui.js'
,
'apachedex.js'
):
if
getattr
(
args
,
'js_embed'
,
True
):
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>'
%
(
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>'
)
format_generator
[
args
.
format
](
out
,
per_site
,
args
,
{
'period'
:
period
,
'decimator'
:
decimator
,
'date_format'
:
date_format
,
'placeholder_delta'
:
placeholder_delta
,
'graph_period'
:
graph_period
,
},
{
'start_time'
:
start_time
,
'end_parsing_time'
:
end_parsing_time
,
'file_count'
:
file_count
,
'all_lines'
:
all_lines
,
'malformed_lines'
:
malformed_lines
,
'no_url_lines'
:
no_url_lines
,
'skipped_lines'
:
skipped_lines
,
'skipped_user_agent'
:
skipped_user_agent
,
})
if
__name__
==
'__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