2008-09-09 20:08:45 +00:00
|
|
|
# Copyright 2008 the V8 project authors. All rights reserved.
|
2008-09-03 19:15:48 +00:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2009-02-18 16:12:40 +00:00
|
|
|
import csv, splaytree, sys, re
|
2009-02-17 14:45:45 +00:00
|
|
|
from operator import itemgetter
|
2009-02-18 16:12:40 +00:00
|
|
|
import getopt, os, string
|
2008-09-03 19:15:48 +00:00
|
|
|
|
|
|
|
class CodeEntry(object):
|
|
|
|
|
|
|
|
def __init__(self, start_addr, name):
|
|
|
|
self.start_addr = start_addr
|
|
|
|
self.tick_count = 0
|
|
|
|
self.name = name
|
2009-02-17 14:45:45 +00:00
|
|
|
self.stacks = {}
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2009-02-17 14:45:45 +00:00
|
|
|
def Tick(self, pc, stack):
|
2008-09-03 19:15:48 +00:00
|
|
|
self.tick_count += 1
|
2009-02-17 14:45:45 +00:00
|
|
|
if len(stack) > 0:
|
|
|
|
stack.insert(0, self.ToString())
|
|
|
|
stack_key = tuple(stack)
|
|
|
|
self.stacks[stack_key] = self.stacks.setdefault(stack_key, 0) + 1
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2008-12-19 13:12:43 +00:00
|
|
|
def RegionTicks(self):
|
|
|
|
return None
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
def SetStartAddress(self, start_addr):
|
|
|
|
self.start_addr = start_addr
|
|
|
|
|
|
|
|
def ToString(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def IsSharedLibraryEntry(self):
|
|
|
|
return False
|
|
|
|
|
2009-02-18 16:12:40 +00:00
|
|
|
def IsICEntry(self):
|
|
|
|
return False
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
|
|
|
|
class SharedLibraryEntry(CodeEntry):
|
|
|
|
|
|
|
|
def __init__(self, start_addr, name):
|
|
|
|
CodeEntry.__init__(self, start_addr, name)
|
|
|
|
|
|
|
|
def IsSharedLibraryEntry(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class JSCodeEntry(CodeEntry):
|
|
|
|
|
2008-12-19 13:12:43 +00:00
|
|
|
def __init__(self, start_addr, name, type, size, assembler):
|
2008-09-03 19:15:48 +00:00
|
|
|
CodeEntry.__init__(self, start_addr, name)
|
|
|
|
self.type = type
|
|
|
|
self.size = size
|
2008-12-19 13:12:43 +00:00
|
|
|
self.assembler = assembler
|
|
|
|
self.region_ticks = None
|
2009-02-18 16:12:40 +00:00
|
|
|
self.builtin_ic_re = re.compile('^(Keyed)?(Call|Load|Store)IC_')
|
2008-12-19 13:12:43 +00:00
|
|
|
|
2009-02-17 14:45:45 +00:00
|
|
|
def Tick(self, pc, stack):
|
|
|
|
super(JSCodeEntry, self).Tick(pc, stack)
|
2008-12-19 13:12:43 +00:00
|
|
|
if not pc is None:
|
|
|
|
offset = pc - self.start_addr
|
|
|
|
seen = []
|
|
|
|
narrowest = None
|
|
|
|
narrowest_width = None
|
|
|
|
for region in self.Regions():
|
|
|
|
if region.Contains(offset):
|
|
|
|
if (not region.name in seen):
|
|
|
|
seen.append(region.name)
|
|
|
|
if narrowest is None or region.Width() < narrowest.Width():
|
|
|
|
narrowest = region
|
|
|
|
if len(seen) == 0:
|
|
|
|
return
|
|
|
|
if self.region_ticks is None:
|
|
|
|
self.region_ticks = {}
|
|
|
|
for name in seen:
|
|
|
|
if not name in self.region_ticks:
|
|
|
|
self.region_ticks[name] = [0, 0]
|
|
|
|
self.region_ticks[name][0] += 1
|
|
|
|
if name == narrowest.name:
|
|
|
|
self.region_ticks[name][1] += 1
|
|
|
|
|
|
|
|
def RegionTicks(self):
|
|
|
|
return self.region_ticks
|
|
|
|
|
|
|
|
def Regions(self):
|
|
|
|
if self.assembler:
|
|
|
|
return self.assembler.regions
|
|
|
|
else:
|
|
|
|
return []
|
2008-09-03 19:15:48 +00:00
|
|
|
|
|
|
|
def ToString(self):
|
2008-10-10 09:26:40 +00:00
|
|
|
name = self.name
|
2009-02-03 10:52:02 +00:00
|
|
|
if name == '':
|
|
|
|
name = '<anonymous>'
|
|
|
|
elif name.startswith(' '):
|
|
|
|
name = '<anonymous>' + name
|
2008-10-10 09:26:40 +00:00
|
|
|
return self.type + ': ' + name
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2009-02-18 16:12:40 +00:00
|
|
|
def IsICEntry(self):
|
|
|
|
return self.type in ('CallIC', 'LoadIC', 'StoreIC') or \
|
|
|
|
(self.type == 'Builtin' and self.builtin_ic_re.match(self.name))
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2008-12-19 13:12:43 +00:00
|
|
|
class CodeRegion(object):
|
|
|
|
|
|
|
|
def __init__(self, start_offset, name):
|
|
|
|
self.start_offset = start_offset
|
|
|
|
self.name = name
|
|
|
|
self.end_offset = None
|
|
|
|
|
|
|
|
def Contains(self, pc):
|
|
|
|
return (self.start_offset <= pc) and (pc <= self.end_offset)
|
|
|
|
|
|
|
|
def Width(self):
|
|
|
|
return self.end_offset - self.start_offset
|
|
|
|
|
|
|
|
|
|
|
|
class Assembler(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
# Mapping from region ids to open regions
|
|
|
|
self.pending_regions = {}
|
|
|
|
self.regions = []
|
|
|
|
|
|
|
|
|
2009-03-31 09:06:37 +00:00
|
|
|
class FunctionEnumerator(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.known_funcs = {}
|
|
|
|
self.next_func_id = 0
|
|
|
|
|
|
|
|
def GetFunctionId(self, name):
|
|
|
|
if not self.known_funcs.has_key(name):
|
|
|
|
self.known_funcs[name] = self.next_func_id
|
|
|
|
self.next_func_id += 1
|
|
|
|
return self.known_funcs[name]
|
|
|
|
|
|
|
|
def GetKnownFunctions(self):
|
|
|
|
known_funcs_items = self.known_funcs.items();
|
|
|
|
known_funcs_items.sort(key = itemgetter(1))
|
|
|
|
result = []
|
|
|
|
for func, id_not_used in known_funcs_items:
|
|
|
|
result.append(func)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2009-03-27 12:32:28 +00:00
|
|
|
VMStates = { 'JS': 0, 'GC': 1, 'COMPILER': 2, 'OTHER': 3, 'EXTERNAL' : 4 }
|
2009-02-26 15:48:32 +00:00
|
|
|
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
class TickProcessor(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.log_file = ''
|
|
|
|
self.deleted_code = []
|
|
|
|
self.vm_extent = {}
|
2008-12-19 13:12:43 +00:00
|
|
|
# Map from assembler ids to the pending assembler objects
|
|
|
|
self.pending_assemblers = {}
|
|
|
|
# Map from code addresses the have been allocated but not yet officially
|
|
|
|
# created to their assemblers.
|
|
|
|
self.assemblers = {}
|
2008-09-03 19:15:48 +00:00
|
|
|
self.js_entries = splaytree.SplayTree()
|
|
|
|
self.cpp_entries = splaytree.SplayTree()
|
|
|
|
self.total_number_of_ticks = 0
|
|
|
|
self.number_of_library_ticks = 0
|
|
|
|
self.unaccounted_number_of_ticks = 0
|
|
|
|
self.excluded_number_of_ticks = 0
|
2009-02-26 15:48:32 +00:00
|
|
|
self.number_of_gc_ticks = 0
|
2009-02-18 10:29:56 +00:00
|
|
|
# Flag indicating whether to ignore unaccounted ticks in the report
|
|
|
|
self.ignore_unknown = False
|
2009-03-31 09:06:37 +00:00
|
|
|
self.func_enum = FunctionEnumerator()
|
|
|
|
self.packed_stacks = []
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2009-03-31 09:06:37 +00:00
|
|
|
def ProcessLogfile(self, filename, included_state = None, ignore_unknown = False, separate_ic = False, call_graph_json = False):
|
2008-09-03 19:15:48 +00:00
|
|
|
self.log_file = filename
|
|
|
|
self.included_state = included_state
|
2009-02-18 10:29:56 +00:00
|
|
|
self.ignore_unknown = ignore_unknown
|
2009-02-18 16:12:40 +00:00
|
|
|
self.separate_ic = separate_ic
|
2009-03-31 09:06:37 +00:00
|
|
|
self.call_graph_json = call_graph_json
|
2009-02-18 10:29:56 +00:00
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
try:
|
|
|
|
logfile = open(filename, 'rb')
|
|
|
|
except IOError:
|
|
|
|
sys.exit("Could not open logfile: " + filename)
|
|
|
|
try:
|
2009-03-31 09:06:37 +00:00
|
|
|
try:
|
|
|
|
logreader = csv.reader(logfile)
|
|
|
|
row_num = 1
|
|
|
|
for row in logreader:
|
|
|
|
row_num += 1
|
|
|
|
if row[0] == 'tick':
|
|
|
|
self.ProcessTick(int(row[1], 16), int(row[2], 16), int(row[3]), self.PreprocessStack(row[4:]))
|
|
|
|
elif row[0] == 'code-creation':
|
|
|
|
self.ProcessCodeCreation(row[1], int(row[2], 16), int(row[3]), row[4])
|
|
|
|
elif row[0] == 'code-move':
|
|
|
|
self.ProcessCodeMove(int(row[1], 16), int(row[2], 16))
|
|
|
|
elif row[0] == 'code-delete':
|
|
|
|
self.ProcessCodeDelete(int(row[1], 16))
|
|
|
|
elif row[0] == 'shared-library':
|
|
|
|
self.AddSharedLibraryEntry(row[1], int(row[2], 16), int(row[3], 16))
|
|
|
|
self.ParseVMSymbols(row[1], int(row[2], 16), int(row[3], 16))
|
|
|
|
elif row[0] == 'begin-code-region':
|
|
|
|
self.ProcessBeginCodeRegion(int(row[1], 16), int(row[2], 16), int(row[3], 16), row[4])
|
|
|
|
elif row[0] == 'end-code-region':
|
|
|
|
self.ProcessEndCodeRegion(int(row[1], 16), int(row[2], 16), int(row[3], 16))
|
|
|
|
elif row[0] == 'code-allocate':
|
|
|
|
self.ProcessCodeAllocate(int(row[1], 16), int(row[2], 16))
|
|
|
|
except csv.Error:
|
|
|
|
print("parse error in line " + str(row_num))
|
|
|
|
raise
|
2008-09-03 19:15:48 +00:00
|
|
|
finally:
|
|
|
|
logfile.close()
|
|
|
|
|
|
|
|
def AddSharedLibraryEntry(self, filename, start, end):
|
|
|
|
# Mark the pages used by this library.
|
|
|
|
i = start
|
|
|
|
while i < end:
|
|
|
|
page = i >> 12
|
|
|
|
self.vm_extent[page] = 1
|
|
|
|
i += 4096
|
|
|
|
# Add the library to the entries so that ticks for which we do not
|
|
|
|
# have symbol information is reported as belonging to the library.
|
|
|
|
self.cpp_entries.Insert(start, SharedLibraryEntry(start, filename))
|
|
|
|
|
|
|
|
def ParseVMSymbols(self, filename, start, end):
|
|
|
|
return
|
|
|
|
|
2008-12-19 13:12:43 +00:00
|
|
|
def ProcessCodeAllocate(self, addr, assem):
|
|
|
|
if assem in self.pending_assemblers:
|
|
|
|
assembler = self.pending_assemblers.pop(assem)
|
|
|
|
self.assemblers[addr] = assembler
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
def ProcessCodeCreation(self, type, addr, size, name):
|
2008-12-19 13:12:43 +00:00
|
|
|
if addr in self.assemblers:
|
|
|
|
assembler = self.assemblers.pop(addr)
|
|
|
|
else:
|
|
|
|
assembler = None
|
|
|
|
self.js_entries.Insert(addr, JSCodeEntry(addr, name, type, size, assembler))
|
2008-09-03 19:15:48 +00:00
|
|
|
|
|
|
|
def ProcessCodeMove(self, from_addr, to_addr):
|
|
|
|
try:
|
|
|
|
removed_node = self.js_entries.Remove(from_addr)
|
|
|
|
removed_node.value.SetStartAddress(to_addr);
|
|
|
|
self.js_entries.Insert(to_addr, removed_node.value)
|
2009-03-25 12:14:13 +00:00
|
|
|
except splaytree.KeyNotFoundError:
|
2008-09-03 19:15:48 +00:00
|
|
|
print('Code move event for unknown code: 0x%x' % from_addr)
|
|
|
|
|
|
|
|
def ProcessCodeDelete(self, from_addr):
|
|
|
|
try:
|
|
|
|
removed_node = self.js_entries.Remove(from_addr)
|
|
|
|
self.deleted_code.append(removed_node.value)
|
2009-03-25 12:14:13 +00:00
|
|
|
except splaytree.KeyNotFoundError:
|
2008-09-03 19:15:48 +00:00
|
|
|
print('Code delete event for unknown code: 0x%x' % from_addr)
|
|
|
|
|
2008-12-19 13:12:43 +00:00
|
|
|
def ProcessBeginCodeRegion(self, id, assm, start, name):
|
|
|
|
if not assm in self.pending_assemblers:
|
|
|
|
self.pending_assemblers[assm] = Assembler()
|
|
|
|
assembler = self.pending_assemblers[assm]
|
|
|
|
assembler.pending_regions[id] = CodeRegion(start, name)
|
|
|
|
|
|
|
|
def ProcessEndCodeRegion(self, id, assm, end):
|
|
|
|
assm = self.pending_assemblers[assm]
|
|
|
|
region = assm.pending_regions.pop(id)
|
|
|
|
region.end_offset = end
|
|
|
|
assm.regions.append(region)
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
def IncludeTick(self, pc, sp, state):
|
|
|
|
return (self.included_state is None) or (self.included_state == state)
|
|
|
|
|
2009-02-17 14:45:45 +00:00
|
|
|
def FindEntry(self, pc):
|
2008-09-03 19:15:48 +00:00
|
|
|
page = pc >> 12
|
|
|
|
if page in self.vm_extent:
|
2009-02-17 14:45:45 +00:00
|
|
|
entry = self.cpp_entries.FindGreatestsLessThan(pc)
|
|
|
|
if entry != None:
|
|
|
|
return entry.value
|
|
|
|
else:
|
|
|
|
return entry
|
2008-09-03 19:15:48 +00:00
|
|
|
max = self.js_entries.FindMax()
|
|
|
|
min = self.js_entries.FindMin()
|
2009-02-18 10:29:56 +00:00
|
|
|
if max != None and pc < (max.key + max.value.size) and pc > min.key:
|
2009-02-17 14:45:45 +00:00
|
|
|
return self.js_entries.FindGreatestsLessThan(pc).value
|
|
|
|
return None
|
|
|
|
|
2009-02-18 16:12:40 +00:00
|
|
|
def PreprocessStack(self, stack):
|
|
|
|
# remove all non-addresses (e.g. 'overflow') and convert to int
|
2009-02-17 14:45:45 +00:00
|
|
|
result = []
|
|
|
|
for frame in stack:
|
|
|
|
if frame.startswith('0x'):
|
2009-02-18 16:12:40 +00:00
|
|
|
result.append(int(frame, 16))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def ProcessStack(self, stack):
|
|
|
|
result = []
|
|
|
|
for frame in stack:
|
|
|
|
entry = self.FindEntry(frame)
|
|
|
|
if entry != None:
|
|
|
|
result.append(entry.ToString())
|
2009-02-17 14:45:45 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
def ProcessTick(self, pc, sp, state, stack):
|
2009-02-26 15:48:32 +00:00
|
|
|
if state == VMStates['GC']:
|
|
|
|
self.number_of_gc_ticks += 1
|
2009-02-17 14:45:45 +00:00
|
|
|
if not self.IncludeTick(pc, sp, state):
|
|
|
|
self.excluded_number_of_ticks += 1;
|
2008-09-03 19:15:48 +00:00
|
|
|
return
|
2009-02-17 14:45:45 +00:00
|
|
|
self.total_number_of_ticks += 1
|
|
|
|
entry = self.FindEntry(pc)
|
|
|
|
if entry == None:
|
|
|
|
self.unaccounted_number_of_ticks += 1
|
|
|
|
return
|
|
|
|
if entry.IsSharedLibraryEntry():
|
|
|
|
self.number_of_library_ticks += 1
|
2009-02-18 16:12:40 +00:00
|
|
|
if entry.IsICEntry() and not self.separate_ic:
|
|
|
|
if len(stack) > 0:
|
|
|
|
caller_pc = stack.pop(0)
|
|
|
|
self.total_number_of_ticks -= 1
|
|
|
|
self.ProcessTick(caller_pc, sp, state, stack)
|
|
|
|
else:
|
|
|
|
self.unaccounted_number_of_ticks += 1
|
|
|
|
else:
|
|
|
|
entry.Tick(pc, self.ProcessStack(stack))
|
2009-03-31 09:06:37 +00:00
|
|
|
if self.call_graph_json:
|
|
|
|
self.AddToPackedStacks(pc, stack)
|
|
|
|
|
|
|
|
def AddToPackedStacks(self, pc, stack):
|
|
|
|
full_stack = stack
|
|
|
|
full_stack.insert(0, pc)
|
|
|
|
func_names = self.ProcessStack(full_stack)
|
|
|
|
func_ids = []
|
|
|
|
for func in func_names:
|
|
|
|
func_ids.append(self.func_enum.GetFunctionId(func))
|
|
|
|
self.packed_stacks.append(func_ids)
|
2008-09-03 19:15:48 +00:00
|
|
|
|
|
|
|
def PrintResults(self):
|
2009-03-31 09:06:37 +00:00
|
|
|
if not self.call_graph_json:
|
|
|
|
self.PrintStatistics()
|
|
|
|
else:
|
|
|
|
self.PrintCallGraphJSON()
|
|
|
|
|
|
|
|
def PrintStatistics(self):
|
2008-09-03 19:15:48 +00:00
|
|
|
print('Statistical profiling result from %s, (%d ticks, %d unaccounted, %d excluded).' %
|
|
|
|
(self.log_file,
|
|
|
|
self.total_number_of_ticks,
|
|
|
|
self.unaccounted_number_of_ticks,
|
|
|
|
self.excluded_number_of_ticks))
|
|
|
|
if self.total_number_of_ticks > 0:
|
|
|
|
js_entries = self.js_entries.ExportValueList()
|
|
|
|
js_entries.extend(self.deleted_code)
|
|
|
|
cpp_entries = self.cpp_entries.ExportValueList()
|
2009-02-18 10:29:56 +00:00
|
|
|
# Print the unknown ticks percentage if they are not ignored.
|
|
|
|
if not self.ignore_unknown and self.unaccounted_number_of_ticks > 0:
|
|
|
|
self.PrintHeader('Unknown')
|
2009-02-26 15:48:32 +00:00
|
|
|
self.PrintCounter(self.unaccounted_number_of_ticks)
|
2008-09-03 19:15:48 +00:00
|
|
|
# Print the library ticks.
|
|
|
|
self.PrintHeader('Shared libraries')
|
|
|
|
self.PrintEntries(cpp_entries, lambda e:e.IsSharedLibraryEntry())
|
|
|
|
# Print the JavaScript ticks.
|
|
|
|
self.PrintHeader('JavaScript')
|
|
|
|
self.PrintEntries(js_entries, lambda e:not e.IsSharedLibraryEntry())
|
|
|
|
# Print the C++ ticks.
|
|
|
|
self.PrintHeader('C++')
|
|
|
|
self.PrintEntries(cpp_entries, lambda e:not e.IsSharedLibraryEntry())
|
2009-02-26 15:48:32 +00:00
|
|
|
# Print the GC ticks.
|
|
|
|
self.PrintHeader('GC')
|
|
|
|
self.PrintCounter(self.number_of_gc_ticks)
|
2009-02-17 14:45:45 +00:00
|
|
|
# Print call profile.
|
|
|
|
print('\n [Call profile]:')
|
|
|
|
print(' total call path')
|
|
|
|
js_entries.extend(cpp_entries)
|
|
|
|
self.PrintCallProfile(js_entries)
|
2008-09-03 19:15:48 +00:00
|
|
|
|
|
|
|
def PrintHeader(self, header_title):
|
|
|
|
print('\n [%s]:' % header_title)
|
2009-02-20 01:56:08 +00:00
|
|
|
print(' ticks total nonlib name')
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2009-02-26 15:48:32 +00:00
|
|
|
def PrintCounter(self, ticks_count):
|
|
|
|
percentage = ticks_count * 100.0 / self.total_number_of_ticks
|
|
|
|
print(' %(ticks)5d %(total)5.1f%%' % {
|
|
|
|
'ticks' : ticks_count,
|
|
|
|
'total' : percentage,
|
|
|
|
})
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
def PrintEntries(self, entries, condition):
|
2009-02-18 10:29:56 +00:00
|
|
|
# If ignoring unaccounted ticks don't include these in percentage
|
|
|
|
# calculations
|
|
|
|
number_of_accounted_ticks = self.total_number_of_ticks
|
|
|
|
if self.ignore_unknown:
|
|
|
|
number_of_accounted_ticks -= self.unaccounted_number_of_ticks
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
number_of_non_library_ticks = number_of_accounted_ticks - self.number_of_library_ticks
|
2009-04-27 13:50:42 +00:00
|
|
|
entries.sort(key=lambda e: (e.tick_count, e.ToString()), reverse=True)
|
2008-09-03 19:15:48 +00:00
|
|
|
for entry in entries:
|
|
|
|
if entry.tick_count > 0 and condition(entry):
|
|
|
|
total_percentage = entry.tick_count * 100.0 / number_of_accounted_ticks
|
|
|
|
if entry.IsSharedLibraryEntry():
|
|
|
|
non_library_percentage = 0
|
|
|
|
else:
|
|
|
|
non_library_percentage = entry.tick_count * 100.0 / number_of_non_library_ticks
|
2009-02-20 01:56:08 +00:00
|
|
|
print(' %(ticks)5d %(total)5.1f%% %(nonlib)6.1f%% %(name)s' % {
|
|
|
|
'ticks' : entry.tick_count,
|
2008-09-03 19:15:48 +00:00
|
|
|
'total' : total_percentage,
|
|
|
|
'nonlib' : non_library_percentage,
|
|
|
|
'name' : entry.ToString()
|
|
|
|
})
|
2008-12-19 13:12:43 +00:00
|
|
|
region_ticks = entry.RegionTicks()
|
|
|
|
if not region_ticks is None:
|
|
|
|
items = region_ticks.items()
|
|
|
|
items.sort(key=lambda e: e[1][1], reverse=True)
|
|
|
|
for (name, ticks) in items:
|
|
|
|
print(' flat cum')
|
|
|
|
print(' %(flat)5.1f%% %(accum)5.1f%% %(name)s' % {
|
|
|
|
'flat' : ticks[1] * 100.0 / entry.tick_count,
|
|
|
|
'accum' : ticks[0] * 100.0 / entry.tick_count,
|
|
|
|
'name': name
|
|
|
|
})
|
2008-09-03 19:15:48 +00:00
|
|
|
|
2009-02-17 14:45:45 +00:00
|
|
|
def PrintCallProfile(self, entries):
|
|
|
|
all_stacks = {}
|
|
|
|
total_stacks = 0
|
|
|
|
for entry in entries:
|
|
|
|
all_stacks.update(entry.stacks)
|
|
|
|
for count in entry.stacks.itervalues():
|
|
|
|
total_stacks += count
|
|
|
|
all_stacks_items = all_stacks.items();
|
|
|
|
all_stacks_items.sort(key = itemgetter(1), reverse=True)
|
2009-02-23 12:18:46 +00:00
|
|
|
missing_percentage = (self.total_number_of_ticks - total_stacks) * 100.0 / self.total_number_of_ticks
|
|
|
|
print(' %(ticks)5d %(total)5.1f%% <no call path information>' % {
|
|
|
|
'ticks' : self.total_number_of_ticks - total_stacks,
|
|
|
|
'total' : missing_percentage
|
|
|
|
})
|
2009-02-17 14:45:45 +00:00
|
|
|
for stack, count in all_stacks_items:
|
2009-02-23 12:18:46 +00:00
|
|
|
total_percentage = count * 100.0 / self.total_number_of_ticks
|
|
|
|
print(' %(ticks)5d %(total)5.1f%% %(call_path)s' % {
|
|
|
|
'ticks' : count,
|
2009-02-17 14:45:45 +00:00
|
|
|
'total' : total_percentage,
|
|
|
|
'call_path' : stack[0] + ' <- ' + stack[1]
|
|
|
|
})
|
|
|
|
|
2009-03-31 09:06:37 +00:00
|
|
|
def PrintCallGraphJSON(self):
|
|
|
|
print('\nvar __profile_funcs = ["' +
|
|
|
|
'",\n"'.join(self.func_enum.GetKnownFunctions()) +
|
|
|
|
'"];')
|
|
|
|
print('var __profile_ticks = [')
|
|
|
|
str_packed_stacks = []
|
|
|
|
for stack in self.packed_stacks:
|
|
|
|
str_packed_stacks.append('[' + ','.join(map(str, stack)) + ']')
|
|
|
|
print(',\n'.join(str_packed_stacks))
|
|
|
|
print('];')
|
2009-02-18 13:45:54 +00:00
|
|
|
|
|
|
|
class CmdLineProcessor(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
2009-03-27 12:32:28 +00:00
|
|
|
self.options = ["js",
|
|
|
|
"gc",
|
|
|
|
"compiler",
|
|
|
|
"other",
|
|
|
|
"external",
|
|
|
|
"ignore-unknown",
|
2009-03-31 09:06:37 +00:00
|
|
|
"separate-ic",
|
|
|
|
"call-graph-json"]
|
2009-02-18 13:45:54 +00:00
|
|
|
# default values
|
|
|
|
self.state = None
|
|
|
|
self.ignore_unknown = False
|
|
|
|
self.log_file = None
|
2009-02-18 16:12:40 +00:00
|
|
|
self.separate_ic = False
|
2009-03-31 09:06:37 +00:00
|
|
|
self.call_graph_json = False
|
2009-02-18 13:45:54 +00:00
|
|
|
|
|
|
|
def ProcessArguments(self):
|
|
|
|
try:
|
2009-03-27 12:32:28 +00:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "jgcoe", self.options)
|
2009-02-18 13:45:54 +00:00
|
|
|
except getopt.GetoptError:
|
|
|
|
self.PrintUsageAndExit()
|
|
|
|
for key, value in opts:
|
|
|
|
if key in ("-j", "--js"):
|
2009-02-26 15:48:32 +00:00
|
|
|
self.state = VMStates['JS']
|
2009-02-18 13:45:54 +00:00
|
|
|
if key in ("-g", "--gc"):
|
2009-02-26 15:48:32 +00:00
|
|
|
self.state = VMStates['GC']
|
2009-02-18 13:45:54 +00:00
|
|
|
if key in ("-c", "--compiler"):
|
2009-02-26 15:48:32 +00:00
|
|
|
self.state = VMStates['COMPILER']
|
2009-02-18 13:45:54 +00:00
|
|
|
if key in ("-o", "--other"):
|
2009-02-26 15:48:32 +00:00
|
|
|
self.state = VMStates['OTHER']
|
2009-03-27 12:32:28 +00:00
|
|
|
if key in ("-e", "--external"):
|
|
|
|
self.state = VMStates['EXTERNAL']
|
2009-02-18 13:45:54 +00:00
|
|
|
if key in ("--ignore-unknown"):
|
|
|
|
self.ignore_unknown = True
|
2009-02-18 16:12:40 +00:00
|
|
|
if key in ("--separate-ic"):
|
|
|
|
self.separate_ic = True
|
2009-03-31 09:06:37 +00:00
|
|
|
if key in ("--call-graph-json"):
|
|
|
|
self.call_graph_json = True
|
2009-02-18 13:45:54 +00:00
|
|
|
self.ProcessRequiredArgs(args)
|
|
|
|
|
|
|
|
def ProcessRequiredArgs(self, args):
|
|
|
|
return
|
|
|
|
|
|
|
|
def GetRequiredArgsNames(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
def PrintUsageAndExit(self):
|
2009-02-18 16:12:40 +00:00
|
|
|
print('Usage: %(script_name)s --{%(opts)s} %(req_opts)s' % {
|
2009-02-18 13:45:54 +00:00
|
|
|
'script_name': os.path.basename(sys.argv[0]),
|
2009-02-18 16:12:40 +00:00
|
|
|
'opts': string.join(self.options, ','),
|
2009-02-18 13:45:54 +00:00
|
|
|
'req_opts': self.GetRequiredArgsNames()
|
|
|
|
})
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
def RunLogfileProcessing(self, tick_processor):
|
2009-03-31 09:06:37 +00:00
|
|
|
tick_processor.ProcessLogfile(self.log_file, self.state, self.ignore_unknown,
|
|
|
|
self.separate_ic, self.call_graph_json)
|
2009-02-18 13:45:54 +00:00
|
|
|
|
|
|
|
|
2008-09-03 19:15:48 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit('You probably want to run windows-tick-processor.py or linux-tick-processor.py.')
|