Bug 1156885 - num_ctors: post to perfherder, not graphserver. r=bhearsum

MozReview-Commit-ID: JwCgwAR00uw

--HG--
extra : rebase_source : 97cf1d6344bfd82638bc9ae0a80950339ef95558
This commit is contained in:
Joel Maher 2016-02-26 12:11:33 -08:00
parent 4074e6e3f7
commit d1746487a1
2 changed files with 56 additions and 91 deletions

52
build/util/count_ctors.py Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/python
import subprocess
import re
import sys
def count_ctors(filename):
proc = subprocess.Popen(
['readelf', '-W', '-S', filename], stdout=subprocess.PIPE)
# Some versions of ld produce both .init_array and .ctors. So we have
# to check for both.
n_init_array_ctors = 0
have_init_array = False
n_ctors_ctors = 0
have_ctors = False
for line in proc.stdout:
f = line.split()
if len(f) != 11:
continue
# Don't try to int()-parse the header line for the section summaries.
if not re.match("\\[\\d+\\]", f[0]):
continue
section_name, contents, size, align = f[1], f[2], int(f[5], 16), int(f[10])
if section_name == ".ctors" and contents == "PROGBITS":
have_ctors = True
# Subtract 2 for the uintptr_t(-1) header and the null terminator.
n_ctors_ctors = size / align - 2
if section_name == ".init_array" and contents == "INIT_ARRAY":
have_init_array = True
n_init_array_ctors = size / align
if have_init_array:
# Even if we have .ctors, we shouldn't have any constructors in .ctors.
# Complain if .ctors does not look how we expect it to.
if have_ctors and n_ctors_ctors != 0:
print >>sys.stderr, "Unexpected .ctors contents for", filename
sys.exit(1)
return n_init_array_ctors
if have_ctors:
return n_ctors_ctors
# We didn't find anything; somebody switched initialization mechanisms on
# us, or the binary is completely busted. Complain either way.
print >>sys.stderr, "Couldn't find .init_array or .ctors in", filename
sys.exit(1)
if __name__ == '__main__':
for f in sys.argv[1:]:
output = {"framework": {"name": "build_metrics"}, "suites": [{"name": "compiler_metrics", "subtests": [{"name": "num_constructors", "value": count_ctors(f)}] } ]}
print "PERFHERDER_DATA: %s" % output

View File

@ -1223,9 +1223,9 @@ or run without that action (ie: --no-{action})"
def _count_ctors(self):
"""count num of ctors and set testresults."""
dirs = self.query_abs_dirs()
abs_count_ctors_path = os.path.join(dirs['abs_tools_dir'],
'buildfarm',
'utils',
abs_count_ctors_path = os.path.join(dirs['abs_src_dir'],
'build',
'util',
'count_ctors.py')
abs_libxul_path = os.path.join(dirs['abs_obj_dir'],
'dist',
@ -1233,16 +1233,7 @@ or run without that action (ie: --no-{action})"
'libxul.so')
cmd = ['python', abs_count_ctors_path, abs_libxul_path]
output = self.get_output_from_command(cmd, cwd=dirs['abs_src_dir'])
output = output.split("\t")
num_ctors = int(output[0])
testresults = [('num_ctors', 'num_ctors', num_ctors, str(num_ctors))]
self.set_buildbot_property('num_ctors',
num_ctors,
write_to_file=True)
self.set_buildbot_property('testresults',
testresults,
write_to_file=True)
self.get_output_from_command(cmd, cwd=dirs['abs_src_dir'])
def _generate_properties_file(self, path):
# TODO it would be better to grab all the properties that were
@ -1256,73 +1247,6 @@ or run without that action (ie: --no-{action})"
graph_props = dict(properties=all_current_props)
self.dump_config(path, graph_props)
def _graph_server_post(self):
"""graph server post results."""
self._assert_cfg_valid_for_action(
['base_name', 'graph_server', 'graph_selector'],
'generate-build-stats'
)
c = self.config
dirs = self.query_abs_dirs()
# grab any props available from previous run
self.generate_build_props(console_output=False,
halt_on_failure=False)
graph_server_post_path = os.path.join(dirs['abs_tools_dir'],
'buildfarm',
'utils',
'graph_server_post.py')
graph_server_path = os.path.join(dirs['abs_tools_dir'],
'lib',
'python')
# graph server takes all our build properties we had initially
# (buildbot_config) and what we updated to since
# the script ran (buildbot_properties)
graph_props_path = os.path.join(c['base_work_dir'], "graph_props.json")
self._generate_properties_file(graph_props_path)
gs_env = self.query_build_env()
gs_env.update({'PYTHONPATH': graph_server_path})
resultsname = c['base_name'] % {'branch': self.branch}
cmd = ['python', graph_server_post_path]
cmd.extend(['--server', c['graph_server']])
cmd.extend(['--selector', c['graph_selector']])
cmd.extend(['--branch', self._query_graph_server_branch_name()])
cmd.extend(['--buildid', self.query_buildid()])
cmd.extend(['--sourcestamp',
self.query_buildbot_property('sourcestamp')])
cmd.extend(['--resultsname', resultsname])
cmd.extend(['--properties-file', graph_props_path])
cmd.extend(['--timestamp', str(self.epoch_timestamp)])
self.info("Obtaining graph server post results")
result_code = self.retry(self.run_command,
args=(cmd,),
kwargs={'cwd': dirs['abs_src_dir'],
'env': gs_env})
if result_code != 0:
self.add_summary('Automation Error: failed graph server post',
level=ERROR)
self.worst_buildbot_status = self.worst_level(
TBPL_EXCEPTION, self.worst_buildbot_status,
TBPL_WORST_LEVEL_TUPLE
)
else:
self.info("graph server post ok")
def _query_graph_server_branch_name(self):
c = self.config
if c.get('graph_server_branch_name'):
return c['graph_server_branch_name']
else:
# capitalize every word in between '-'
branch_list = self.branch.split('-')
branch_list = [elem.capitalize() for elem in branch_list]
return '-'.join(branch_list)
def _query_props_set_by_mach(self, console_output=True, error_level=FATAL):
mach_properties_path = os.path.join(
self.query_abs_dirs()['abs_obj_dir'], 'dist', 'mach_build_properties.json'
@ -1995,21 +1919,10 @@ or run without that action (ie: --no-{action})"
"""
c = self.config
# grab any props available from this or previous unclobbered runs
self.generate_build_props(console_output=False,
halt_on_failure=False)
if c.get('enable_count_ctors'):
if c.get('enable_count_ctors'):
self.info("counting ctors...")
self._count_ctors()
num_ctors = self.buildbot_properties.get('num_ctors', 'unknown')
self.info("TinderboxPrint: num_ctors: %s" % (num_ctors,))
if not self.query_is_nightly():
self._graph_server_post()
else:
self.info("We are not posting to graph server as this is a "
"nightly build.")
else:
self.info("Nothing to do for this action since ctors "
"counts are disabled for this build.")