bt benchmark: Normalize indentation around invalid_commits
[lttng-ci.git] / scripts / babeltrace-benchmark / benchmark.py
index 518dce70ab117c0286ecfeb5fb53be5ffed02750..961624e6ac79d8551f31786e967a330c0587bd06 100644 (file)
@@ -38,6 +38,29 @@ from minio.error import ResponseError
 BENCHMARK_TYPES = ["dummy", "text"]
 DEFAULT_BUCKET = "lava"
 
+invalid_commits = {
+    "ec9a9794af488a9accce7708a8b0d8188b498789", # Does not build
+    "8c99128c640cbce71fb8a6caa15e4c672252b662", # Block on configure
+    "f3847c753f1b4f12353c38d97b0577d9993d19fb", # Does not build
+    "e0111295f17ddfcc33ec771a8deac505473a06ad", # Does not build
+    "d0d4e0ed487ea23aaf0d023513c0a4d86901b79b", # Does not build
+    "c24f7ab4dd9edeb5e50b0070fd9d9e8691057dde", # Does not build
+    "ce67f5614a4db3b2de4d887eca52135b439b4937", # Does not build
+    "80aff5efc66679fd934cef433c0e698694748385", # Does not build
+    "f4f11e84942d36fcc8a597d226928bce2ccac4b3", # Does not build
+    "ae466a6e1b856d96cf5112a371b4df2b732503ec", # Does not build
+}
+
+def json_type(string):
+    """
+    Argpase type for json args.
+    We expect a base dictionary.
+    """
+    passed_json = json.loads(string)
+    if not isinstance(passed_json, dict):
+        msg = "%r is not a dict" % string
+        raise argparse.ArgumentTypeError(msg)
+    return passed_json
 
 def graph_get_color(branch):
     """
@@ -126,7 +149,7 @@ def get_benchmark_results(client, commit, workdir):
     results = {}
     benchmark_valid = True
     for b_type in BENCHMARK_TYPES:
-        prefix = "/results/benchmarks/babeltrace/{}/".format(b_type)
+        prefix = "/results/benchmarks/babeltrace/{}".format(b_type)
         result_file = get_file(client, prefix, commit, workdir)
         if not result_file:
             """
@@ -186,6 +209,50 @@ def plot_raw_value(branch, benchmark_type, x_data, y_data, labels, latest_values
     plt.ylabel("User + system time (s)")
     plt.xlabel("Latest commits")
     plt.legend()
+    plt.grid(True)
+
+    # Put tick on the right side
+    ax.tick_params(labeltop=False, labelright=True)
+
+    plt.tight_layout()
+    return
+
+
+def plot_delta_between_point(
+    branch, benchmark_type, x_data, y_data, labels, latest_values
+):
+    """
+    Plot the graph of delta between each sequential commit.
+    """
+    local_abs_max = 100
+
+    # Transform y_data to a list of  for which the reference is the first
+    # element.
+    local_y_data = []
+    for pos, y in enumerate(y_data):
+        if pos == 0:
+            local_y_data.append(0.0)
+            continue
+        local_y_data.append(y - y_data[pos - 1])
+
+    plt.plot(x_data, local_y_data, "o", label=branch, color=graph_get_color(branch))
+
+    # Get max absolute value to align the y axis with zero in the middle.
+    if local_y_data:
+        local_abs_max = abs(max(local_y_data, key=abs)) * 1.3
+
+    plt.ylim(ymin=local_abs_max * -1, ymax=local_abs_max)
+
+    ax = plt.gca()
+    plt.xticks(x_data, labels, rotation=90, family="monospace")
+    plt.title(
+        graph_get_title(branch, benchmark_type) + " Delta to previous commit",
+        fontweight="bold",
+    )
+    plt.ylabel("Seconds")
+    plt.xlabel("Latest commits")
+    plt.legend()
+    plt.grid(True)
 
     # Put tick on the right side
     ax.tick_params(labeltop=False, labelright=True)
@@ -246,6 +313,7 @@ def plot_ratio(branch, benchmark_type, x_data, y_data, labels, latest_values):
     plt.ylabel("Ratio")
     plt.xlabel("Latest commits")
     plt.legend()
+    plt.grid(True)
 
     # Put tick on the right side
     ax.tick_params(labeltop=False, labelright=True)
@@ -253,6 +321,7 @@ def plot_ratio(branch, benchmark_type, x_data, y_data, labels, latest_values):
     plt.tight_layout()
     return
 
+
 def generate_graph(branches, report_name, git_path):
 
     # The PDF document
@@ -305,32 +374,41 @@ def generate_graph(branches, report_name, git_path):
             plot_raw_value(branch, b_type, x_data, y_data, labels, latest_values)
             pdf_pages.savefig(fig)
 
-            fig = plt.figure(figsize=(width, 8.27), dpi=100)
             # Use the mean of each sanitize dataset here, we do not care for
             # variance for ratio. At least not yet.
             y_data = [mean(sanitize_dataset(c[1][b_type])[0]) for c in results]
+            fig = plt.figure(figsize=(width, 8.27), dpi=100)
             plot_ratio(branch, b_type, x_data, y_data, labels, latest_values)
             pdf_pages.savefig(fig)
 
+            fig = plt.figure(figsize=(width, 8.27), dpi=100)
+            plot_delta_between_point(
+                branch, b_type, x_data, y_data, labels, latest_values
+            )
+            pdf_pages.savefig(fig)
+
     pdf_pages.close()
 
 
-def launch_jobs(branches, git_path, wait_for_completion, debug):
+def launch_jobs(branches, git_path, wait_for_completion, debug, force):
     """
     Lauch jobs for all missing results.
     """
     client = get_client()
+    commits_to_test = set()
     for branch, cutoff in branches.items():
-        commits = get_git_log(branch, cutoff, git_path)
-
+        commits = [x for x in get_git_log(branch, cutoff, git_path) if x not in invalid_commits]
         with tempfile.TemporaryDirectory() as workdir:
             for commit in commits:
                 b_results = get_benchmark_results(client, commit, workdir)[0]
-                if b_results:
+                if b_results and not force:
                     continue
-                lava_submit.submit(
-                    commit, wait_for_completion=wait_for_completion, debug=debug
-                )
+                commits_to_test.add(commit)
+    for index, commit in enumerate(commits_to_test):
+        print("Job {}/{}".format(index+1, len(commits_to_test)))
+        lava_submit.submit(
+            commit, wait_for_completion=wait_for_completion, debug=debug
+        )
 
 
 def main():
@@ -347,6 +425,9 @@ def main():
     parser.add_argument(
         "--generate-jobs", action="store_true", help="Generate and send jobs"
     )
+    parser.add_argument(
+        "--force-jobs", action="store_true", help="Force the queueing of jobs to lava"
+    )
     parser.add_argument(
         "--do-not-wait-on-completion",
         action="store_true",
@@ -368,19 +449,35 @@ def main():
     parser.add_argument(
         "--repo-path", help="The location of the git repo to use.", required=True
     )
+    parser.add_argument(
+        "--overwrite-branches-cutoff",
+        help="A dictionary of the form {"
+        "'branch_name': 'commit_hash_cutoff',...}. Allow custom graphing and"
+        "jobs generation.",
+        required=False, type=json_type
+    )
 
     args = parser.parse_args()
 
+    if args.overwrite_branches_cutoff:
+        bt_branches = args.overwrite_branches_cutoff
+
     if not os.path.exists(args.repo_path):
         print("Repository location does not exists.")
         return 1
 
     if args.generate_jobs:
         print("Launching jobs for:")
+
         for branch, cutoff in bt_branches.items():
             print("\t Branch {} with cutoff {}".format(branch, cutoff))
+
         launch_jobs(
-            bt_branches, args.repo_path, not args.do_not_wait_on_completion, args.debug
+            bt_branches,
+            args.repo_path,
+            not args.do_not_wait_on_completion,
+            args.debug,
+            args.force_jobs,
         )
 
     if args.generate_report:
This page took 0.02399 seconds and 4 git commands to generate.