aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java
diff options
context:
space:
mode:
authorGravatar Klaas Boesche <klaasb@google.com>2015-10-05 14:39:50 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-10-05 15:16:54 +0000
commit358db6450bdfcd80c6f3d11cc2010fce548a1bc1 (patch)
tree5349d4fa410df61106d428c4d51cb305583b081b /src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java
parenta67ac5c6fc2b7b5c20a0fd87fe5b8c61fd346b7f (diff)
Refactor SkylarkStatistics to reduce size.
Does not save all Tasks anymore and generates TasksStatistics on the fly. Adds an ArrayList implementation for primitive longs to efficiently save a lot of task duration data. Necessary when loading lots of profile files. -- MOS_MIGRATED_REVID=104656311
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java b/src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java
index 72afab45bf..2b60eb73e8 100644
--- a/src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java
+++ b/src/main/java/com/google/devtools/build/lib/profiler/statistics/TasksStatistics.java
@@ -13,9 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.profiler.statistics;
-import com.google.devtools.build.lib.profiler.ProfileInfo;
import com.google.devtools.build.lib.profiler.ProfileInfo.Task;
-
+import com.google.devtools.build.lib.util.LongArrayList;
import java.util.List;
/**
@@ -32,7 +31,6 @@ public class TasksStatistics {
*/
public final double standardDeviationMillis;
public final long totalNanos;
- public final long selfNanos;
public TasksStatistics(
String name,
@@ -41,8 +39,7 @@ public class TasksStatistics {
long maxNanos,
double medianNanos,
double standardDeviationMillis,
- long totalNanos,
- long selfNanos) {
+ long totalNanos) {
this.name = name;
this.count = count;
this.minNanos = minNanos;
@@ -50,7 +47,6 @@ public class TasksStatistics {
this.medianNanos = medianNanos;
this.standardDeviationMillis = standardDeviationMillis;
this.totalNanos = totalNanos;
- this.selfNanos = selfNanos;
}
public double minimumMillis() {
@@ -77,44 +73,55 @@ public class TasksStatistics {
return toMilliSeconds(totalNanos);
}
- public double selfMillis() {
- return toMilliSeconds(selfNanos);
- }
-
- public double selfMeanNanos() {
- return selfNanos / count;
- }
-
- public double selfMeanMillis() {
- return toMilliSeconds(selfMeanNanos());
+ @Override
+ public String toString() {
+ return String.format(
+ "%s %d %.3f %.3f %.3f %.3f %.3f %.3f",
+ name,
+ count,
+ minimumMillis(),
+ meanMillis(),
+ medianMillis(),
+ maximumMillis(),
+ standardDeviationMillis,
+ totalMillis());
}
/**
* @return The set of statistics grouped in this class, computed from a list of {@link Task}s.
*/
public static TasksStatistics create(String name, List<Task> tasks) {
- tasks = ProfileInfo.TASK_DURATION_ORDERING.immutableSortedCopy(tasks);
- int count = tasks.size();
- long min = tasks.get(0).durationNanos;
- long max = tasks.get(count - 1).durationNanos;
+ LongArrayList durations = new LongArrayList(tasks.size());
+ for (Task task : tasks) {
+ durations.add(task.durationNanos);
+ }
+ return create(name, durations);
+ }
+
+ /**
+ * @return The set of statistics grouped in this class, computed from a list of durations
+ */
+ public static TasksStatistics create(String name, LongArrayList durations) {
+ durations.sort();
+ int count = durations.size();
+ long min = durations.get(0);
+ long max = durations.get(count - 1);
int midIndex = count / 2;
double median =
- tasks.size() % 2 == 0
- ? (tasks.get(midIndex).durationNanos + tasks.get(midIndex - 1).durationNanos) / 2.0
- : tasks.get(midIndex).durationNanos;
+ count % 2 == 0
+ ? (durations.get(midIndex) + durations.get(midIndex - 1)) / 2.0
+ : durations.get(midIndex);
// Compute standard deviation with a shift to avoid catastrophic cancellation
// and also do it in milliseconds, as in nanoseconds it overflows
long sum = 0L;
- long self = 0L;
double sumOfSquaredShiftedMillis = 0L;
final long shift = min;
- for (Task task : tasks) {
- sum += task.durationNanos;
- self += task.durationNanos - task.getInheritedDuration();
- double taskDurationShiftMillis = toMilliSeconds(task.durationNanos - shift);
+ for (int index = 0; index < count; index++) {
+ sum += durations.get(index);
+ double taskDurationShiftMillis = toMilliSeconds(durations.get(index) - shift);
sumOfSquaredShiftedMillis += taskDurationShiftMillis * taskDurationShiftMillis;
}
double sumShiftedMillis = toMilliSeconds(sum - count * shift);
@@ -123,7 +130,7 @@ public class TasksStatistics {
Math.sqrt(
(sumOfSquaredShiftedMillis - (sumShiftedMillis * sumShiftedMillis) / count) / count);
- return new TasksStatistics(name, count, min, max, median, standardDeviation, sum, self);
+ return new TasksStatistics(name, count, min, max, median, standardDeviation, sum);
}
static double toMilliSeconds(double nanoseconds) {