[Mesa-dev] [PATCH] gallivm: JIT symbol resolution with linux perf.
From: José Fonseca jfons...@vmware.com Details on docs/llvmpipe.html --- bin/perf-annotate-jit | 240 configure.ac |7 - docs/llvmpipe.html | 40 ++-- src/gallium/auxiliary/gallivm/lp_bld_debug.cpp | 117 +--- src/gallium/auxiliary/gallivm/lp_bld_debug.h |6 +- src/gallium/auxiliary/gallivm/lp_bld_init.c| 11 +- src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 23 --- src/gallium/auxiliary/gallivm/lp_bld_misc.h|3 - 8 files changed, 361 insertions(+), 86 deletions(-) create mode 100755 bin/perf-annotate-jit diff --git a/bin/perf-annotate-jit b/bin/perf-annotate-jit new file mode 100755 index 000..7ebc965 --- /dev/null +++ b/bin/perf-annotate-jit @@ -0,0 +1,240 @@ +#!/usr/bin/env python +# +# Copyright 2012 VMware Inc +# Copyright 2008-2009 Jose Fonseca +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the Software), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + + +import sys +import os.path +import re +import optparse +import subprocess + + +class Parser: +Parser interface. + +def __init__(self): +pass + +def parse(self): +raise NotImplementedError + + +class LineParser(Parser): +Base class for parsers that read line-based formats. + +def __init__(self, file): +Parser.__init__(self) +self._file = file +self.__line = None +self.__eof = False +self.line_no = 0 + +def readline(self): +line = self._file.readline() +if not line: +self.__line = '' +self.__eof = True +else: +self.line_no += 1 +self.__line = line.rstrip('\r\n') + +def lookahead(self): +assert self.__line is not None +return self.__line + +def consume(self): +assert self.__line is not None +line = self.__line +self.readline() +return line + +def eof(self): +assert self.__line is not None +return self.__eof + + +mapFile = None + +def lookupMap(filename, matchSymbol): +global mapFile +mapFile = filename +stream = open(filename, 'rt') +for line in stream: +start, length, symbol = line.split() + +start = int(start, 16) +length = int(length,16) + +if symbol == matchSymbol: +return start + +return None + +def lookupAsm(filename, desiredFunction): +stream = open(filename + '.asm', 'rt') +while stream.readline() != desiredFunction + ':\n': +pass + +asm = [] +line = stream.readline().strip() +while line: +addr, instr = line.split(':', 1) +addr = int(addr) +asm.append((addr, instr)) +line = stream.readline().strip() + +return asm + + + +samples = {} + + +class PerfParser(LineParser): +Parser for linux perf callgraph output. + +It expects output generated with + +perf record -g +perf script + + +def __init__(self, infile, symbol): +LineParser.__init__(self, infile) + self.symbol = symbol + +def readline(self): +# Override LineParser.readline to ignore comment lines +while True: +LineParser.readline(self) +if self.eof() or not self.lookahead().startswith('#'): +break + +def parse(self): +# read lookahead +self.readline() + +while not self.eof(): +self.parse_event() + +asm = lookupAsm(mapFile, self.symbol) + +addresses = samples.keys() +addresses.sort() +total_samples = 0 + + sys.stdout.write('%s:\n' % self.symbol) +for address, instr in asm: +try: +sample = samples.pop(address) +except KeyError: +sys.stdout.write(6*' ') +else: +sys.stdout.write('%6u' % (sample)) +total_samples += sample +sys.stdout.write('%6u:
Re: [Mesa-dev] [PATCH] gallivm: JIT symbol resolution with linux perf.
On 04/17/2013 06:34 AM, jfons...@vmware.com wrote: From: José Fonsecajfons...@vmware.com Details on docs/llvmpipe.html --- bin/perf-annotate-jit | 240 configure.ac |7 - docs/llvmpipe.html | 40 ++-- src/gallium/auxiliary/gallivm/lp_bld_debug.cpp | 117 +--- src/gallium/auxiliary/gallivm/lp_bld_debug.h |6 +- src/gallium/auxiliary/gallivm/lp_bld_init.c| 11 +- src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 23 --- src/gallium/auxiliary/gallivm/lp_bld_misc.h|3 - 8 files changed, 361 insertions(+), 86 deletions(-) create mode 100755 bin/perf-annotate-jit diff --git a/bin/perf-annotate-jit b/bin/perf-annotate-jit new file mode 100755 index 000..7ebc965 --- /dev/null +++ b/bin/perf-annotate-jit @@ -0,0 +1,240 @@ +#!/usr/bin/env python +# +# Copyright 2012 VMware Inc +# Copyright 2008-2009 Jose Fonseca +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the Software), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + Could you add some comments in this file explaining what this does? Maybe include a pointer to the docs page too. I'm not familiar with linux perf. LGTM, but Roland should probably review too. -Brian ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] gallivm: JIT symbol resolution with linux perf.
- Original Message - On 04/17/2013 06:34 AM, jfons...@vmware.com wrote: From: José Fonsecajfons...@vmware.com Details on docs/llvmpipe.html --- bin/perf-annotate-jit | 240 configure.ac |7 - docs/llvmpipe.html | 40 ++-- src/gallium/auxiliary/gallivm/lp_bld_debug.cpp | 117 +--- src/gallium/auxiliary/gallivm/lp_bld_debug.h |6 +- src/gallium/auxiliary/gallivm/lp_bld_init.c| 11 +- src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 23 --- src/gallium/auxiliary/gallivm/lp_bld_misc.h|3 - 8 files changed, 361 insertions(+), 86 deletions(-) create mode 100755 bin/perf-annotate-jit diff --git a/bin/perf-annotate-jit b/bin/perf-annotate-jit new file mode 100755 index 000..7ebc965 --- /dev/null +++ b/bin/perf-annotate-jit @@ -0,0 +1,240 @@ +#!/usr/bin/env python +# +# Copyright 2012 VMware Inc +# Copyright 2008-2009 Jose Fonseca +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the Software), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + Could you add some comments in this file explaining what this does? Maybe include a pointer to the docs page too. I'm not familiar with linux perf. Yes, good point. diff --git a/bin/perf-annotate-jit b/bin/perf-annotate-jit index 7ebc965..7464340 100755 --- a/bin/perf-annotate-jit +++ b/bin/perf-annotate-jit @@ -22,6 +22,17 @@ # THE SOFTWARE. # +Perf annotate for JIT code. + +Linux `perf annotate` does not work with JIT code. This script takes the data +produced by `perf script` command, plus the diassemblies outputed by gallivm +into /tmp/perf-X.map.asm and produces output similar to `perf annotate`. + +See docs/llvmpipe.html for usage instructions. + +The `perf script` output parser was derived from the gprof2dot.py script. + + import sys import os.path LGTM, but Roland should probably review too. Thanks for reviewing. Jose ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] gallivm: JIT symbol resolution with linux perf.
Am 17.04.2013 14:34, schrieb jfons...@vmware.com: From: José Fonseca jfons...@vmware.com Details on docs/llvmpipe.html --- bin/perf-annotate-jit | 240 configure.ac |7 - docs/llvmpipe.html | 40 ++-- src/gallium/auxiliary/gallivm/lp_bld_debug.cpp | 117 +--- src/gallium/auxiliary/gallivm/lp_bld_debug.h |6 +- src/gallium/auxiliary/gallivm/lp_bld_init.c| 11 +- src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 23 --- src/gallium/auxiliary/gallivm/lp_bld_misc.h|3 - 8 files changed, 361 insertions(+), 86 deletions(-) create mode 100755 bin/perf-annotate-jit diff --git a/bin/perf-annotate-jit b/bin/perf-annotate-jit new file mode 100755 index 000..7ebc965 --- /dev/null +++ b/bin/perf-annotate-jit @@ -0,0 +1,240 @@ +#!/usr/bin/env python +# +# Copyright 2012 VMware Inc +# Copyright 2008-2009 Jose Fonseca +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the Software), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + + +import sys +import os.path +import re +import optparse +import subprocess + + +class Parser: +Parser interface. + +def __init__(self): +pass + +def parse(self): +raise NotImplementedError + + +class LineParser(Parser): +Base class for parsers that read line-based formats. + +def __init__(self, file): +Parser.__init__(self) +self._file = file +self.__line = None +self.__eof = False +self.line_no = 0 + +def readline(self): +line = self._file.readline() +if not line: +self.__line = '' +self.__eof = True +else: +self.line_no += 1 +self.__line = line.rstrip('\r\n') + +def lookahead(self): +assert self.__line is not None +return self.__line + +def consume(self): +assert self.__line is not None +line = self.__line +self.readline() +return line + +def eof(self): +assert self.__line is not None +return self.__eof + + +mapFile = None + +def lookupMap(filename, matchSymbol): +global mapFile +mapFile = filename +stream = open(filename, 'rt') +for line in stream: +start, length, symbol = line.split() + +start = int(start, 16) +length = int(length,16) + +if symbol == matchSymbol: +return start + +return None + +def lookupAsm(filename, desiredFunction): +stream = open(filename + '.asm', 'rt') +while stream.readline() != desiredFunction + ':\n': +pass + +asm = [] +line = stream.readline().strip() +while line: +addr, instr = line.split(':', 1) +addr = int(addr) +asm.append((addr, instr)) +line = stream.readline().strip() + +return asm + + + +samples = {} + + +class PerfParser(LineParser): +Parser for linux perf callgraph output. + +It expects output generated with + +perf record -g +perf script + + +def __init__(self, infile, symbol): +LineParser.__init__(self, infile) + self.symbol = symbol + +def readline(self): +# Override LineParser.readline to ignore comment lines +while True: +LineParser.readline(self) +if self.eof() or not self.lookahead().startswith('#'): +break + +def parse(self): +# read lookahead +self.readline() + +while not self.eof(): +self.parse_event() + +asm = lookupAsm(mapFile, self.symbol) + +addresses = samples.keys() +addresses.sort() +total_samples = 0 + + sys.stdout.write('%s:\n' % self.symbol) +for address, instr in asm: +try: +sample =