flamegraph

Fork of flamegraph without j***s*****
git clone git://git.laack.co/flamegraph.git
Log | Files | Refs | README

stackcollapse-ljp.awk (1858B)


      1 #!/usr/bin/awk -f
      2 #
      3 # stackcollapse-ljp.awk	collapse lightweight java profile reports
      4 #				into single lines stacks.
      5 #
      6 # Parses a list of multiline stacks generated by:
      7 #
      8 #  https://code.google.com/p/lightweight-java-profiler
      9 #
     10 # and outputs a semicolon separated stack followed by a space and a count.
     11 #
     12 # USAGE: ./stackcollapse-ljp.pl infile > outfile
     13 #
     14 # Example input:
     15 #
     16 #  42 3  my_func_b(prog.java:455)
     17 #        my_func_a(prog.java:123)
     18 #        java.lang.Thread.run(Thread.java:744)
     19 #  [...]
     20 #
     21 # Example output:
     22 #
     23 #  java.lang.Thread.run;my_func_a;my_func_b 42
     24 #
     25 # The unused number is the number of frames in each stack.
     26 #
     27 # Copyright 2014 Brendan Gregg.  All rights reserved.
     28 #
     29 # CDDL HEADER START
     30 #
     31 # The contents of this file are subject to the terms of the
     32 # Common Development and Distribution License (the "License").
     33 # You may not use this file except in compliance with the License.
     34 #
     35 # You can obtain a copy of the license at docs/cddl1.txt or
     36 # http://opensource.org/licenses/CDDL-1.0.
     37 # See the License for the specific language governing permissions
     38 # and limitations under the License.
     39 #
     40 # When distributing Covered Code, include this CDDL HEADER in each
     41 # file and include the License file at docs/cddl1.txt.
     42 # If applicable, add the following below this CDDL HEADER, with the
     43 # fields enclosed by brackets "[]" replaced with your own identifying
     44 # information: Portions Copyright [yyyy] [name of copyright owner]
     45 #
     46 # CDDL HEADER END
     47 #
     48 # 12-Jun-2014	Brendan Gregg	Created this.
     49 
     50 $1 == "Total" {
     51 	# We're done. Print last stack and exit.
     52 	print stack, count
     53 	exit
     54 }
     55 
     56 {
     57 	# Strip file location. Comment this out to keep.
     58 	gsub(/\(.*\)/, "")
     59 }
     60 
     61 NF == 3 {
     62 	# New stack begins. Print previous buffered stack.
     63 	if (count)
     64 		print stack, count
     65 
     66 	# Begin a new stack.
     67 	count = $1
     68 	stack = $3
     69 }
     70 
     71 NF == 1 {
     72 	# Build stack.
     73 	stack = $1 ";" stack
     74 }