parameters: (tracefile, args)
docstring: Simple analyzer for stack traces. Outputs stacks in a format similar
      to that of DTrace. Further analysis of the data can be done by tools
      such as FlameGraph
      (https://github.com/brendangregg/FlameGraph)
  
      This script prints its output to stdout.
docstring_summary: Simple analyzer for stack traces. Outputs stacks in a format similar
      to that of DTrace. Further analysis of the data can be done by tools
      such as FlameGraph
      (https://github.com/brendangregg/FlameGraph)
docstring_tokens: Simple analyzer for stack traces . Outputs stacks in a format similar to that of DTrace . Further analysis of the data can be done by tools such as FlameGraph ( https : // github . com / brendangregg / FlameGraph )
function: def stacks(tracefile, args):
      """
      Simple analyzer for stack traces. Outputs stacks in a format similar
      to that of DTrace. Further analysis of the data can be done by tools
      such as FlameGraph
      (https://github.com/brendangregg/FlameGraph)
  
      This script prints its output to stdout.
      """
  
      # Validate that the supplied apk exists
      if not os.path.exists(args.apk):
          print("stacks: {apk}: no such file or directory".format(apk=args.apk))
          sys.exit(2)
  
      symbols = extract_apk_symbols(args.apk)
      interpreter = TraceFileInterpreter(tracefile, symbols)
      trace = interpreter.interpret()
      stacks = defaultdict(int)  # [frame] -> int (count)
  
      for unit in trace.executionUnits.values():
          for block_id in unit.blocks:
              block = trace.blocks[block_id]
              for point in block.points:
                  stackObject = point.properties.stackTraces.get("stacks", None)
                  if not stackObject:
                      continue
                  stackFrames = stackObject.frames
                  singleStack = []
                  for frame in stackFrames:
                      if frame.symbol:
                          # We actually know the symbol for this address.
                          singleStack.insert(0, frame.symbol)
                      else:
                          # No symbolication luck here :(
                          singleStack.insert(0, frame.identifier)
                  stacks[tuple(singleStack)] += 1
  
      # DTrace collapser ignores the first three lines
      print("\n\n\n")
      for k, v in stacks.items():
          for frame in k:
              if str(frame).isdigit():
                  print("_", frame, sep="")
              else:
                  print(frame, sep="")
          print(v)
          print("\n")
function_tokens: def stacks ( tracefile , args ) : # Validate that the supplied apk exists if not os . path . exists ( args . apk ) : print ( "stacks: {apk}: no such file or directory" . format ( apk = args . apk ) ) sys . exit ( 2 ) symbols = extract_apk_symbols ( args . apk ) interpreter = TraceFileInterpreter ( tracefile , symbols ) trace = interpreter . interpret ( ) stacks = defaultdict ( int ) # [frame] -> int (count) for unit in trace . executionUnits . values ( ) : for block_id in unit . blocks : block = trace . blocks [ block_id ] for point in block . points : stackObject = point . properties . stackTraces . get ( "stacks" , None ) if not stackObject : continue stackFrames = stackObject . frames singleStack = [ ] for frame in stackFrames : if frame . symbol : # We actually know the symbol for this address. singleStack . insert ( 0 , frame . symbol ) else : # No symbolication luck here :( singleStack . insert ( 0 , frame . identifier ) stacks [ tuple ( singleStack ) ] += 1 # DTrace collapser ignores the first three lines print ( "\n\n\n" ) for k , v in stacks . items ( ) : for frame in k : if str ( frame ) . isdigit ( ) : print ( "_" , frame , sep = "" ) else : print ( frame , sep = "" ) print ( v ) print ( "\n" )