@Test public void testDefaultDisabled() { ShadowDebug.setNativeHeapSize(4 * 1024); ShadowDebug.setNativeHeapAllocatedSize(3 * 1024); MemoryMetrics snapshot = new MemoryMetrics(); MemoryMetricsCollector collector = new MemoryMetricsCollector(); collector.getSnapshot(snapshot); assertThat(collector.getSnapshot(snapshot)).isFalse(); assertThat(snapshot.nativeHeapSizeKb).isEqualTo(0); assertThat(snapshot.nativeHeapAllocatedKb).isEqualTo(0); }
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }  }
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }  @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }  @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics();  }