def before(self):
     self.timer = Timer()
     self.profile = Mock(spec=Profile)
     for i in range(20):
         self.timer.record('runProfiler', 0.5)
     set_agent_config(sampling_interval_seconds=1, cpu_limit_percentage=10)
     self.process_duration_check = CpuUsageCheck(self.timer)
Esempio n. 2
0
 def _set_default_environment(profiling_group_name):
     return {
         'timer':
         Timer(),
         'profiler_thread_name':
         'codeguru-profiler-agent-' + str(uuid.uuid4()).replace('-', ''),
         'reporting_mode':
         'codeguru_service',
         'file_prefix':
         'profile-{}'.format(re.sub(r"\W", "", profiling_group_name)),
         'excluded_threads':
         set(),
         'should_profile':
         True,
         'sampling_interval':
         DEFAULT_SAMPLING_INTERVAL,
         'reporting_interval':
         DEFAULT_REPORTING_INTERVAL,
         'minimum_time_reporting':
         INITIAL_MINIMUM_REPORTING_INTERVAL,
         'max_stack_depth':
         DEFAULT_MAX_STACK_DEPTH,
         'cpu_limit_percentage':
         DEFAULT_CPU_LIMIT_PERCENTAGE,
         'memory_limit_bytes':
         DEFAULT_MEMORY_LIMIT_BYTES,
         'host_weight':
         1.0,
         'killswitch_filepath':
         KILLSWITCH_FILEPATH,
         'max_threads':
         100
     }
Esempio n. 3
0
        def test_metrics_get_reset(self):
            subject = Timer()
            subject.record("test-record", 10)

            subject.reset()

            assert (not "test-record" in subject.metrics)
 def before(self):
     self.timer = Timer()
     self.env = {
         'timer': self.timer,
         'killswitch_filepath': 'path_to_my_kill_switch',
         'memory_limit_bytes': DEFAULT_MEMORY_LIMIT_BYTES
     }
     self.disabler = ProfilerDisabler(self.env)
Esempio n. 5
0
 def before(self):
     self.timer = Timer()
     self.profile = Mock(spec=Profile)
     for i in range(20):
         self.timer.record('runProfiler', 0.5)
     set_agent_config(cpu_limit_percentage=9)
     self.process_duration_check = CpuUsageCheck(self.timer)
     self.profile.get_active_millis_since_start = Mock(return_value=100 *
                                                       1000)
    def test_it_returns_json_with_generic_metrics(self):
        timer = Timer()
        timer.record("metric1", 12345000)
        timer.record("metric1", 12350000)
        subject = AgentDebugInfo(timer=timer)

        serialized_json = subject.serialize_to_json()
        assert serialized_json["genericMetrics"] == {
            "metric1_timings_max": 12350000,
            "metric1_timings_average": 12347500.0
        }
Esempio n. 7
0
 def before(self):
     self.timer = Timer()
     self.profiler = Profiler(
         profiling_group_name=DUMMY_TEST_PROFILING_GROUP_NAME,
         environment_override={
             "timer": self.timer,
             "cpu_limit_percentage": 40,
             "sampling_interval": timedelta(seconds=0.01),
             'agent_metadata':
             AgentMetadata(fleet_info=DefaultFleetInfo())
         },
     )
     yield
     self.profiler.stop()
 def test_it_returns_false(self):
     self.process_duration_check.timer = Timer()
     assert not self.process_duration_check.is_cpu_usage_limit_reached()
Esempio n. 9
0
                    [Frame("bottom"), Frame("middle")]],
            attempted_sample_threads_count=10,
            seen_threads_count=15))
    profile.end = end_time
    profile.set_overhead_ms(timedelta(milliseconds=256))
    if platform.system() == "Windows":
        # In Windows, as time.process stays constant if no cpu time was used (https://bugs.python.org/issue37859), we
        # would need to manually override the cpu_time_seconds to ensure the test runs as expected
        profile.cpu_time_seconds = 0.123
    return profile


agent_metadata = AgentMetadata(fleet_info=AWSEC2Instance(
    host_name="testHostName", host_type="testHostType"))

environment = {"timer": Timer(), "agent_metadata": agent_metadata}


class TestSdkProfileEncoder:
    def before(self):
        self.profile = example_profile()
        self.output_stream = io.BytesIO()
        self.subject = \
            ProfileEncoder(gzip=False, environment=environment)
        self.decoded_json_result = self.decoded_json_result.__get__(self)
        self._decoded_json_result = None

    def decoded_json_result(self):
        if not self._decoded_json_result:
            self.subject.encode(profile=self.profile,
                                output_stream=self.output_stream)
 def __init__(self):
     self.timer = Timer()
Esempio n. 11
0
 def before(self):
     self.subject = Timer()
     self.subject.record("test-record", 10)
            seen_threads_count=15))
    profile.end = end_time
    profile.set_overhead_ms(timedelta(milliseconds=256))
    if platform.system() == "Windows":
        # In Windows, as time.process stays constant if no cpu time was used (https://bugs.python.org/issue37859), we
        # would need to manually override the cpu_time_seconds to ensure the test runs as expected
        profile.cpu_time_seconds = 0.123
    return profile


agent_metadata = AgentMetadata(fleet_info=AWSEC2Instance(
    host_name="testHostName", host_type="testHostType"))
errors_metadata = ErrorsMetadata()

environment = {
    "timer": Timer(),
    "agent_metadata": agent_metadata,
    "errors_metadata": errors_metadata
}


class TestSdkProfileEncoder:
    def before(self):
        self.profile = example_profile()
        self.output_stream = io.BytesIO()
        self.subject = \
            ProfileEncoder(gzip=False, environment=environment)
        self.decoded_json_result = self.decoded_json_result.__get__(self)
        self._decoded_json_result = None

    def decoded_json_result(self):