Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cb1d416
Update python-package.yml
henryhuynh210 Jan 9, 2024
d3ec153
Update python-package.yml
henryhuynh210 Jan 9, 2024
32c757d
Update test_with_timer.py
henryhuynh210 Jan 9, 2024
a555fd9
Update python-package.yml
henryhuynh210 Jan 17, 2024
3d021e8
Update test_with_timer.py
henryhuynh210 Jan 17, 2024
24b122a
Update python-package.yml
henryhuynh210 Jan 17, 2024
1ce548e
Exclude ubuntu 3.6 python-package.yml since arch x86 is not supported
henryhuynh210 Jan 17, 2024
98c0f1c
Update test_with_timer.py
henryhuynh210 Jan 17, 2024
2714ca5
Update python-package.yml
henryhuynh210 Jan 17, 2024
86040ce
Update python-package.yml
henryhuynh210 Jan 17, 2024
0227dd3
Windows does not have sys.set_int_max_str_digits until 3.10
henryhuynh210 Jan 17, 2024
69f94ba
Update test_with_timer.py
henryhuynh210 Jan 17, 2024
cf49aae
Update test_with_timer.py
henryhuynh210 Jan 17, 2024
45bed74
Update test_sampler.py
henryhuynh210 Jan 17, 2024
5d5fc49
Update test_sampler.py
henryhuynh210 Jan 17, 2024
6e48e49
Update test_sampler.py
henryhuynh210 Jan 17, 2024
6ecdacf
Update test_sampler.py
henryhuynh210 Jan 17, 2024
dd0aee8
Update test_sampler.py
henryhuynh210 Jan 17, 2024
03e318d
Update test_sampler.py
henryhuynh210 Jan 17, 2024
15f7559
Update test_sampler.py
henryhuynh210 Jan 17, 2024
fb0b308
Update sampler.py for Python 3.11
henryhuynh210 Jan 17, 2024
fadfa88
Fix spacing sampler.py
henryhuynh210 Jan 17, 2024
6d8de2a
Fix spacing pt. 2 sampler.py
henryhuynh210 Jan 17, 2024
1066ee5
Update test_sampler.py
henryhuynh210 Jan 17, 2024
63b5f41
Update test_sampler.py
henryhuynh210 Jan 17, 2024
ba0e266
Update test_sampler.py
henryhuynh210 Jan 17, 2024
add96d4
Update test_with_timer.py
henryhuynh210 Jan 17, 2024
3051286
Update sampler.py
henryhuynh210 Jan 17, 2024
3851301
Temp debug change for test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
5914eb9
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
ec7dd34
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
b4450ea
revert test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
5f7198a
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
daca418
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
60bd4ea
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
74aeacf
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
65dd32c
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
711c18b
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
ecbfc53
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
3d61100
Update test_live_backend_reporting.py
henryhuynh210 Jan 18, 2024
560ed1a
Update test_live_backend_reporting.py
henryhuynh210 Jan 18, 2024
d966866
Update test_live_backend_reporting.py
henryhuynh210 Jan 18, 2024
522eafc
Update test_live_backend_reporting.py
henryhuynh210 Jan 18, 2024
1f5e029
Update test_live_backend_reporting.py
henryhuynh210 Jan 18, 2024
576e05b
Update test_end_to_end_profile_and_save_to_file.py
henryhuynh210 Jan 18, 2024
897452d
Revert temp changes done for debugging
henryhuynh210 Jan 18, 2024
6ded19e
Set last_frame_line_no to -1 if it's None. Tie ubuntu to version 20.0…
jpalevic-amazon Feb 8, 2024
b5e6d5c
Set ubuntu to ubuntu-latest
jpalevic-amazon Feb 8, 2024
77d4c2b
revert to initial branch state from henry's branch to see if tests pa…
jpalevic-amazon Feb 9, 2024
00d7c0d
Add sleep to see if this fixes failing 2 tests
jpalevic-amazon Feb 9, 2024
2eae10b
Use ubuntu-20.04 instead of ubuntu-latest, update workflows to latest…
jpalevic-amazon Feb 13, 2024
b268bb1
push github workflow changes
jpalevic-amazon Feb 13, 2024
a7e5b14
Log socket name for 3.11 macos and ubuntu integ tests which shouldn't…
jpalevic-amazon Feb 13, 2024
1d99f85
Log socket correctly
jpalevic-amazon Feb 13, 2024
ab937d4
Skip test/integration/test_live_backend_reporting.py if run on GitHub
jpalevic-amazon Feb 13, 2024
3e3ae21
Clear static profiler from decorator after profiler decorator unit tests
jpalevic-amazon Feb 14, 2024
d7cba56
add logging to debug test
jpalevic-amazon Feb 14, 2024
4938b3d
format string
jpalevic-amazon Feb 14, 2024
befeea6
format string
jpalevic-amazon Feb 14, 2024
4c154cb
add sleep between start and stop
jpalevic-amazon Feb 14, 2024
f1cfbd8
add additional prints
jpalevic-amazon Feb 15, 2024
a325e49
log actual end time
jpalevic-amazon Feb 15, 2024
9c01941
switch to logger
jpalevic-amazon Feb 15, 2024
bfc36cc
fix logging
jpalevic-amazon Feb 15, 2024
b30fbab
fix logging
jpalevic-amazon Feb 15, 2024
e4be842
fix logging
jpalevic-amazon Feb 15, 2024
d5fe96c
Add 2 second sleep to see if time.time changes
jpalevic-amazon Feb 15, 2024
998a626
lengthen test time
jpalevic-amazon Feb 15, 2024
9caf52e
clean up file diff
jpalevic-amazon Feb 15, 2024
16e40b0
add short sleep to test handler function
jpalevic-amazon Feb 15, 2024
3ff0845
Clean up commits
jpalevic-amazon Feb 15, 2024
e642706
More formatting
jpalevic-amazon Feb 15, 2024
0267997
Resolve last last_frame_line_no == None issue
jpalevic-amazon Feb 15, 2024
851a3b1
Adjust github workflows
jpalevic-amazon Feb 15, 2024
dbddce3
fix python-package.yml
jpalevic-amazon Feb 15, 2024
a90c590
Update agent version and Changelog
jpalevic-amazon Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ jobs:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.6', '3.7', '3.8', '3.9']
os: [ubuntu-20.04, ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
exclude:
- os: ubuntu-latest
python-version: '3.6'
- os: ubuntu-20.04
python-version: '3.7'
- os: ubuntu-20.04
python-version: '3.8'
- os: ubuntu-20.04
python-version: '3.9'
- os: ubuntu-20.04
python-version: '3.10'
- os: ubuntu-20.04
python-version: '3.11'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install pip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish-live.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
CHANGELOG
=========

1.2.5 (layer_v12)
===================
* Fix bug which causes agent to crash if line_no was None.

1.2.4 (layer_v11)
===================
* Updated lambda bootstrap code to support profiling python 3.9 lambda functions.

1.2.3 (layer_v10)
===================
* Fix bug to sent agent overhead in the rigth format: int and as part of memoryInMB (instead of the previous string as part of memory_usage_mb).
* Fix bug to sent agent overhead in the right format: int and as part of memoryInMB (instead of the previous string as part of memory_usage_mb).

1.2.2 (layer_v9)
===================
Expand Down
2 changes: 1 addition & 1 deletion codeguru_profiler_agent/agent_metadata/agent_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# NOTE: Please do not alter the value for the following constants without the full knowledge of the use of them.
# These constants are used in several scripts, including setup.py.
__agent_name__ = "CodeGuruProfiler-python"
__agent_version__ = "1.2.4"
__agent_version__ = "1.2.5"


def look_up_fleet_info(
Expand Down
6 changes: 4 additions & 2 deletions codeguru_profiler_agent/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def sample(self):
seen_threads_count=all_threads_count)

def _get_all_threads(self):
return self._thread_lister._current_frames().items()
return list(self._thread_lister._current_frames().items())

def _threads_to_sample_from(self, all_threads):
if len(all_threads) > self._max_threads:
if isinstance(all_threads, dict):
all_threads = list(all_threads.keys())
return random.sample(all_threads, self._max_threads)
else:
return all_threads
return list(all_threads)
5 changes: 4 additions & 1 deletion codeguru_profiler_agent/sampling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def _extract_stack(stack, max_depth):
)
if len(result) < max_depth:
last_frame, last_frame_line_no = stack[-1]
_maybe_append_synthetic_frame(result, last_frame, last_frame_line_no)
# If the line_no is None, ignore the line as we can't get the line
# of code from the line cache
if last_frame_line_no != None:
_maybe_append_synthetic_frame(result, last_frame, last_frame_line_no)
return result[:max_depth]


Expand Down
11 changes: 9 additions & 2 deletions test/acceptance/test_end_to_end_profile_and_save_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import tempfile
import os
import time

from datetime import timedelta
from unittest.mock import patch
Expand Down Expand Up @@ -56,14 +57,15 @@ def test_it_samples_and_saves_a_profile_to_a_file(self):
profiler = Profiler(
profiling_group_name=DUMMY_TEST_PROFILING_GROUP_NAME,
environment_override={
"initial_sampling_interval": timedelta(),
"initial_sampling_interval": timedelta(seconds=1),
"reporting_mode": "file",
"file_prefix": file_prefix,
'agent_metadata': AgentMetadata(fleet_info=DefaultFleetInfo())
})

try:
profiler.start()
time.sleep(2)
finally:
profiler.stop()

Expand All @@ -74,7 +76,12 @@ def test_it_samples_and_saves_a_profile_to_a_file(self):
os.listdir(self.temporary_directory)[0]))

with (open(resulting_profile_path)) as profiling_result_file:
resulting_json = json.loads(profiling_result_file.read())
file_content = profiling_result_file.read()

try:
resulting_json = json.loads(file_content)
except json.JSONDecodeError as e:
raise

self.assert_valid_agent_metadata(resulting_json["agentMetadata"])
assert test_start_time <= resulting_json["start"] <= resulting_json["end"] <= test_end_time
Expand Down
6 changes: 3 additions & 3 deletions test/integration/test_live_backend_reporting.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import boto3
import pytest
import socket
import os
import time
import platform

from datetime import timedelta

Expand All @@ -19,8 +20,7 @@


@pytest.mark.skipif(
socket.getfqdn().endswith("internal.cloudapp.net"), # hosts running ubuntu and windows in GitHub
socket.getfqdn().endswith("ip6.arpa"), # hosts running macs in GitHub
os.getenv("GITHUB_ACTIONS") == "true",
reason="This integration test is skipped on any shared fleet from Amazon or GitHub "
"because it needs credentials to access the backend service. "
"For information on how to run this locally, read the README.md file from the test/integration/ folder.")
Expand Down
3 changes: 3 additions & 0 deletions test/unit/aws_lambda/test_profiler_decorator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import time
import codeguru_profiler_agent.aws_lambda.profiler_decorator

from unittest.mock import MagicMock
Expand Down Expand Up @@ -77,11 +78,13 @@ def around(self):
@with_lambda_profiler(profiling_group_name="pg_name", region_name="eu-north-1",
environment_override={'cpu_limit_percentage': 42}, env=self.env)
def handler_function(event, context):
time.sleep(0.5)
return True

self.handler = handler_function
yield \
codeguru_profiler_agent.aws_lambda.profiler_decorator.clear_static_profiler()
codeguru_profiler_agent.aws_lambda.profiler_decorator.clear_static_profiler()

def test_given_profiling_group_is_used(self):
self.handler({}, self.context)
Expand Down
8 changes: 7 additions & 1 deletion test/unit/metrics/test_with_timer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import platform
import sys
from test.pytestutils import before

from codeguru_profiler_agent.metrics.with_timer import with_timer
Expand All @@ -12,9 +14,13 @@ def __init__(self):
def foo_wall(self):
return

# Run something to make sure the cpu clock does tick (https://bugs.python.org/issue37859)
@with_timer(metric_name="test-foo-cpu", measurement="cpu-time")
def foo_cpu(self):
# Run something to make sure the cpu clock does tick (https://bugs.python.org/issue37859)
# Call set_int_max_str for specific versions to test as its limited to resolve CVE-2020-10735
# (https://docs.python.org/3/library/stdtypes.html#integer-string-conversion-length-limitation)
if (sys.version_info >= (3, 7) and platform.system() != 'Windows') or (sys.version_info >= (3, 10) and platform.system() == 'Windows'):
sys.set_int_max_str_digits(0)
len(str(2 ** 500_000))
return

Expand Down
23 changes: 5 additions & 18 deletions test/unit/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,35 @@ def test_it_calls_the_get_stacks_method_with_the_current_threads_and_the_default
sampler.sample()

self.mock_get_stacks.assert_called_once_with(
threads_to_sample=self._current_frames_reply.items(),
threads_to_sample=ANY,
excluded_threads=default_excluded_threads,
max_depth=default_max_depth,
)


class TestWhenThereAreMoreThreadsThanMaxThreads(TestSampler):
@before
def before(self):
super().before()
self.environment["max_threads"] = 1
self.subject = Sampler(environment=self.environment)

def test_it_calls_the_get_stacks_method_with_a_subset_of_the_threads(
self):
def test_it_calls_the_get_stacks_method_with_a_subset_of_the_threads(self):
self.subject.sample()

allowed_results = [
mock.call(
threads_to_sample=[("fake_thread_1",
"fake_thread_frames_1")],
threads_to_sample=list([("fake_thread_1", "fake_thread_frames_1")]),
excluded_threads=ANY,
max_depth=ANY,
),
mock.call(
threads_to_sample=[("fake_thread_2",
"fake_thread_frames_2")],
threads_to_sample=list([("fake_thread_2", "fake_thread_frames_2")]),
excluded_threads=ANY,
max_depth=ANY,
),
]

assert (self.mock_get_stacks.call_args in allowed_results)

def test_it_includes_the_number_of_threads_it_attempted_to_sample_and_how_many_in_total_were_seen_in_the_system(
self):
self.mock_get_stacks.result = [["dummy_stack_sample"]]

result = self.subject.sample()

assert (result.attempted_sample_threads_count == 1)
assert (result.seen_threads_count == 2)
assert self.mock_get_stacks.call_args in allowed_results


class TestWhenACustomStackDepthLimitIsSpecified(TestSampler):
Expand Down