def RetrieveStackTrace(self, inspector_client=None): """Retrieves the creation stack trace and stores it into this LeakNode. Args: inspector_client: RemoteInspectorClient, client to use for retrieving the full stack trace. If None, we will retrieve a possibly shortened value from the snapshot. """ stack = None if not self._stacktrace_suffix: # No stack trace information. self.stack = stacktrace.Stack('') return if inspector_client: # The heap snapshot contains only the first 1000 characters of each # string. As we store the creation stack trace in objects as strings, we # will need to evaluate this string using the remote inspector client to # get the full stack trace. stack = inspector_client.EvaluateJavaScript( self.how_to_find_node + self._stacktrace_suffix) else: # See if the object contains a stack trace. for edge in self.node.edges_from: if edge.name_string == self._stacktrace_suffix: stack = edge.to_node.string break if stack: self.stack = stacktrace.Stack(stack)
def testUnknown(self): data = textwrap.dedent("""some data across a few lines""") stack = stacktrace.Stack(data) self.assertEqual(stacktrace.Stack.UNKNOWN, stack.vm) self.assertEqual(data.split('\n'), stack.frames)
def testV8Stack(self): v8_trace = """Error at frame (some file:42:1) at eval at <anonymous> at [object Object].function (unknown source)""" stack = stacktrace.Stack(v8_trace) self.assertEqual(stacktrace.Stack.V8, stack.vm) self.assertEqual(3, len(stack.frames)) self.assertEqual('frame', stack.frames[0]) self.assertEqual('eval at <anonymous>', stack.frames[1]) self.assertEqual('[object Object].function', stack.frames[2])
def testJSCStack(self): jsc_trace = """--> Stack trace: 0 frame@somefile:42 1 @eval code 2 map@[native code]""" stack = stacktrace.Stack(jsc_trace) self.assertEqual(stacktrace.Stack.JSC, stack.vm) self.assertEqual(3, len(stack.frames)) self.assertEqual('frame', stack.frames[0]) self.assertEqual('*', stack.frames[1]) self.assertEqual('map', stack.frames[2])
def _ParseJSCFrame(self, frame): return stacktrace.Stack('--> Stack trace:\n%s' % frame).frames[0]
def _ParseV8Frame(self, frame): return stacktrace.Stack('Error\n%s' % frame).frames[0]