ArmPlatformPkg: convert LFs to CRLF, expand hard TABs

We're going to switch the internal line terminators globally to LF at some
point, but until then, let's use CRLF consistently. Convert source files
with LFs in them to CRLF, using "unix2dos".

"git show -b" prints no code changes for this patch.

(I collected all the file name suffixes in this package, with:

$ git ls-files -- $PACKAGE | rev | cut -f 1 -d . | sort -u | rev

I eliminated those suffixes that didn't stand for text files, then
blanket-converted the rest with unix2dos. Finally, picked up the actual
changes with git-add.)

At the same time, the following file had to undergo TAB expansion:

  ArmPlatformPkg/Scripts/Ds5/profile.py

I used "expand -t 4", conforming to the Indentation section of PEP-8
<https://www.python.org/dev/peps/pep-0008/#indentation>.

Both the CRLF conversion and the TAB expansion are motivated by
"PatchCheck.py". "PatchCheck.py" is also the reason why CRLF conversion
and TAB expansion have to happen in the same patch.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1659
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200227213903.13884-4-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
This commit is contained in:
Laszlo Ersek 2020-02-27 22:39:03 +01:00 committed by mergify[bot]
parent a5c2ce7cd1
commit e63d54db95

View File

@ -1,328 +1,328 @@
#!/usr/bin/python #!/usr/bin/python
# #
# Copyright (c) 2014, ARM Limited. All rights reserved. # Copyright (c) 2014, ARM Limited. All rights reserved.
# #
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
import getopt import getopt
import operator import operator
import os import os
import pickle import pickle
import sys import sys
from sys import argv from sys import argv
from cStringIO import StringIO from cStringIO import StringIO
modules = {} modules = {}
functions = {} functions = {}
functions_addr = {} functions_addr = {}
def usage(): def usage():
print "-t,--trace: Location of the Trace file" print "-t,--trace: Location of the Trace file"
print "-s,--symbols: Location of the symbols and modules" print "-s,--symbols: Location of the symbols and modules"
def get_address_from_string(address): def get_address_from_string(address):
return int(address.strip("S:").strip("N:").strip("EL2:").strip("EL1:"), 16) return int(address.strip("S:").strip("N:").strip("EL2:").strip("EL1:"), 16)
def get_module_from_addr(modules, addr): def get_module_from_addr(modules, addr):
for key,value in modules.items(): for key,value in modules.items():
if (value['start'] <= addr) and (addr <= value['end']): if (value['start'] <= addr) and (addr <= value['end']):
return key return key
return None return None
def add_cycles_to_function(functions, func_name, addr, cycles): def add_cycles_to_function(functions, func_name, addr, cycles):
if func_name != "<Unknown>": if func_name != "<Unknown>":
# Check if we are still in the previous function # Check if we are still in the previous function
if add_cycles_to_function.prev_func_name == func_name: if add_cycles_to_function.prev_func_name == func_name:
add_cycles_to_function.prev_entry['cycles'] += cycles add_cycles_to_function.prev_entry['cycles'] += cycles
return (add_cycles_to_function.prev_func_name, add_cycles_to_function.prev_module_name) return (add_cycles_to_function.prev_func_name, add_cycles_to_function.prev_module_name)
if func_name in functions.keys(): if func_name in functions.keys():
for module_name, module_value in functions[func_name].iteritems(): for module_name, module_value in functions[func_name].iteritems():
if (module_value['start'] <= addr) and (addr < module_value['end']): if (module_value['start'] <= addr) and (addr < module_value['end']):
module_value['cycles'] += cycles module_value['cycles'] += cycles
add_cycles_to_function.prev_func_name = func_name add_cycles_to_function.prev_func_name = func_name
add_cycles_to_function.prev_module_name = module_name add_cycles_to_function.prev_module_name = module_name
add_cycles_to_function.prev_entry = module_value add_cycles_to_function.prev_entry = module_value
return (func_name, module_name) return (func_name, module_name)
elif (module_value['end'] == 0): elif (module_value['end'] == 0):
module_value['cycles'] += cycles module_value['cycles'] += cycles
add_cycles_to_function.prev_func_name = func_name add_cycles_to_function.prev_func_name = func_name
add_cycles_to_function.prev_module_name = module_name add_cycles_to_function.prev_module_name = module_name
add_cycles_to_function.prev_entry = module_value add_cycles_to_function.prev_entry = module_value
return (func_name, module_name) return (func_name, module_name)
# Workaround to fix the 'info func' limitation that does not expose the 'static' function # Workaround to fix the 'info func' limitation that does not expose the 'static' function
module_name = get_module_from_addr(modules, addr) module_name = get_module_from_addr(modules, addr)
functions[func_name] = {} functions[func_name] = {}
functions[func_name][module_name] = {} functions[func_name][module_name] = {}
functions[func_name][module_name]['start'] = 0 functions[func_name][module_name]['start'] = 0
functions[func_name][module_name]['end'] = 0 functions[func_name][module_name]['end'] = 0
functions[func_name][module_name]['cycles'] = cycles functions[func_name][module_name]['cycles'] = cycles
functions[func_name][module_name]['count'] = 0 functions[func_name][module_name]['count'] = 0
add_cycles_to_function.prev_func_name = func_name add_cycles_to_function.prev_func_name = func_name
add_cycles_to_function.prev_module_name = module_name add_cycles_to_function.prev_module_name = module_name
add_cycles_to_function.prev_entry = functions[func_name][module_name] add_cycles_to_function.prev_entry = functions[func_name][module_name]
return (func_name, module_name) return (func_name, module_name)
else: else:
# Check if we are still in the previous function # Check if we are still in the previous function
if (add_cycles_to_function.prev_entry is not None) and (add_cycles_to_function.prev_entry['start'] <= addr) and (addr < add_cycles_to_function.prev_entry['end']): if (add_cycles_to_function.prev_entry is not None) and (add_cycles_to_function.prev_entry['start'] <= addr) and (addr < add_cycles_to_function.prev_entry['end']):
add_cycles_to_function.prev_entry['cycles'] += cycles add_cycles_to_function.prev_entry['cycles'] += cycles
return (add_cycles_to_function.prev_func_name, add_cycles_to_function.prev_module_name) return (add_cycles_to_function.prev_func_name, add_cycles_to_function.prev_module_name)
# Generate the key for the given address # Generate the key for the given address
key = addr & ~0x0FFF key = addr & ~0x0FFF
if key not in functions_addr.keys(): if key not in functions_addr.keys():
if 'Unknown' not in functions.keys(): if 'Unknown' not in functions.keys():
functions['Unknown'] = {} functions['Unknown'] = {}
if 'Unknown' not in functions['Unknown'].keys(): if 'Unknown' not in functions['Unknown'].keys():
functions['Unknown']['Unknown'] = {} functions['Unknown']['Unknown'] = {}
functions['Unknown']['Unknown']['cycles'] = 0 functions['Unknown']['Unknown']['cycles'] = 0
functions['Unknown']['Unknown']['count'] = 0 functions['Unknown']['Unknown']['count'] = 0
functions['Unknown']['Unknown']['cycles'] += cycles functions['Unknown']['Unknown']['cycles'] += cycles
add_cycles_to_function.prev_func_name = None add_cycles_to_function.prev_func_name = None
return None return None
for func_key, module in functions_addr[key].iteritems(): for func_key, module in functions_addr[key].iteritems():
for module_key, module_value in module.iteritems(): for module_key, module_value in module.iteritems():
if (module_value['start'] <= addr) and (addr < module_value['end']): if (module_value['start'] <= addr) and (addr < module_value['end']):
module_value['cycles'] += cycles module_value['cycles'] += cycles
# In case o <Unknown> we prefer to fallback on the direct search # In case o <Unknown> we prefer to fallback on the direct search
add_cycles_to_function.prev_func_name = func_key add_cycles_to_function.prev_func_name = func_key
add_cycles_to_function.prev_module_name = module_key add_cycles_to_function.prev_module_name = module_key
add_cycles_to_function.prev_entry = module_value add_cycles_to_function.prev_entry = module_value
return (func_key, module_key) return (func_key, module_key)
print "Warning: Function %s @ 0x%x not found" % (func_name, addr) print "Warning: Function %s @ 0x%x not found" % (func_name, addr)
add_cycles_to_function.prev_func_name = None add_cycles_to_function.prev_func_name = None
return None return None
# Static variables for the previous function # Static variables for the previous function
add_cycles_to_function.prev_func_name = None add_cycles_to_function.prev_func_name = None
add_cycles_to_function.prev_entry = None add_cycles_to_function.prev_entry = None
def trace_read(): def trace_read():
global trace_process global trace_process
line = trace.readline() line = trace.readline()
trace_process += len(line) trace_process += len(line)
return line return line
# #
# Parse arguments # Parse arguments
# #
trace_name = None trace_name = None
symbols_file = None symbols_file = None
opts,args = getopt.getopt(sys.argv[1:], "ht:vs:v", ["help","trace=","symbols="]) opts,args = getopt.getopt(sys.argv[1:], "ht:vs:v", ["help","trace=","symbols="])
if (opts is None) or (not opts): if (opts is None) or (not opts):
usage() usage()
sys.exit() sys.exit()
for o,a in opts: for o,a in opts:
if o in ("-h","--help"): if o in ("-h","--help"):
usage() usage()
sys.exit() sys.exit()
elif o in ("-t","--trace"): elif o in ("-t","--trace"):
trace_name = a trace_name = a
elif o in ("-s","--symbols"): elif o in ("-s","--symbols"):
symbols_file = a symbols_file = a
else: else:
assert False, "Unhandled option (%s)" % o assert False, "Unhandled option (%s)" % o
# #
# We try first to see if we run the script from DS-5 # We try first to see if we run the script from DS-5
# #
try: try:
from arm_ds.debugger_v1 import Debugger from arm_ds.debugger_v1 import Debugger
from arm_ds.debugger_v1 import DebugException from arm_ds.debugger_v1 import DebugException
# Debugger object for accessing the debugger # Debugger object for accessing the debugger
debugger = Debugger() debugger = Debugger()
# Initialisation commands # Initialisation commands
ec = debugger.getExecutionContext(0) ec = debugger.getExecutionContext(0)
ec.getExecutionService().stop() ec.getExecutionService().stop()
ec.getExecutionService().waitForStop() ec.getExecutionService().waitForStop()
# in case the execution context reference is out of date # in case the execution context reference is out of date
ec = debugger.getExecutionContext(0) ec = debugger.getExecutionContext(0)
# #
# Get the module name and their memory range # Get the module name and their memory range
# #
info_file = ec.executeDSCommand("info file") info_file = ec.executeDSCommand("info file")
info_file_str = StringIO(info_file) info_file_str = StringIO(info_file)
line = info_file_str.readline().strip('\n') line = info_file_str.readline().strip('\n')
while line != '': while line != '':
if ("Symbols from" in line): if ("Symbols from" in line):
# Get the module name from the line 'Symbols from "/home/...."' # Get the module name from the line 'Symbols from "/home/...."'
module_name = line.split("\"")[1].split("/")[-1] module_name = line.split("\"")[1].split("/")[-1]
modules[module_name] = {} modules[module_name] = {}
# Look for the text section # Look for the text section
line = info_file_str.readline().strip('\n') line = info_file_str.readline().strip('\n')
while (line != '') and ("Symbols from" not in line): while (line != '') and ("Symbols from" not in line):
if ("ER_RO" in line): if ("ER_RO" in line):
modules[module_name]['start'] = get_address_from_string(line.split()[0]) modules[module_name]['start'] = get_address_from_string(line.split()[0])
modules[module_name]['end'] = get_address_from_string(line.split()[2]) modules[module_name]['end'] = get_address_from_string(line.split()[2])
line = info_file_str.readline().strip('\n') line = info_file_str.readline().strip('\n')
break; break;
if (".text" in line): if (".text" in line):
modules[module_name]['start'] = get_address_from_string(line.split()[0]) modules[module_name]['start'] = get_address_from_string(line.split()[0])
modules[module_name]['end'] = get_address_from_string(line.split()[2]) modules[module_name]['end'] = get_address_from_string(line.split()[2])
line = info_file_str.readline().strip('\n') line = info_file_str.readline().strip('\n')
break; break;
line = info_file_str.readline().strip('\n') line = info_file_str.readline().strip('\n')
line = info_file_str.readline().strip('\n') line = info_file_str.readline().strip('\n')
# #
# Get the function name and their memory range # Get the function name and their memory range
# #
info_func = ec.executeDSCommand("info func") info_func = ec.executeDSCommand("info func")
info_func_str = StringIO(info_func) info_func_str = StringIO(info_func)
# Skip the first line 'Low-level symbols ...' # Skip the first line 'Low-level symbols ...'
line = info_func_str.readline().strip('\n') line = info_func_str.readline().strip('\n')
func_prev = None func_prev = None
while line != '': while line != '':
# We ignore all the functions after 'Functions in' # We ignore all the functions after 'Functions in'
if ("Functions in " in line): if ("Functions in " in line):
line = info_func_str.readline().strip('\n') line = info_func_str.readline().strip('\n')
while line != '': while line != '':
line = info_func_str.readline().strip('\n') line = info_func_str.readline().strip('\n')
line = info_func_str.readline().strip('\n') line = info_func_str.readline().strip('\n')
continue continue
if ("Low-level symbols" in line): if ("Low-level symbols" in line):
# We need to fixup the last function of the module # We need to fixup the last function of the module
if func_prev is not None: if func_prev is not None:
func_prev['end'] = modules[module_name]['end'] func_prev['end'] = modules[module_name]['end']
func_prev = None func_prev = None
line = info_func_str.readline().strip('\n') line = info_func_str.readline().strip('\n')
continue continue
func_name = line.split()[1] func_name = line.split()[1]
func_start = get_address_from_string(line.split()[0]) func_start = get_address_from_string(line.split()[0])
module_name = get_module_from_addr(modules, func_start) module_name = get_module_from_addr(modules, func_start)
if func_name not in functions.keys(): if func_name not in functions.keys():
functions[func_name] = {} functions[func_name] = {}
functions[func_name][module_name] = {} functions[func_name][module_name] = {}
functions[func_name][module_name]['start'] = func_start functions[func_name][module_name]['start'] = func_start
functions[func_name][module_name]['cycles'] = 0 functions[func_name][module_name]['cycles'] = 0
functions[func_name][module_name]['count'] = 0 functions[func_name][module_name]['count'] = 0
# Set the end address of the previous function # Set the end address of the previous function
if func_prev is not None: if func_prev is not None:
func_prev['end'] = func_start func_prev['end'] = func_start
func_prev = functions[func_name][module_name] func_prev = functions[func_name][module_name]
line = info_func_str.readline().strip('\n') line = info_func_str.readline().strip('\n')
# Fixup the last function # Fixup the last function
func_prev['end'] = modules[module_name]['end'] func_prev['end'] = modules[module_name]['end']
if symbols_file is not None: if symbols_file is not None:
pickle.dump((modules, functions), open(symbols_file, "w")) pickle.dump((modules, functions), open(symbols_file, "w"))
except: except:
if symbols_file is None: if symbols_file is None:
print "Error: Symbols file is required when run out of ARM DS-5" print "Error: Symbols file is required when run out of ARM DS-5"
sys.exit() sys.exit()
(modules, functions) = pickle.load(open(symbols_file, "r")) (modules, functions) = pickle.load(open(symbols_file, "r"))
# #
# Build optimized table for the <Unknown> functions # Build optimized table for the <Unknown> functions
# #
functions_addr = {} functions_addr = {}
for func_key, module in functions.iteritems(): for func_key, module in functions.iteritems():
for module_key, module_value in module.iteritems(): for module_key, module_value in module.iteritems():
key = module_value['start'] & ~0x0FFF key = module_value['start'] & ~0x0FFF
if key not in functions_addr.keys(): if key not in functions_addr.keys():
functions_addr[key] = {} functions_addr[key] = {}
if func_key not in functions_addr[key].keys(): if func_key not in functions_addr[key].keys():
functions_addr[key][func_key] = {} functions_addr[key][func_key] = {}
functions_addr[key][func_key][module_key] = module_value functions_addr[key][func_key][module_key] = module_value
# #
# Process the trace file # Process the trace file
# #
if trace_name is None: if trace_name is None:
sys.exit() sys.exit()
trace = open(trace_name, "r") trace = open(trace_name, "r")
trace_size = os.path.getsize(trace_name) trace_size = os.path.getsize(trace_name)
trace_process = 0 trace_process = 0
# Get the column names from the first line # Get the column names from the first line
columns = trace_read().split() columns = trace_read().split()
column_addr = columns.index('Address') column_addr = columns.index('Address')
column_cycles = columns.index('Cycles') column_cycles = columns.index('Cycles')
column_function = columns.index('Function') column_function = columns.index('Function')
line = trace_read() line = trace_read()
i = 0 i = 0
prev_callee = None prev_callee = None
while line: while line:
try: try:
func_name = line.split('\t')[column_function].strip() func_name = line.split('\t')[column_function].strip()
address = get_address_from_string(line.split('\t')[column_addr]) address = get_address_from_string(line.split('\t')[column_addr])
cycles = int(line.split('\t')[column_cycles]) cycles = int(line.split('\t')[column_cycles])
callee = add_cycles_to_function(functions, func_name, address, cycles) callee = add_cycles_to_function(functions, func_name, address, cycles)
if (prev_callee != None) and (prev_callee != callee): if (prev_callee != None) and (prev_callee != callee):
functions[prev_callee[0]][prev_callee[1]]['count'] += 1 functions[prev_callee[0]][prev_callee[1]]['count'] += 1
prev_callee = callee prev_callee = callee
except ValueError: except ValueError:
pass pass
line = trace_read() line = trace_read()
if ((i % 1000000) == 0) and (i != 0): if ((i % 1000000) == 0) and (i != 0):
percent = (trace_process * 100.00) / trace_size percent = (trace_process * 100.00) / trace_size
print "Processing file ... (%.2f %%)" % (percent) print "Processing file ... (%.2f %%)" % (percent)
i = i + 1 i = i + 1
# Fixup the last callee # Fixup the last callee
functions[prev_callee[0]][prev_callee[1]]['count'] += 1 functions[prev_callee[0]][prev_callee[1]]['count'] += 1
# #
# Process results # Process results
# #
functions_cycles = {} functions_cycles = {}
all_functions_cycles = {} all_functions_cycles = {}
total_cycles = 0 total_cycles = 0
for func_key, module in functions.iteritems(): for func_key, module in functions.iteritems():
for module_key, module_value in module.iteritems(): for module_key, module_value in module.iteritems():
key = "%s/%s" % (module_key, func_key) key = "%s/%s" % (module_key, func_key)
functions_cycles[key] = (module_value['cycles'], module_value['count']) functions_cycles[key] = (module_value['cycles'], module_value['count'])
total_cycles += module_value['cycles'] total_cycles += module_value['cycles']
if func_key not in all_functions_cycles.keys(): if func_key not in all_functions_cycles.keys():
all_functions_cycles[func_key] = (module_value['cycles'], module_value['count']) all_functions_cycles[func_key] = (module_value['cycles'], module_value['count'])
else: else:
all_functions_cycles[func_key] = tuple(map(sum, zip(all_functions_cycles[func_key], (module_value['cycles'], module_value['count'])))) all_functions_cycles[func_key] = tuple(map(sum, zip(all_functions_cycles[func_key], (module_value['cycles'], module_value['count']))))
sorted_functions_cycles = sorted(functions_cycles.iteritems(), key=operator.itemgetter(1), reverse = True) sorted_functions_cycles = sorted(functions_cycles.iteritems(), key=operator.itemgetter(1), reverse = True)
sorted_all_functions_cycles = sorted(all_functions_cycles.items(), key=operator.itemgetter(1), reverse = True) sorted_all_functions_cycles = sorted(all_functions_cycles.items(), key=operator.itemgetter(1), reverse = True)
print print
print "----" print "----"
for (key,value) in sorted_functions_cycles[:20]: for (key,value) in sorted_functions_cycles[:20]:
if value[0] != 0: if value[0] != 0:
print "%s (cycles: %d - %d%%, count: %d)" % (key, value[0], (value[0] * 100) / total_cycles, value[1]) print "%s (cycles: %d - %d%%, count: %d)" % (key, value[0], (value[0] * 100) / total_cycles, value[1])
else: else:
break; break;
print "----" print "----"
for (key,value) in sorted_all_functions_cycles[:20]: for (key,value) in sorted_all_functions_cycles[:20]:
if value[0] != 0: if value[0] != 0:
print "%s (cycles: %d - %d%%, count: %d)" % (key, value[0], (value[0] * 100) / total_cycles, value[1]) print "%s (cycles: %d - %d%%, count: %d)" % (key, value[0], (value[0] * 100) / total_cycles, value[1])
else: else:
break; break;