Repository: mozilla/bugbug

Issue:
Add ploc metric
The old `lloc` behavior has been renamed as `ploc` to better describe what that metric is being calculating.  The new `lloc` behavior should be added instead #1497 


Discussion:

Resolving patch:
diff --git a/bugbug/commit_features.py b/bugbug/commit_features.py
--- a/bugbug/commit_features.py
+++ b/bugbug/commit_features.py
@@ -142,6 +142,7 @@ def __call__(self, commit, **kwargs):
             "Average number of unique operators": commit["average_halstead_n1"],
             "Average number of operators": commit["average_halstead_N1"],
             "Average number of source loc": commit["average_source_loc"],
+            "Average number of instruction loc": commit["average_instruction_loc"],
             "Average number of logical loc": commit["average_logical_loc"],
             "Maximum cyclomatic": commit["maximum_cyclomatic"],
             "Maximum number of unique operands": commit["maximum_halstead_n2"],
@@ -149,6 +150,7 @@ def __call__(self, commit, **kwargs):
             "Maximum number of unique operators": commit["maximum_halstead_n1"],
             "Maximum number of operators": commit["maximum_halstead_N1"],
             "Maximum number of source loc": commit["maximum_source_loc"],
+            "Maximum number of instruction loc": commit["maximum_instruction_loc"],
             "Maximum number of logical loc": commit["maximum_logical_loc"],
             "Minimum cyclomatic": commit["minimum_cyclomatic"],
             "Minimum number of unique operands": commit["minimum_halstead_n2"],
@@ -156,11 +158,13 @@ def __call__(self, commit, **kwargs):
             "Minimum number of unique operators": commit["minimum_halstead_n1"],
             "Minimum number of operators": commit["minimum_halstead_N1"],
             "Minimum number of source loc": commit["minimum_source_loc"],
+            "Minimum number of instruction loc": commit["minimum_instruction_loc"],
             "Minimum number of logical loc": commit["minimum_logical_loc"],
             "Total of number of operands": commit["total_halstead_N2"],
             "Total of number of unique operators": commit["total_halstead_n1"],
             "Total number of operators": commit["total_halstead_N1"],
             "Total number of source loc": commit["total_source_loc"],
+            "Total number of instruction loc": commit["total_instruction_loc"],
             "Total number of logical loc": commit["total_logical_loc"],
         }
 
@@ -558,6 +562,10 @@ def merge_commits(commits: Sequence[repository.CommitDict]) -> repository.Commit
                 commit["average_source_loc"] for commit in commits
             )
             / len(commits),
+            "average_instruction_loc": sum(
+                commit["average_instruction_loc"] for commit in commits
+            )
+            / len(commits),
             "average_logical_loc": sum(
                 commit["average_logical_loc"] for commit in commits
             )
@@ -580,6 +588,9 @@ def merge_commits(commits: Sequence[repository.CommitDict]) -> repository.Commit
             "maximum_source_loc": max(
                 commit["maximum_source_loc"] for commit in commits
             ),
+            "maximum_instruction_loc": max(
+                commit["maximum_instruction_loc"] for commit in commits
+            ),
             "maximum_logical_loc": max(
                 commit["maximum_logical_loc"] for commit in commits
             ),
@@ -601,6 +612,9 @@ def merge_commits(commits: Sequence[repository.CommitDict]) -> repository.Commit
             "minimum_source_loc": min(
                 commit["minimum_source_loc"] for commit in commits
             ),
+            "minimum_instruction_loc": min(
+                commit["minimum_instruction_loc"] for commit in commits
+            ),
             "minimum_logical_loc": min(
                 commit["minimum_logical_loc"] for commit in commits
             ),
@@ -609,6 +623,9 @@ def merge_commits(commits: Sequence[repository.CommitDict]) -> repository.Commit
             "total_halstead_n1": sum(commit["total_halstead_n1"] for commit in commits),
             "total_halstead_N1": sum(commit["total_halstead_N1"] for commit in commits),
             "total_source_loc": sum(commit["total_source_loc"] for commit in commits),
+            "total_instruction_loc": sum(
+                commit["total_instruction_loc"] for commit in commits
+            ),
             "total_logical_loc": sum(commit["total_logical_loc"] for commit in commits),
         }
     )
diff --git a/bugbug/repository.py b/bugbug/repository.py
--- a/bugbug/repository.py
+++ b/bugbug/repository.py
@@ -180,6 +180,7 @@ def __init__(
         self.average_halstead_N2 = 0.0
         self.average_halstead_n2 = 0.0
         self.average_source_loc = 0.0
+        self.average_instruction_loc = 0.0
         self.average_logical_loc = 0.0
         self.maximum_cyclomatic = 0
         self.maximum_halstead_N2 = 0
@@ -187,6 +188,7 @@ def __init__(
         self.maximum_halstead_N1 = 0
         self.maximum_halstead_n1 = 0
         self.maximum_source_loc = 0
+        self.maximum_instruction_loc = 0
         self.maximum_logical_loc = 0
         self.minimum_cyclomatic = sys.maxsize
         self.minimum_halstead_N1 = sys.maxsize
@@ -194,6 +196,7 @@ def __init__(
         self.minimum_halstead_N2 = sys.maxsize
         self.minimum_halstead_n2 = sys.maxsize
         self.minimum_source_loc = sys.maxsize
+        self.minimum_instruction_loc = sys.maxsize
         self.minimum_logical_loc = sys.maxsize
         self.total_cyclomatic = 0
         self.total_halstead_N1 = 0
@@ -201,6 +204,7 @@ def __init__(
         self.total_halstead_N2 = 0
         self.total_halstead_n2 = 0
         self.total_source_loc = 0
+        self.total_instruction_loc = 0
         self.total_logical_loc = 0
 
     def __eq__(self, other):
@@ -453,6 +457,7 @@ def get_metrics(commit, metrics_space):
         commit.total_halstead_n1 += metrics["halstead"]["n1"]
         commit.total_halstead_N1 += metrics["halstead"]["N1"]
         commit.total_source_loc += metrics["loc"]["sloc"]
+        commit.total_instruction_loc += metrics["loc"]["ploc"]
         commit.total_logical_loc += metrics["loc"]["lloc"]
 
         commit.maximum_cyclomatic = max(
@@ -475,6 +480,9 @@ def get_metrics(commit, metrics_space):
         commit.maximum_source_loc = max(
             metrics["loc"]["sloc"], commit.maximum_source_loc
         )
+        commit.maximum_instruction_loc = max(
+            metrics["loc"]["ploc"], commit.maximum_instruction_loc
+        )
         commit.maximum_logical_loc = max(
             metrics["loc"]["lloc"], commit.maximum_logical_loc
         )
@@ -499,6 +507,9 @@ def get_metrics(commit, metrics_space):
         commit.minimum_source_loc = min(
             metrics["loc"]["sloc"], commit.minimum_source_loc
         )
+        commit.minimum_instruction_loc = min(
+            metrics["loc"]["ploc"], commit.minimum_instruction_loc
+        )
         commit.minimum_logical_loc = min(
             metrics["loc"]["lloc"], commit.minimum_logical_loc
         )
@@ -637,6 +648,9 @@ def transform(hg: hglib.client, repo_dir: str, commit: Commit):
         commit.average_halstead_n1 = commit.total_halstead_n1 / metrics_file_count
         commit.average_halstead_N1 = commit.total_halstead_N1 / metrics_file_count
         commit.average_source_loc = commit.total_source_loc / metrics_file_count
+        commit.average_instruction_loc = (
+            commit.total_instruction_loc / metrics_file_count
+        )
         commit.average_logical_loc = commit.total_logical_loc / metrics_file_count
     else:
         # these values are initialized with sys.maxsize (because we take the min)
@@ -647,6 +661,7 @@ def transform(hg: hglib.client, repo_dir: str, commit: Commit):
         commit.minimum_halstead_N1 = 0
         commit.minimum_halstead_n1 = 0
         commit.minimum_source_loc = 0
+        commit.minimum_instruction_loc = 0
         commit.minimum_logical_loc = 0
 
     return commit


Test patch: