gprof2dot.awk 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at http://www.graphviz.org/
  9. *************************************************************************/
  10. # remove leading underscore, then translate leading dot to underscore
  11. function canon(s) {
  12. gsub(/\./,"_",s);
  13. gsub(/^_*/,"",s);
  14. gsub(/_*$/,"",s);
  15. return s;
  16. }
  17. BEGIN {
  18. maxhue = .65
  19. minsaturation = .2;
  20. brightness = 1.0;
  21. printf ("digraph prof {\n");
  22. printf (" node [style=filled];\n");
  23. }
  24. $1 ~ /\[/ && $0 !~ "as a" {
  25. if (NF == 6) {
  26. tail = $5
  27. source = 1
  28. }
  29. else {
  30. tail = $6
  31. source = 0
  32. }
  33. mytotal = $4
  34. while (getline) {
  35. if (NF == 0) {
  36. # if (source == 1) printf("\t%s;\n",canon(tail));
  37. break
  38. }
  39. if ( $2 ~ /\./ ) {
  40. ntc = $3;
  41. gsub("/.*","",ntc);
  42. if (mytotal < 0.0000000001)
  43. color = 0.0
  44. else
  45. color = $2/(mytotal + .01);
  46. color = color/ntc;
  47. tailc = canon(tail);
  48. headc = canon($4);
  49. hue = maxhue * (1.0 - color);
  50. saturation = minsaturation
  51. + (1.0 - minsaturation) * color;
  52. brightness = .7 + .3*color;
  53. if ((tailc != "") && (headc != "")) {
  54. printf ("\t%s -> %s [color=\"%.3f %.3f %.3f\"];\n",
  55. # tailc, headc, hue, saturation, brightness);
  56. tailc, headc, hue, brightness, brightness);
  57. Degree[tailc]++; Degree[headc]++;
  58. }
  59. else { # Recursive call
  60. printf ("\t%s -> %s;\n ", canon(tail), canon($2))
  61. }
  62. }
  63. }
  64. }
  65. $2 == "cumulative" {
  66. while ($1 != "time") getline;
  67. getline;
  68. scale = $1;
  69. brightness = 1.0;
  70. while (NF > 0) {
  71. if ($1 == " ") exit;
  72. if ($(NF - 2) == "<cycle") func_name = $(NF - 3);
  73. else func_name = $(NF - 1);
  74. func_name = canon(func_name);
  75. if (Degree[func_name] > 0) {
  76. hue = maxhue * (1.0 - $1/scale);
  77. saturation = minsaturation + ((1.0 - minsaturation) * $1/scale);
  78. printf("%s [color=\"%.3f %.3f %.3f\"];\n",func_name,
  79. hue,saturation,brightness);
  80. }
  81. getline;
  82. }
  83. exit;
  84. }
  85. END { print "}" }