Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
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
nexedi
tsn-measures
Commits
2c34b5e5
Commit
2c34b5e5
authored
May 29, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start script to import measures and generate graphs and markdown tables
parent
c09e2e8d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
154 additions
and
7 deletions
+154
-7
measure-analysis/measure-analysis.py
measure-analysis/measure-analysis.py
+154
-7
No files found.
measure-analysis/measure-analysis.py
100644 → 100755
View file @
2c34b5e5
#!/usr/bin/env python3
import
statistics
import
statistics
import
json
import
markdown_table
import
argparse
import
os
class
MeasureSetHandler
:
measures_dir
=
"measures"
measure_sets_file_name
=
"measure_sets.json"
measure_sets_path
=
measures_dir
+
"/"
+
measure_sets_file_name
def
__init__
(
self
):
with
open
(
MeasureSetHandler
.
measure_sets_path
)
as
measure_sets_file
:
self
.
measure_sets
=
json
.
load
(
measure_sets_file
)
def
__str__
(
self
):
for
measure_set
in
self
.
measure_sets
:
print
(
"List of measures:
\
n
\
n
"
)
print
(
" "
+
measure_set
)
def
save
(
self
):
with
open
(
MeasureSetHandler
.
measure_sets_path
,
'w'
)
as
measure_sets_file
:
json
.
dump
(
self
.
measure_sets
,
measure_sets_file
)
def
add_measure_set
(
self
,
measure_set
):
mtype
=
measure_set
.
measure_type
if
mtype
not
in
self
.
measure_sets
:
self
.
measure_sets
[
mtype
]
=
{
'ids'
:
[],
'next_id'
:
0
}
next_id
=
self
.
measure_sets
[
mtype
][
'next_id'
]
measure_file_name
=
MeasureSetHandler
.
measures_dir
+
"/"
+
mtype
+
str
(
next_id
)
measure_set
.
export_to_json
(
measure_file_name
)
self
.
measure_sets
[
mtype
][
'ids'
].
append
(
next_id
)
self
.
measure_sets
[
mtype
][
'next_id'
]
+=
1
class
Measures
:
self
.
save
()
def
__init__
(
self
,
board
,
linux_version
,
boot_params
):
def
remove_measure_set
(
self
,
mtype
,
mid
):
if
mtype
in
self
.
measure_sets
and
len
(
self
.
measure_sets
[
mtype
][
'ids'
])
>
0
:
self
.
measure_sets
[
mtype
][
'ids'
].
remove
(
mid
)
measure_file_name
=
MeasureSetHandler
.
measures_dir
+
"/"
+
mtype
+
str
(
mid
)
os
.
remove
(
measure_file_name
)
self
.
save
()
def
remove_all
(
self
):
for
mtype
in
self
.
measure_sets
:
for
mid
in
self
.
measure_sets
[
mtype
][
'ids'
]:
self
.
remove_measure_set
(
mtype
,
mid
)
class
MeasureSet
:
def
__init__
(
self
):
self
.
board
=
"Emerald"
self
.
linux_version
=
"4.19"
self
.
boot_params
=
"isolcpus"
self
.
cols
=
{}
self
.
interval
=
0
self
.
units
=
[]
def
__str__
(
self
):
return
"Cols: "
+
str
(
self
.
cols
)
+
"
\
n
Interval: "
+
str
(
self
.
interval
)
def
set_meta_data
(
self
,
board
,
linux_version
,
boot_params
):
self
.
board
=
board
self
.
board
=
board
self
.
linux_version
=
linux_version
self
.
linux_version
=
linux_version
self
.
boot_params
=
boot_params
self
.
boot_params
=
boot_params
def
add_results
(
self
,
cols
,
interval
):
def
add_results
(
self
,
measure_type
,
interval
,
col_names
,
units
,
cols
):
self
.
measure_type
=
measure_type
self
.
cols
=
cols
self
.
cols
=
cols
self
.
col_names
=
col_names
self
.
interval
=
interval
self
.
interval
=
interval
self
.
units
=
units
self
.
max
=
[
max
(
col
)
for
col
in
cols
]
self
.
min
=
[
min
(
col
)
for
col
in
cols
]
self
.
avg
=
[
statistics
.
mean
(
col
)
for
col
in
cols
]
self
.
var
=
[
statistics
.
variance
(
col
)
for
col
in
cols
]
def
export_to_json
(
self
,
path
):
with
open
(
path
,
'w'
)
as
outfile
:
json
.
dump
({
'measure_type'
:
self
.
measure_type
,
'interval'
:
self
.
interval
,
'col_names'
:
self
.
col_names
,
'units'
:
self
.
units
,
'cols'
:
self
.
cols
},
outfile
)
def
import_from_json
(
self
,
path
,
flat
):
with
open
(
path
)
as
infile
:
data
=
json
.
load
(
infile
)
measure_type
=
data
[
'measure_type'
]
interval
=
data
[
'interval'
]
col_names
=
data
[
'col_names'
]
values
=
data
[
'values'
]
units
=
data
[
'units'
]
if
flat
:
nb_cols
=
len
(
col_names
)
cols
=
[[]
for
c
in
range
(
nb_cols
)]
for
i
,
value
in
enumerate
(
values
):
cols
[
i
%
nb_cols
].
append
(
value
)
else
:
cols
=
data
[
'cols'
]
self
.
add_results
(
measure_type
,
interval
,
col_names
,
units
,
cols
)
def
generate_graph
(
self
,
path
):
pass
def
generate_table
(
self
):
m
=
[
self
.
min
,
self
.
max
,
self
.
avg
,
self
.
var
]
headers
=
[
"Name"
,
"Min"
,
"Max"
,
"Avg"
,
"Var"
]
values
=
[[
(
format
(
m
[
j
][
i
],
'.4f'
)
+
self
.
units
[
i
])
for
j
in
range
(
len
(
m
))]
for
i
in
range
(
len
(
m
[
0
]))]
table
=
[
headers
]
table
+=
[([(
"*"
+
self
.
col_names
[
i
]
+
"*"
)]
+
values
[
i
])
for
i
in
range
(
len
(
values
))]
col_lens
=
[
max
([
len
(
table
[
i
][
j
])
for
i
in
range
(
len
(
table
))])
for
j
in
range
(
len
(
table
[
0
]))]
table
=
[[
table
[
i
][
j
].
ljust
(
col_lens
[
j
])
for
j
in
range
(
len
(
table
[
0
]))]
for
i
in
range
(
len
(
table
))]
table_str
=
" | "
.
join
(
table
[
0
])
+
"
\
n
"
table_str
+=
" | "
.
join
([
(
"-"
*
col_lens
[
i
])
for
i
in
range
(
len
(
col_lens
))
])
+
"
\
n
"
table_str
+=
"
\
n
"
.
join
([
" | "
.
join
(
line
)
for
line
in
table
[
1
:]])
return
table_str
def
parse
():
parser
=
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'Measure analysis'
)
parser
.
add_argument
(
'-i'
,
nargs
=
1
,
required
=
False
,
help
=
'import file'
)
parser
.
add_argument
(
'--remove_all'
,
action
=
'store_true'
,
help
=
'remove all measure sets'
)
parser
.
add_argument
(
'-t'
,
action
=
'store_true'
,
help
=
'generate table'
)
args
=
parser
.
parse_args
()
ms_handler
=
MeasureSetHandler
()
self
.
max
=
{
name
:
max
(
cols
[
name
])
for
name
in
cols
}
if
args
.
remove_all
:
self
.
min
=
{
name
:
min
(
cols
[
name
])
for
name
in
cols
}
confirm
=
input
(
"Are you sure all measure sets should be removed ? [Yes] / [No]: "
)
self
.
avg
=
{
name
:
statistics
.
mean
(
cols
[
name
])
for
name
in
cols
}
if
confirm
==
"Yes"
:
self
.
var
=
{
name
:
statistics
.
variance
(
cols
[
name
])
for
name
in
cols
}
ms_handler
.
remove_all
()
if
args
.
i
is
not
None
:
measure_set
=
MeasureSet
()
measure_set
.
import_from_json
(
args
.
i
[
0
],
True
)
ms_handler
.
add_measure_set
(
measure_set
)
parse
()
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