From ac1a86db41683ed5468fa6a45c7678c64d6014af Mon Sep 17 00:00:00 2001
From: Florent Kirchner <florent.kirchner@cea.fr>
Date: Thu, 5 Oct 2017 17:11:14 +0200
Subject: [PATCH] Add FlameGraph parameter

---
 .../markdown-report/Report_markdown.mli       |  3 ++
 src/plugins/markdown-report/md_gen.ml         | 44 ++++++++++---------
 src/plugins/markdown-report/mdr_params.ml     | 11 +++++
 src/plugins/markdown-report/mdr_params.mli    |  3 ++
 4 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/src/plugins/markdown-report/Report_markdown.mli b/src/plugins/markdown-report/Report_markdown.mli
index 5f38b40b369..1359dd68361 100644
--- a/src/plugins/markdown-report/Report_markdown.mli
+++ b/src/plugins/markdown-report/Report_markdown.mli
@@ -13,6 +13,9 @@ module Gen_draft: Parameter_sig.Bool
 (** Value of [-mdr-remarks]. *)
 module Remarks: Parameter_sig.String
 
+(** Value of [-mdr-flamegraph]. *)
+module FlameGraph: Parameter_sig.String
+
 (** Value of [-mdr-authors]. *)
 module Authors: Parameter_sig.String_list
 
diff --git a/src/plugins/markdown-report/md_gen.ml b/src/plugins/markdown-report/md_gen.ml
index 3e1f753d7d8..4b6479fc014 100644
--- a/src/plugins/markdown-report/md_gen.ml
+++ b/src/plugins/markdown-report/md_gen.ml
@@ -411,26 +411,30 @@ let gen_section_alarms is_draft =
     H1 (plain "Results of the analysis", Some "alarms") :: text_content
 
 let gen_section_callgraph is_draft =
-  let content =
-    if is_draft then
-      Comment
-        "flamegraph allow to visualize the functions and callstacks \
-         whose analysis is the most costly."
-      :: insert_marks
-    else
-      [
-        Block [
-          Text [
-            Plain "The image below shows the flamegraph (";
-            plain_link "http://www.brendangregg.com/flamegraphs.html";
-            Plain ") for the chosen entry point."
-          ]
-        ];
-        Block
-          [ Text [Image ("flamegraph", "../server.flamegraph.svg")] ]
-      ]
-  in
-  H1 (plain "Flamegraph", Some "flamegraph") :: content
+  let f = Mdr_params.FlameGraph.get () in
+  if f = "" then []
+  else begin
+    let content =
+      if is_draft then
+        Comment
+          "A flamegraph provides a visualization of the functions and callstacks \
+           whose analysis is the most costly."
+        :: insert_marks
+      else
+        [
+          Block [
+            Text [
+              Plain "The image below shows the flamegraph (";
+              plain_link "http://www.brendangregg.com/flamegraphs.html";
+              Plain ") for the chosen entry point."
+            ]
+          ];
+          Block
+            [ Text [Image ("flamegraph", f)] ]
+        ]
+    in
+    H1 (plain "Flamegraph", Some "flamegraph") :: content
+  end
 
 let gen_section_postlude is_draft =
   if is_draft then
diff --git a/src/plugins/markdown-report/mdr_params.ml b/src/plugins/markdown-report/mdr_params.ml
index 0a576f7ad4c..cc2b0d1f774 100644
--- a/src/plugins/markdown-report/mdr_params.ml
+++ b/src/plugins/markdown-report/mdr_params.ml
@@ -39,6 +39,17 @@ struct
 end
 )
 
+module FlameGraph = Empty_string(
+struct
+  let option_name = "-mdr-flamegraph"
+  let arg_name = "f"
+  let help =
+    "reads file <f> to include a FlameGraph (https://github.com/brendangregg/FlameGraph.git),\
+     allowing the most analysis-intensive callstacks to be identified\
+     quickly and accurately"
+end
+)
+
 module Authors = String_list(
 struct
   let option_name = "-mdr-authors"
diff --git a/src/plugins/markdown-report/mdr_params.mli b/src/plugins/markdown-report/mdr_params.mli
index 1809a56e844..9671bc092fb 100644
--- a/src/plugins/markdown-report/mdr_params.mli
+++ b/src/plugins/markdown-report/mdr_params.mli
@@ -12,6 +12,9 @@ module Gen_draft: Parameter_sig.Bool
 (** Value of [-mdr-remarks]. *)
 module Remarks: Parameter_sig.String
 
+(** Value of [-mdr-flamegraph]. *)
+module FlameGraph: Parameter_sig.String
+
 (** Value of [-mdr-authors]. *)
 module Authors: Parameter_sig.String_list
 
-- 
GitLab