Add memory profiler.
This adds two dump command, bazel dump --rules and bazel dump --skylark_memory.
dump --rules outputs a summary of the count, action count, and memory consumption of each rule and aspect class.
dump --skylark_memory outputs a pprof-compatible file with all Skylark analysis allocations. Users can then use pprof as per normal to analyse their builds.
RELNOTES: Add memory profiler.
PiperOrigin-RevId: 172558600
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index 6e1e70b..a031f2c 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -550,13 +550,12 @@
* @throws IllegalStateException if any of the required attributes is missing
*/
public RuleClass build() {
- return build(name);
+ // For built-ins, name == key
+ return build(name, name);
}
- /**
- * Same as {@link #build} except with setting the name parameter.
- */
- public RuleClass build(String name) {
+ /** Same as {@link #build} except with setting the name and key parameters. */
+ public RuleClass build(String name, String key) {
Preconditions.checkArgument(this.name.isEmpty() || this.name.equals(name));
type.checkName(name);
type.checkAttributes(attributes);
@@ -575,6 +574,7 @@
}
return new RuleClass(
name,
+ key,
skylark,
skylarkExecutable,
skylarkTestable,
@@ -1025,6 +1025,8 @@
private final String name; // e.g. "cc_library"
+ private final String key; // Just the name for native, label + name for skylark
+
/**
* The kind of target represented by this RuleClass (e.g. "cc_library rule").
* Note: Even though there is partial duplication with the {@link RuleClass#name} field,
@@ -1154,6 +1156,7 @@
@VisibleForTesting
RuleClass(
String name,
+ String key,
boolean isSkylark,
boolean skylarkExecutable,
boolean skylarkTestable,
@@ -1180,6 +1183,7 @@
Set<Label> requiredToolchains,
Attribute... attributes) {
this.name = name;
+ this.key = key;
this.isSkylark = isSkylark;
this.targetKind = name + Rule.targetKindSuffix();
this.skylarkExecutable = skylarkExecutable;
@@ -1277,6 +1281,11 @@
return name;
}
+ /** Returns a unique key. Used for profiling purposes. */
+ public String getKey() {
+ return key;
+ }
+
/**
* Returns the target kind of this class of rule (e.g. "cc_library rule").
*/