From b207d394c787412000a25f15305b8549f949a9b9 Mon Sep 17 00:00:00 2001 From: Beau Lyddon Date: Thu, 20 Mar 2014 17:23:37 -0600 Subject: [PATCH 1/2] Add memory profiling Use the GAE runtime module and the memory_usage().current() to get the memory used by the request. --- appstats_logger/recorder.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/appstats_logger/recorder.py b/appstats_logger/recorder.py index 4d2dfa3..eb1be0d 100644 --- a/appstats_logger/recorder.py +++ b/appstats_logger/recorder.py @@ -21,6 +21,8 @@ import threading import time +from google.appengine.api import runtime + class Recorder(object): """In-memory state for the current request. @@ -49,6 +51,8 @@ def __init__(self, env): self.overhead = (time.time() - self.start_timestamp) + self.start_memory = runtime.memory_usage().current() + def record_rpc_request(self, service, call, request, response, rpc): """Record the request of an RPC call. @@ -135,6 +139,8 @@ def get_profile_data(self): return { 'overhead': int(self.overhead * 1000), 'exec_time': int((time.time() - self.start_timestamp) * 1000), + 'memory_start': self.start_memory, + 'memory_end': runtime.memory_usage().current(), 'calls': self.traces } From 5327b0038b0bfa6c41f3356124d9c73348796288 Mon Sep 17 00:00:00 2001 From: Beau Lyddon Date: Mon, 24 Mar 2014 09:19:26 -0500 Subject: [PATCH 2/2] Switch memory profiling to track the end memory consumption and the delta --- appstats_logger/recorder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/appstats_logger/recorder.py b/appstats_logger/recorder.py index eb1be0d..d9c6f27 100644 --- a/appstats_logger/recorder.py +++ b/appstats_logger/recorder.py @@ -136,11 +136,12 @@ def record_rpc_response(self, service, call, request, response, rpc): def get_profile_data(self): """Return a dict with the profile results.""" + end_memory = runtime.memory_usage().current() return { 'overhead': int(self.overhead * 1000), 'exec_time': int((time.time() - self.start_timestamp) * 1000), - 'memory_start': self.start_memory, - 'memory_end': runtime.memory_usage().current(), + 'memory_delta': float(end_memory - self.start_memory), + 'memory_end': end_memory, 'calls': self.traces }