Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
3d6ec674
Commit
3d6ec674
authored
3 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Added msg-stats
parent
35c2d3a9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/msg_stats.py
+80
-0
80 additions, 0 deletions
scripts/msg_stats.py
with
80 additions
and
0 deletions
scripts/msg_stats.py
0 → 100644
+
80
−
0
View file @
3d6ec674
import
asyncio
import
time
from
xaal.lib
import
AsyncEngine
,
Message
,
MessageAction
MSG_STATS
=
{
"
total
"
:
0
,
"
alive
"
:
0
,
"
request_isalive
"
:
0
,
"
request
"
:
0
,
"
reply
"
:
0
,
"
get_description
"
:
0
,
"
get_attributes
"
:
0
,
"
attributes_change
"
:
0
,
"
notify
"
:
0
,
}
DEVICE_STATS
=
{}
def
count
(
msg
:
Message
):
msg_count
(
msg
)
device_count
(
msg
)
def
device_count
(
msg
:
Message
):
addr
=
msg
.
source
try
:
DEVICE_STATS
[
addr
]
+=
1
except
KeyError
:
DEVICE_STATS
[
addr
]
=
1
def
msg_count
(
msg
:
Message
):
# Count the number of messages received
MSG_STATS
[
"
total
"
]
+=
1
if
msg
.
is_request_isalive
():
MSG_STATS
[
"
request_isalive
"
]
+=
1
return
if
msg
.
is_alive
():
MSG_STATS
[
"
alive
"
]
+=
1
return
if
msg
.
is_reply
()
or
msg
.
is_request
():
# This msg is a get attribute or description type
if
msg
.
action
==
MessageAction
.
GET_ATTRIBUTES
.
value
:
MSG_STATS
[
"
get_attributes
"
]
+=
1
return
if
msg
.
action
==
MessageAction
.
GET_DESCRIPTION
.
value
:
MSG_STATS
[
"
get_description
"
]
+=
1
return
if
msg
.
is_request
():
# direct request / not isalive / not attributes / description
MSG_STATS
[
"
request
"
]
+=
1
if
msg
.
is_reply
():
MSG_STATS
[
"
reply
"
]
+=
1
if
msg
.
is_attributes_change
():
MSG_STATS
[
"
attributes_change
"
]
+=
1
if
msg
.
is_notify
():
MSG_STATS
[
"
notify
"
]
+=
1
async
def
show
():
t0
=
time
.
time
()
while
1
:
await
asyncio
.
sleep
(
5
)
t
=
time
.
time
()
-
t0
print
(
MSG_STATS
)
print
(
DEVICE_STATS
)
def
run
():
eng
=
AsyncEngine
()
eng
.
disable_msg_filter
()
eng
.
subscribe
(
count
)
eng
.
on_start
(
show
)
eng
.
run
()
if
__name__
==
"
__main__
"
:
run
()
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