Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pyzenkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
Pyzenkit
Commits
c3071422
Commit
c3071422
authored
7 years ago
by
Honza Mach
Browse files
Options
Downloads
Patches
Plain Diff
Added support for statistics calculation for nested statistics.
parent
be8d9767
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyzenkit/tests/test_zendaemon.py
+19
-0
19 additions, 0 deletions
pyzenkit/tests/test_zendaemon.py
pyzenkit/zendaemon.py
+27
-20
27 additions, 20 deletions
pyzenkit/zendaemon.py
with
46 additions
and
20 deletions
pyzenkit/tests/test_zendaemon.py
+
19
−
0
View file @
c3071422
...
@@ -55,5 +55,24 @@ class TestPyzenkitZenDaemon(unittest.TestCase):
...
@@ -55,5 +55,24 @@ class TestPyzenkitZenDaemon(unittest.TestCase):
"""
"""
self
.
assertTrue
(
True
)
self
.
assertTrue
(
True
)
def
test_02_calc_statistics
(
self
):
"""
Perform the test of statistics calculation.
"""
self
.
maxDiff
=
None
result
=
pyzenkit
.
zendaemon
.
calc_statistics
(
{
'
cnt_test_a1
'
:
50
,
'
cnt_test_a2
'
:
100
,
'
sub
'
:
{
'
cnt_test_b1
'
:
500
,
'
cnt_test_b2
'
:
1000
}},
{},
50
)
self
.
assertEqual
(
result
,
{
'
cnt_test_a1
'
:
{
'
cnt
'
:
50
,
'
inc
'
:
50
,
'
pct
'
:
100.0
,
'
spd
'
:
1.0
},
'
cnt_test_a2
'
:
{
'
cnt
'
:
100
,
'
inc
'
:
100
,
'
pct
'
:
100.0
,
'
spd
'
:
2.0
},
'
sub
'
:
{
'
cnt_test_b1
'
:
{
'
cnt
'
:
500
,
'
inc
'
:
500
,
'
pct
'
:
100.0
,
'
spd
'
:
10.0
},
'
cnt_test_b2
'
:
{
'
cnt
'
:
1000
,
'
inc
'
:
1000
,
'
pct
'
:
100.0
,
'
spd
'
:
20.0
}}}
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
unittest
.
main
()
unittest
.
main
()
This diff is collapsed.
Click to expand it.
pyzenkit/zendaemon.py
+
27
−
20
View file @
c3071422
...
@@ -217,6 +217,31 @@ class EventQueueManager:
...
@@ -217,6 +217,31 @@ class EventQueueManager:
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
calc_statistics
(
stats_cur
,
stats_prev
,
tdiff
):
"""
Calculate statistics.
"""
result
=
{}
for
key
in
stats_cur
:
if
isinstance
(
stats_cur
[
key
],
dict
):
result
[
key
]
=
calc_statistics
(
stats_cur
[
key
],
stats_prev
.
get
(
key
,
{}),
tdiff
)
else
:
result
[
key
]
=
{
# Absolute count.
'
cnt
'
:
stats_cur
[
key
],
# Increase count (delta from previous value).
'
inc
'
:
stats_cur
[
key
]
-
stats_prev
.
get
(
key
,
0
),
# Processing speed (#/s).
'
spd
'
:
(
stats_cur
[
key
]
-
stats_prev
.
get
(
key
,
0
))
/
tdiff
,
# Percentage increase count.
'
pct
'
:
(
stats_cur
[
key
]
-
stats_prev
.
get
(
key
,
0
))
/
(
stats_cur
[
key
]
/
100
)
}
return
result
#-------------------------------------------------------------------------------
class
ZenDaemonComponentException
(
pyzenkit
.
baseapp
.
ZenAppProcessException
):
class
ZenDaemonComponentException
(
pyzenkit
.
baseapp
.
ZenAppProcessException
):
"""
"""
Describes problems specific to daemon components.
Describes problems specific to daemon components.
...
@@ -260,25 +285,6 @@ class ZenDaemonComponent:
...
@@ -260,25 +285,6 @@ class ZenDaemonComponent:
'
statistics
'
:
self
.
statistics_cur
'
statistics
'
:
self
.
statistics_cur
}
}
@staticmethod
def
calc_statistics
(
stats_cur
,
stats_prev
,
tdiff
):
"""
Calculate daemon component statistics.
"""
result
=
{}
for
key
in
stats_cur
:
result
[
key
]
=
{
# Absolute count.
'
cnt
'
:
stats_cur
[
key
],
# Increase from previous value.
'
inc
'
:
stats_cur
[
key
]
-
stats_prev
.
get
(
key
,
0
),
# Processing speed (#/s)
'
spd
'
:
(
stats_cur
[
key
]
-
stats_prev
.
get
(
key
,
0
))
/
tdiff
,
# Percentage increase.
'
pct
'
:
(
stats_cur
[
key
]
-
stats_prev
.
get
(
key
,
0
))
/
(
stats_cur
[
key
]
/
100
)
}
return
result
def
get_statistics
(
self
):
def
get_statistics
(
self
):
"""
"""
Calculate processing statistics
Calculate processing statistics
...
@@ -286,7 +292,7 @@ class ZenDaemonComponent:
...
@@ -286,7 +292,7 @@ class ZenDaemonComponent:
curts
=
time
.
time
()
curts
=
time
.
time
()
tdiff
=
curts
-
self
.
statistics_ts
tdiff
=
curts
-
self
.
statistics_ts
stats
=
self
.
calc_statistics
(
self
.
statistics_cur
,
self
.
statistics_prev
,
tdiff
)
stats
=
calc_statistics
(
self
.
statistics_cur
,
self
.
statistics_prev
,
tdiff
)
self
.
statistics_prev
=
copy
.
copy
(
self
.
statistics_cur
)
self
.
statistics_prev
=
copy
.
copy
(
self
.
statistics_cur
)
self
.
statistics_ts
=
curts
self
.
statistics_ts
=
curts
...
@@ -940,6 +946,7 @@ class DemoDaemonComponent(ZenDaemonComponent):
...
@@ -940,6 +946,7 @@ class DemoDaemonComponent(ZenDaemonComponent):
"""
"""
daemon
.
queue
.
schedule
(
'
default
'
)
daemon
.
queue
.
schedule
(
'
default
'
)
daemon
.
logger
.
info
(
"
Working
"
)
daemon
.
logger
.
info
(
"
Working
"
)
self
.
inc_statistic
(
'
cnt_default
'
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
return
(
daemon
.
FLAG_CONTINUE
,
None
)
return
(
daemon
.
FLAG_CONTINUE
,
None
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment