| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.BroadcastReceiver; | 7 import android.content.BroadcastReceiver; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.IntentFilter; | 10 import android.content.IntentFilter; |
| 11 import android.os.Debug; | 11 import android.os.Debug; |
| 12 import android.util.Log; | 12 import android.util.Log; |
| 13 | 13 |
| 14 import org.chromium.content.common.CommandLine; | 14 import org.chromium.base.CommandLine; |
| 15 import org.chromium.content.common.ContentSwitches; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * Logs Heap stats, such as gc count, alloc count, etc. | 18 * Logs Heap stats, such as gc count, alloc count, etc. |
| 18 * It's enabled by CommandLine.ENABLE_TEST_INTENTS, and logs whenever broadcast | 19 * It's enabled by CommandLine.ENABLE_TEST_INTENTS, and logs whenever broadcast |
| 19 * intent ACTION_LOG is received, e.g.: | 20 * intent ACTION_LOG is received, e.g.: |
| 20 * adb shell am broadcast -a com.google.android.apps.chrome.LOG_HEAP_STATS | 21 * adb shell am broadcast -a com.google.android.apps.chrome.LOG_HEAP_STATS |
| 21 */ | 22 */ |
| 22 public class HeapStatsLogger { | 23 public class HeapStatsLogger { |
| 23 private static final String TAG = "HeapStatsLogger"; | 24 private static final String TAG = "HeapStatsLogger"; |
| 24 private static final String ACTION_LOG = "com.google.android.apps.chrome.LOG
_HEAP_STATS"; | 25 private static final String ACTION_LOG = "com.google.android.apps.chrome.LOG
_HEAP_STATS"; |
| 25 | 26 |
| 26 private static HeapStatsLogger sHeapStats; | 27 private static HeapStatsLogger sHeapStats; |
| 27 | 28 |
| 28 private final HeapStatsLoggerReceiver mBroadcastReceiver; | 29 private final HeapStatsLoggerReceiver mBroadcastReceiver; |
| 29 private final HeapStatsLoggerIntentFilter mIntentFilter; | 30 private final HeapStatsLoggerIntentFilter mIntentFilter; |
| 30 | 31 |
| 31 public static void init(Context context) { | 32 public static void init(Context context) { |
| 32 if (CommandLine.getInstance().hasSwitch(CommandLine.ENABLE_TEST_INTENTS)
) { | 33 if (CommandLine.getInstance().hasSwitch(ContentSwitches.ENABLE_TEST_INTE
NTS)) { |
| 33 sHeapStats = new HeapStatsLogger(context); | 34 sHeapStats = new HeapStatsLogger(context); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 37 private HeapStatsLogger(Context context) { | 38 private HeapStatsLogger(Context context) { |
| 38 Debug.startAllocCounting(); | 39 Debug.startAllocCounting(); |
| 39 mBroadcastReceiver = new HeapStatsLoggerReceiver(); | 40 mBroadcastReceiver = new HeapStatsLoggerReceiver(); |
| 40 mIntentFilter = new HeapStatsLoggerIntentFilter(); | 41 mIntentFilter = new HeapStatsLoggerIntentFilter(); |
| 41 context.registerReceiver(mBroadcastReceiver, mIntentFilter); | 42 context.registerReceiver(mBroadcastReceiver, mIntentFilter); |
| 42 } | 43 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 63 // Format is "key=value unit", and it'll be parsed by the test | 64 // Format is "key=value unit", and it'll be parsed by the test |
| 64 // runner in order to be added to the bot graphs. | 65 // runner in order to be added to the bot graphs. |
| 65 "gc_count=" + Debug.getGlobalGcInvocationCount() + " times " + | 66 "gc_count=" + Debug.getGlobalGcInvocationCount() + " times " + |
| 66 "alloc_count=" + Debug.getGlobalAllocCount() + " times " + | 67 "alloc_count=" + Debug.getGlobalAllocCount() + " times " + |
| 67 "alloc_size=" + Debug.getGlobalAllocSize() + " bytes " + | 68 "alloc_size=" + Debug.getGlobalAllocSize() + " bytes " + |
| 68 "freed_count=" + Debug.getGlobalFreedCount() + " times " + | 69 "freed_count=" + Debug.getGlobalFreedCount() + " times " + |
| 69 "freed_size=" + Debug.getGlobalFreedSize() + " bytes" | 70 "freed_size=" + Debug.getGlobalFreedSize() + " bytes" |
| 70 ); | 71 ); |
| 71 } | 72 } |
| 72 } | 73 } |
| OLD | NEW |