Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Simulation] Add energy analysis with exporting commands and chart visualization #235

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Vinggui
Copy link
Contributor

@Vinggui Vinggui commented Mar 23, 2022

Contribution description

This PR adds energy analysis (including charts), transmission timings, and collision analysis support to the OTNS. It is, however, compatible with the current version of the Openthread/Openthread simulated device.

This PR also introduces:

  • A new CLI called energy save [output name], allowing the user to store the energy results obtained out of their simulation;
  • A new button called "Open Charts" in the Action bar of the web interface. It opens a new browser tab which does not interfere with the PIXI interface. This tab contains
    3 charts: Energy consumption history, energy consumption by radio state and node ID, and power consumption.

This energy simulation is based on the STM32WB55rg at 3.3V:

	RadioDisabledConsumption float64 = 0.00011 //To be confirmed
	RadioTxConsumption       float64 = 0.01716 //5.2 mA
	RadioRxConsumption       float64 = 0.01485 //4.5 mA
	RadioIdleConsumption     float64 = 0.01485 //4.5 mA

Main modifications

  • A new energy analysis module (Go);
  • An extended PROTO service that provides a streaming API to the new char tab;
  • A new HTML file using Chart.js and the extended gRPC service;
  • Some re-wiring on the existent go modules, to include the energy analysis module;
  • New event type providing TxDone callbacks that consider transmission times to the simulated device;
  • New style of simplelogger.Debugf "status push", showing the simulated time;
  • New event type that allows simulated devices to do Clear Channel Assessment (with future possibility to provide scanning and RSSI model into the simulation);
  • New event type eventTypeRadioComm = 6 that will substitute eventTypeRadioReceived = 1. At the moment, both types are used to keep compatibility between the new changes of PR #7500 and the current OpenThread version, respectively.

Needs check/review

I believe that the modifications should not impact any other OTNS' functionalities, but I could not yet test some of them, for example:

  • Real devices integrated to the simulator;
  • Replay;
  • Python commands.

If you please have easy access to it, send me feedback.

Requirements

None (if intended to be used with current Openthread repository). But, there is another PR #7500 in Openthread repository that allows all the new features in the simulation to work.

Testing procedure

Just install OTNS the same way as before, using the "OTNS=1" for the building parameter.

To obtain the energy results, just use the command energy save, but if you want a specific name for the files, use energy save "name"

@lgtm-com
Copy link

lgtm-com bot commented Mar 23, 2022

This pull request introduces 3 alerts and fixes 1 when merging 1e0f326 into 941d6e2 - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class
  • 1 for Reflected cross-site scripting

fixed alerts:

  • 1 for Incorrect conversion between integer types

@lgtm-com
Copy link

lgtm-com bot commented Mar 23, 2022

This pull request introduces 1 alert and fixes 1 when merging 50adc82 into 941d6e2 - view on LGTM.com

new alerts:

  • 1 for Reflected cross-site scripting

fixed alerts:

  • 1 for Incorrect conversion between integer types

@Vinggui

This comment was marked as resolved.

@lgtm-com
Copy link

lgtm-com bot commented Mar 29, 2022

This pull request introduces 1 alert and fixes 1 when merging 7258257 into 941d6e2 - view on LGTM.com

new alerts:

  • 1 for Reflected cross-site scripting

fixed alerts:

  • 1 for Incorrect conversion between integer types

Copy link
Member

@simonlingoogle simonlingoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a very brief review of the code. The overall structure seems good to me.

One major concern might be why do we need an extra streaming RPC for energy report?
I wonder if Visualize RPC should also send energy-related events.

cli/ast.go Outdated Show resolved Hide resolved
@@ -230,7 +232,7 @@ loop:
select {
case f := <-d.taskChan:
f()
break
// break //ineffective break statement. Did you mean to break out of the outer loop?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a redundant break.
I think it's added to be more readable for C/C++ readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I was fixing some warnings with it. I don't mind leaving, but for that C/C++ readers, a simple comment like that also solves the issue, without adding warnings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it cause warning ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked again, and those warnings were actually pointed by VS Code. I believe that VS Code got it right anyway, a commented break is as useful and visually representative as an unnecessary break.

web/site/templates/chartsViewer.html Outdated Show resolved Hide resolved
web/site/templates/chartsViewer.html Outdated Show resolved Hide resolved
web/site/site.go Outdated Show resolved Hide resolved
web/site/js/chartsViewer.js Outdated Show resolved Hide resolved
visualize/nopVisualizer.go Outdated Show resolved Hide resolved
visualize/multi/multiVisualizer.go Outdated Show resolved Hide resolved
@@ -217,6 +231,7 @@ service VisualizeGrpcService {
// rpc Echo (EchoRequest) returns (EchoResponse);
rpc Visualize (VisualizeRequest) returns (stream VisualizeEvent);
rpc Command (CommandRequest) returns (CommandResponse);
rpc EnergyReport (VisualizeRequest) returns (stream NetworkEnergyEvent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need an extra GRPC streaming interface? Visualize should just work?

Copy link
Contributor Author

@Vinggui Vinggui Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One major concern might be why do we need an extra streaming RPC for energy report? I wonder if Visualize RPC should also send energy-related events.

I decided to create a new RPC stream to detach the streamed objects from what is used by the visualize.js. It looks to me that splitting both streams is the correct approach to what this "API" is serving each clients' necessity.

Not only that, but visualizer.js filters each streamed object for every callback it receives. Using the same streaming interface would increase unnecessary filtering in both visualizer.js and energyViewer.js.

I don't see a reason to merge them together, but please let me know if I did not evaluate it correctly.

visualize/grpc/grpcVisualizer.go Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Mar 30, 2022

This pull request introduces 1 alert and fixes 1 when merging 3e23d29 into 8da999e - view on LGTM.com

new alerts:

  • 1 for Reflected cross-site scripting

fixed alerts:

  • 1 for Incorrect conversion between integer types

@lgtm-com
Copy link

lgtm-com bot commented Mar 30, 2022

This pull request introduces 1 alert and fixes 1 when merging ad023ac into 8da999e - view on LGTM.com

new alerts:

  • 1 for Reflected cross-site scripting

fixed alerts:

  • 1 for Incorrect conversion between integer types

@lgtm-com
Copy link

lgtm-com bot commented Mar 31, 2022

This pull request introduces 1 alert and fixes 1 when merging c642beb into 8da999e - view on LGTM.com

new alerts:

  • 1 for Reflected cross-site scripting

fixed alerts:

  • 1 for Incorrect conversion between integer types

@Vinggui
Copy link
Contributor Author

Vinggui commented Mar 31, 2022

I realized one big problem in this simulated energy measurements: the transmission times are not simulated. So, we don't get the right timing spent on transmission state.

Update:
@simonlingoogle, I got transmission timing working, and collision model implemented too. Please, consider reviewing again both PR #7500 and this one. I think I made a good contribution here.

@Vinggui Vinggui changed the title Added energy analysis to the simulator, with exporting commands and chart visualization [Simulation] Add energy analysis with exporting commands and chart visualization May 5, 2022
@Vinggui Vinggui requested a review from simonlingoogle May 5, 2022 20:28
@codecov-commenter
Copy link

codecov-commenter commented May 7, 2022

Codecov Report

Merging #235 (a7729bb) into main (7d96f58) will decrease coverage by 3.80%.
The diff coverage is 11.31%.

@@            Coverage Diff             @@
##             main     #235      +/-   ##
==========================================
- Coverage   49.93%   46.12%   -3.81%     
==========================================
  Files          38       40       +2     
  Lines        4604     5058     +454     
==========================================
+ Hits         2299     2333      +34     
- Misses       2123     2535     +412     
- Partials      182      190       +8     
Impacted Files Coverage Δ
cli/CmdRunner.go 22.62% <0.00%> (-0.51%) ⬇️
cli/ast.go 66.66% <ø> (ø)
types/types.go 65.38% <ø> (ø)
visualize/grpc/grpcStream.go 50.00% <0.00%> (-50.00%) ⬇️
visualize/multi/multiVisualizer.go 0.00% <0.00%> (ø)
visualize/nopVisualizer.go 50.00% <ø> (ø)
visualize/types.go 17.39% <ø> (ø)
web/site/bindata.go 99.01% <ø> (+0.01%) ⬆️
visualize/grpc/pb/visualize_grpc.pb.go 18.00% <1.92%> (-1.42%) ⬇️
dispatcher/dispatcher.go 48.22% <5.26%> (-8.88%) ⬇️
... and 10 more

@lgtm-com
Copy link

lgtm-com bot commented May 7, 2022

This pull request introduces 2 alerts when merging eb6d545 into 8b7655f - view on LGTM.com

new alerts:

  • 1 for Incorrect conversion between integer types
  • 1 for Reflected cross-site scripting

@lgtm-com
Copy link

lgtm-com bot commented May 7, 2022

This pull request fixes 1 alert when merging 0bc5318 into 8b7655f - view on LGTM.com

fixed alerts:

  • 1 for Reflected cross-site scripting

@lgtm-com
Copy link

lgtm-com bot commented May 9, 2022

This pull request fixes 1 alert when merging a7729bb into 7d96f58 - view on LGTM.com

fixed alerts:

  • 1 for Reflected cross-site scripting

@lgtm-com
Copy link

lgtm-com bot commented Jun 30, 2022

This pull request fixes 1 alert when merging 31e9e06 into 4616010 - view on LGTM.com

fixed alerts:

  • 1 for Reflected cross-site scripting

@lgtm-com
Copy link

lgtm-com bot commented Sep 19, 2022

This pull request fixes 1 alert when merging c3a61f8 into 0ab7444 - view on LGTM.com

fixed alerts:

  • 1 for Reflected cross-site scripting

@Vinggui Vinggui marked this pull request as draft September 19, 2022 18:25
@lgtm-com
Copy link

lgtm-com bot commented Sep 19, 2022

This pull request fixes 1 alert when merging ae7a872 into 0ab7444 - view on LGTM.com

fixed alerts:

  • 1 for Reflected cross-site scripting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants