Skip to content

Commit cca9d6c

Browse files
committed
Send agent overhead values as int
We are currently sending the `memory_usage_mb` and `timeInMs` fields in the agent overhead metadata, unfortunately the schema for those is INT which means they are currently discarded when the profile is validated at submission time. This does not prevent profiles from being accepted but we lose the overhead data which means we will not show it in the UI. This change converts them to int before we serialize the report. It would be nice for the backend to accept decimals at least for the memory since it is in MB and we may often be under 1MB. But at the moment it is better to align to current schema.
1 parent 33d230d commit cca9d6c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

codeguru_profiler_agent/agent_metadata/agent_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
"memory_usage_mb": 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"]["memory_usage_mb"]) 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"]["memory_usage_mb"]) 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)