Skip to content

Commit c0f4bf4

Browse files
Merge pull request #42 from aws/fix_agent_overhead_format
Send agent overhead values as int
2 parents 33d230d + b2a3e69 commit c0f4bf4

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

codeguru_profiler_agent/agent_metadata/agent_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def fleet_info(self):
6969
def serialize_to_json(self, sample_weight, duration_ms, cpu_time_seconds,
7070
average_num_threads, overhead_ms, memory_usage_mb, total_sample_count):
7171
"""
72-
This needs to be compliant with agent profile schema.
72+
This needs to be compliant with the AgentMetadata schema that is used on the service side.
7373
"""
7474
if self.json_rep is None:
7575
self.json_rep = {
@@ -83,7 +83,7 @@ def serialize_to_json(self, sample_weight, duration_ms, cpu_time_seconds,
8383
"version": self.agent_info.version
8484
},
8585
"agentOverhead": {
86-
"memory_usage_mb": memory_usage_mb
86+
"memoryInMB": int(memory_usage_mb)
8787
},
8888
"runtimeVersion": self.runtime_version,
8989
"cpuTimeInSeconds": cpu_time_seconds,
@@ -93,5 +93,5 @@ def serialize_to_json(self, sample_weight, duration_ms, cpu_time_seconds,
9393
"numTimesSampled": total_sample_count
9494
}
9595
if overhead_ms != 0:
96-
self.json_rep["agentOverhead"]["timeInMs"] = overhead_ms
96+
self.json_rep["agentOverhead"]["timeInMs"] = int(overhead_ms)
9797
return self.json_rep

test/acceptance/test_end_to_end_profile_and_save_to_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def assert_valid_agent_metadata(agent_metadata):
9292
assert agent_metadata["agentOverhead"]
9393
assert agent_metadata["durationInMs"]
9494
assert agent_metadata["sampleWeights"]["WALL_TIME"]
95-
assert agent_metadata["agentOverhead"]["memory_usage_mb"]
95+
assert type(agent_metadata["agentOverhead"]["memoryInMB"]) is int
9696

9797
if platform.system() != "Windows":
9898
# Due to the issue mentioned on https://bugs.python.org/issue37859, we would skip checking agentOverhead for
9999
# Windows system as the agent is only run for very short period of time. We may improve the accuracy of
100100
# measuring the overhead by using time.perf_counter_ns for Windows in the future.
101-
assert agent_metadata["agentOverhead"]["timeInMs"]
101+
assert type(agent_metadata["agentOverhead"]["timeInMs"]) is int
102102
assert agent_metadata["cpuTimeInSeconds"] > 0

test/unit/sdk_reporter/test_sdk_profile_encoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def example_profile():
3131
[Frame("bottom"), Frame("middle"), Frame("different_top")],
3232
[Frame("bottom"), Frame("middle")]], attempted_sample_threads_count=10, seen_threads_count=15))
3333
profile.end = end_time
34-
profile.set_overhead_ms(timedelta(milliseconds=256))
34+
profile.set_overhead_ms(timedelta(microseconds=256123))
3535
if platform.system() == "Windows":
3636
# In Windows, as time.process stays constant if no cpu time was used (https://bugs.python.org/issue37859), we
3737
# would need to manually override the cpu_time_seconds to ensure the test runs as expected
@@ -122,7 +122,7 @@ def test_it_includes_the_overhead_ms_in_the_agent_metadata(self):
122122
assert (self.decoded_json_result()["agentMetadata"]["agentOverhead"]["timeInMs"] == 256)
123123

124124
def test_it_includes_the_memory_overhead_in_the_agent_metadata(self):
125-
assert (self.decoded_json_result()["agentMetadata"]["agentOverhead"]["memory_usage_mb"] > 0)
125+
assert (type(self.decoded_json_result()["agentMetadata"]["agentOverhead"]["memoryInMB"]) is int)
126126

127127
def test_it_includes_the_num_times_sampled_in_the_agent_metadata(self):
128128
assert (self.decoded_json_result()["agentMetadata"]["numTimesSampled"] > 0)

0 commit comments

Comments
 (0)