def test_block_profile(self): if runtime_info.OS_WIN or not min_version(3, 4): return stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', auto_profiling = False, debug = True ) messages = [] def add_mock(topic, message): messages.append(message) agent.message_queue.add = add_mock agent.start_block_profiler() def blocking_call(): time.sleep(0.1) for i in range(5): blocking_call() agent.stop_block_profiler() self.assertTrue('blocking_call' in str(messages)) agent.destroy()
def test_block_profile(self): if runtime_info.OS_WIN or not min_version(3, 4): return stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', auto_profiling = False, debug = True ) messages = [] def add_mock(topic, message): messages.append(message) agent.message_queue.add = add_mock agent.start_block_profiler() def blocking_call(): time.sleep(0.1) for i in range(5): blocking_call() agent.stop_block_profiler() self.assertTrue('blocking_call' in str(messages)) agent.destroy()
def test_allocation_profile(self): if runtime_info.OS_WIN or not min_version(3, 4): return stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', auto_profiling = False, debug = True ) messages = [] def add_mock(topic, message): messages.append(message) agent.message_queue.add = add_mock agent.start_allocation_profiler() mem1 = [] for i in range(0, 1000): obj1 = {'v': random.randint(0, 1000000)} mem1.append(obj1) agent.stop_allocation_profiler() self.assertTrue('agent_test.py' in str(messages)) agent.destroy()
def test_allocation_profile(self): if runtime_info.OS_WIN or not min_version(3, 4): return stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', auto_profiling = False, debug = True ) messages = [] def add_mock(topic, message): messages.append(message) agent.message_queue.add = add_mock agent.start_allocation_profiler() mem1 = [] for i in range(0, 1000): obj1 = {'v': random.randint(0, 1000000)} mem1.append(obj1) agent.stop_allocation_profiler() self.assertTrue('agent_test.py' in str(messages)) agent.destroy()
def test_record_allocation_profile(self): if runtime_info.OS_WIN or not min_version(3, 4): return stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', auto_profiling = False, debug = True ) agent.allocation_reporter.profiler.reset() mem1 = [] def mem_leak(n = 100000): mem2 = [] for i in range(0, n): mem1.append(random.randint(0, 1000)) mem2.append(random.randint(0, 1000)) def mem_leak2(): mem_leak() def mem_leak3(): mem_leak2() def mem_leak4(): mem_leak3() def mem_leak5(): mem_leak4() result = {} def record(): agent.allocation_reporter.profiler.start_profiler() time.sleep(2) agent.allocation_reporter.profiler.stop_profiler() t = threading.Thread(target=record) t.start() # simulate leak mem_leak5() t.join() profile = agent.allocation_reporter.profiler.build_profile(2)[0]['profile'].to_dict() #print(str(profile)) self.assertTrue('allocation_profiler_test.py' in str(profile)) agent.destroy()
def test_record_allocation_profile(self): if not min_version(3, 4): return stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', debug = True ) mem1 = [] def mem_leak(n = 100000): mem2 = [] for i in range(0, n): mem1.append(random.randint(0, 1000)) mem2.append(random.randint(0, 1000)) def mem_leak2(): mem_leak() def mem_leak3(): mem_leak2() def mem_leak4(): mem_leak3() def mem_leak5(): mem_leak4() result = {} def record(): agent.allocation_reporter.record(2) t = threading.Thread(target=record) t.start() # simulate leak mem_leak5() t.join() #print(agent.allocation_reporter.profile) self.assertTrue('allocation_reporter_test.py' in str(agent.allocation_reporter.profile)) agent.destroy()
def test_report(self): stackimpact._agent = None agent = stackimpact.start(dashboard_address='http://localhost:5001', agent_key='key1', app_name='TestPythonApp', debug=True) agent.process_reporter.start() agent.process_reporter.report() time.sleep(0.1) agent.process_reporter.report() metrics = agent.process_reporter.metrics if not runtime_info.OS_WIN: self.is_valid(metrics, Metric.TYPE_COUNTER, Metric.CATEGORY_CPU, Metric.NAME_CPU_TIME, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_CPU, Metric.NAME_CPU_USAGE, 0, float("inf")) if not runtime_info.OS_WIN: self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_MAX_RSS, 0, float("inf")) if runtime_info.OS_LINUX: self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_CURRENT_RSS, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_VM_SIZE, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_GC, Metric.NAME_GC_COUNT, 0, float("inf")) if min_version(3, 4): self.is_valid(metrics, Metric.TYPE_COUNTER, Metric.CATEGORY_GC, Metric.NAME_GC_COLLECTIONS, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_COUNTER, Metric.CATEGORY_GC, Metric.NAME_GC_COLLECTED, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_GC, Metric.NAME_GC_UNCOLLECTABLE, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_RUNTIME, Metric.NAME_THREAD_COUNT, 0, float("inf")) agent.destroy()
def test_report(self): stackimpact._agent = None agent = stackimpact.start( dashboard_address = 'http://localhost:5001', agent_key = 'key1', app_name = 'TestPythonApp', debug = True ) agent.process_reporter.start() agent.process_reporter.report() time.sleep(0.1) agent.process_reporter.report() metrics = agent.process_reporter.metrics if not runtime_info.OS_WIN: self.is_valid(metrics, Metric.TYPE_COUNTER, Metric.CATEGORY_CPU, Metric.NAME_CPU_TIME, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_CPU, Metric.NAME_CPU_USAGE, 0, float("inf")) if not runtime_info.OS_WIN: self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_MAX_RSS, 0, float("inf")) if runtime_info.OS_LINUX: self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_CURRENT_RSS, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_MEMORY, Metric.NAME_VM_SIZE, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_GC, Metric.NAME_GC_COUNT, 0, float("inf")) if min_version(3, 4): self.is_valid(metrics, Metric.TYPE_COUNTER, Metric.CATEGORY_GC, Metric.NAME_GC_COLLECTIONS, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_COUNTER, Metric.CATEGORY_GC, Metric.NAME_GC_COLLECTED, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_GC, Metric.NAME_GC_UNCOLLECTABLE, 0, float("inf")) self.is_valid(metrics, Metric.TYPE_STATE, Metric.CATEGORY_RUNTIME, Metric.NAME_THREAD_COUNT, 0, float("inf")) agent.destroy()