forked from square/leakcanary
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request square#30 from square/py/custom_excluded_refs
Customizable ExcludedRef
- Loading branch information
Showing
8 changed files
with
115 additions
and
82 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
library/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/ExcludedRefs.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
library/leakcanary-watcher/src/main/java/com/squareup/leakcanary/ExcludedRefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2015 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.squareup.leakcanary; | ||
|
||
import java.io.Serializable; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static com.squareup.leakcanary.Preconditions.checkNotNull; | ||
import static java.util.Collections.unmodifiableMap; | ||
import static java.util.Collections.unmodifiableSet; | ||
|
||
/** | ||
* Prevents specific references from being taken into account when computing the shortest strong | ||
* reference path from a suspected leaking instance to the GC roots. | ||
* | ||
* This class lets you ignore known memory leaks that you known about. If the shortest path | ||
* matches {@link ExcludedRefs}, than the heap analyzer should look for a longer path with nothing | ||
* matching in {@link ExcludedRefs}. | ||
*/ | ||
public final class ExcludedRefs implements Serializable { | ||
|
||
public final Map<String, Set<String>> excludeFieldMap; | ||
public final Map<String, Set<String>> excludeStaticFieldMap; | ||
public final Set<String> excludedThreads; | ||
|
||
private ExcludedRefs(Map<String, Set<String>> excludeFieldMap, | ||
Map<String, Set<String>> excludeStaticFieldMap, Set<String> excludedThreads) { | ||
// Copy + unmodifiable. | ||
this.excludeFieldMap = unmodifiableMap(new LinkedHashMap<>(excludeFieldMap)); | ||
this.excludeStaticFieldMap = unmodifiableMap(new LinkedHashMap<>(excludeStaticFieldMap)); | ||
this.excludedThreads = unmodifiableSet(new LinkedHashSet<>(excludedThreads)); | ||
} | ||
|
||
public static final class Builder { | ||
private final Map<String, Set<String>> excludeFieldMap = new LinkedHashMap<>(); | ||
private final Map<String, Set<String>> excludeStaticFieldMap = new LinkedHashMap<>(); | ||
private final Set<String> excludedThreads = new LinkedHashSet<>(); | ||
|
||
public Builder instanceField(String className, String fieldName) { | ||
checkNotNull(className, "className"); | ||
checkNotNull(fieldName, "fieldName"); | ||
Set<String> excludedFields = excludeFieldMap.get(className); | ||
if (excludedFields == null) { | ||
excludedFields = new LinkedHashSet<>(); | ||
excludeFieldMap.put(className, excludedFields); | ||
} | ||
excludedFields.add(fieldName); | ||
return this; | ||
} | ||
|
||
public Builder staticField(String className, String fieldName) { | ||
checkNotNull(className, "className"); | ||
checkNotNull(fieldName, "fieldName"); | ||
Set<String> excludedFields = excludeStaticFieldMap.get(className); | ||
if (excludedFields == null) { | ||
excludedFields = new LinkedHashSet<>(); | ||
excludeStaticFieldMap.put(className, excludedFields); | ||
} | ||
excludedFields.add(fieldName); | ||
return this; | ||
} | ||
|
||
public Builder thread(String threadName) { | ||
checkNotNull(threadName, "threadName"); | ||
excludedThreads.add(threadName); | ||
return this; | ||
} | ||
|
||
public ExcludedRefs build() { | ||
return new ExcludedRefs(excludeFieldMap, excludeStaticFieldMap, excludedThreads); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters