本文整理汇总了Java中com.squareup.haha.perflib.ClassInstance.FieldValue方法的典型用法代码示例。如果您正苦于以下问题:Java ClassInstance.FieldValue方法的具体用法?Java ClassInstance.FieldValue怎么用?Java ClassInstance.FieldValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.haha.perflib.ClassInstance
的用法示例。
在下文中一共展示了ClassInstance.FieldValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: threadName
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
static String threadName(Instance holder) {
List<ClassInstance.FieldValue> values = classInstanceValues(holder);
Object nameField = fieldValue(values, "name");
if (nameField == null) {
// Sometimes we can't find the String at the expected memory address in the heap dump.
// See https://github.com/square/leakcanary/issues/417 .
return "Thread name not available";
}
return asString(nameField);
}
示例2: hasField
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
static boolean hasField(List<ClassInstance.FieldValue> values, String fieldName) {
for (ClassInstance.FieldValue fieldValue : values) {
if (fieldValue.getField().getName().equals(fieldName)) {
//noinspection unchecked
return true;
}
}
return false;
}
示例3: findLeakingReference
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
private Instance findLeakingReference(String key, Snapshot snapshot) {
ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName());
List<String> keysFound = new ArrayList<String>();
for (Instance instance : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> values = classInstanceValues(instance);
String keyCandidate = asString(fieldValue(values, "key"));
if (keyCandidate.equals(key)) {
return fieldValue(values, "referent");
}
keysFound.add(keyCandidate);
}
throw new IllegalStateException(
"Could not find weak reference with key " + key + " in " + keysFound);
}
示例4: findTrackedReferences
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
public List<TrackedReference> findTrackedReferences(File heapDumpFile) {
if (!heapDumpFile.exists()) {
throw new IllegalArgumentException("File does not exist: " + heapDumpFile);
}
try {
HprofBuffer buffer = new MemoryMappedFileBuffer(heapDumpFile);
HprofParser parser = new HprofParser(buffer);
Snapshot snapshot = parser.parse();
deduplicateGcRoots(snapshot);
ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName());
List<TrackedReference> references = new ArrayList<>();
for (Instance weakRef : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> values = classInstanceValues(weakRef);
String key = asString(fieldValue(values, "key"));
String name =
hasField(values, "name") ? asString(fieldValue(values, "name")) : "(No name field)";
Instance instance = fieldValue(values, "referent");
if (instance != null) {
String className = getClassName(instance);
List<String> fields = describeFields(instance);
references.add(new TrackedReference(key, name, className, fields));
}
}
return references;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
示例5: findLeakingReference
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
private Instance findLeakingReference(String key, Snapshot snapshot) {
ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName());
List<String> keysFound = new ArrayList<>();
for (Instance instance : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> values = classInstanceValues(instance);
String keyCandidate = asString(fieldValue(values, "key"));
if (keyCandidate.equals(key)) {
return fieldValue(values, "referent");
}
keysFound.add(keyCandidate);
}
throw new IllegalStateException(
"Could not find weak reference with key " + key + " in " + keysFound);
}
示例6: fieldToString
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
static String fieldToString(ClassInstance.FieldValue fieldValue) {
return fieldToString(fieldValue.getField(), fieldValue.getValue());
}
示例7: classInstanceValues
import com.squareup.haha.perflib.ClassInstance; //导入方法依赖的package包/类
static List<ClassInstance.FieldValue> classInstanceValues(Instance instance) {
ClassInstance classInstance = (ClassInstance) instance;
return classInstance.getValues();
}