stackcollapse-ljp.awk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. $1 == "Total" {
  50. # We're done. Print last stack and exit.
  51. print stack, count
  52. exit
  53. }
  54. {
  55. # Strip file location. Comment this out to keep.
  56. gsub(/\(.*\)/, "")
  57. }
  58. NF == 3 {
  59. # New stack begins. Print previous buffered stack.
  60. if (count)
  61. print stack, count
  62. # Begin a new stack.
  63. count = $1
  64. stack = $3
  65. }
  66. NF == 1 {
  67. # Build stack.
  68. stack = $1 ";" stack
  69. }