This repository was archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
added performance metrics LabGraph issue 78 #88
Open
mark-nguyen1
wants to merge
1
commit into
facebookresearch:main
Choose a base branch
from
mark-nguyen1:MLHIssue78
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,5 @@ venv.bak/ | |
|
||
# Sphinx | ||
sphinx/_build/ | ||
*~ | ||
*~ | ||
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,16 @@ | |
import labgraph as lg | ||
import numpy as np | ||
import time | ||
import random | ||
from .random_message import RandomMessage | ||
from datetime import datetime | ||
from time import perf_counter | ||
from collections import deque | ||
|
||
|
||
data = deque() | ||
throughput_data = "" | ||
datarate_data = "" | ||
one_second_must_pass = perf_counter() | ||
class AmplifierConfig(lg.Config): | ||
out_in_ratio: float | ||
|
||
|
@@ -22,10 +29,35 @@ def output(self, _in: float) -> float: | |
@lg.subscriber(AMPLIFIER_INPUT) | ||
@lg.publisher(AMPLIFIER_OUTPUT) | ||
async def amplify(self, message: RandomMessage) -> lg.AsyncPublisher: | ||
current_time = time.time() | ||
global data | ||
global throughput_data | ||
global datarate_data | ||
global one_second_must_pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try to avoid using global here. |
||
|
||
current_time_UTC = str(datetime.utcnow()) + " (UTC)" | ||
start_time = perf_counter() | ||
# timestamp_data = time.time() | ||
output_data = np.array( | ||
[self.output(_in) for _in in message.data] | ||
) | ||
|
||
|
||
data.append(message.data.size * message.data.itemsize) | ||
if perf_counter() - one_second_must_pass >= 1: | ||
tempThroughput = 0 | ||
tempDataRate = 0 | ||
for messagedata in data: | ||
tempThroughput += messagedata | ||
tempDataRate += 1.0 | ||
throughput_data = str(tempThroughput) + " bytes" | ||
datarate_data = str(tempDataRate) + " msg/sec" | ||
data.clear() | ||
one_second_must_pass = perf_counter() | ||
|
||
latency_data = str(perf_counter() - start_time) + " s" | ||
yield self.AMPLIFIER_OUTPUT, RandomMessage( | ||
timestamp=current_time, data=output_data | ||
timestamp=current_time_UTC, data=output_data, latency=latency_data, throughput=throughput_data, datarate=datarate_data | ||
) | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,23 @@ | |
import labgraph as lg | ||
import numpy as np | ||
import time | ||
import random | ||
from .random_message import RandomMessage | ||
from datetime import datetime | ||
from time import perf_counter | ||
from collections import deque | ||
|
||
data = deque() | ||
throughput_data = "" | ||
datarate_data = "" | ||
one_second_must_pass = perf_counter() | ||
|
||
class AttenuatorConfig(lg.Config): | ||
attenuation: float | ||
|
||
|
||
class CustomMessage(RandomMessage): | ||
latency: float | ||
|
||
class Attenuator(lg.Node): | ||
ATTENUATOR_INPUT = lg.Topic(RandomMessage) | ||
ATTENUATOR_OUTPUT = lg.Topic(RandomMessage) | ||
|
@@ -22,10 +32,33 @@ def output(self, _in: float) -> float: | |
@lg.subscriber(ATTENUATOR_INPUT) | ||
@lg.publisher(ATTENUATOR_OUTPUT) | ||
async def attenuate(self, message: RandomMessage) -> lg.AsyncPublisher: | ||
current_time = time.time() | ||
global data | ||
global throughput_data | ||
global datarate_data | ||
global one_second_must_pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for global. |
||
|
||
start_time = perf_counter() | ||
current_time_UCT = str(datetime.utcnow()) + " (UTC)" | ||
output_data = np.array( | ||
[self.output(_in) for _in in message.data] | ||
) | ||
|
||
data.append(message.data.size * message.data.itemsize) | ||
if perf_counter() - one_second_must_pass >= 1: | ||
tempThroughput = 0 | ||
tempDataRate = 0 | ||
for messagedata in data: | ||
tempThroughput += messagedata | ||
tempDataRate += 1.0 | ||
throughput_data = str(tempThroughput) + " bytes" | ||
datarate_data = str(tempDataRate) + " msg/sec" | ||
data.clear() | ||
one_second_must_pass = perf_counter() | ||
|
||
latency_data = str(perf_counter() - start_time) + " s" | ||
yield self.ATTENUATOR_OUTPUT, RandomMessage( | ||
timestamp=current_time, data=output_data | ||
timestamp=current_time_UCT, data=output_data, latency=latency_data,throughput=throughput_data, datarate=datarate_data | ||
) | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, deque can be replaced by a more performant buffer data structure.