SKETCH Add performance tracking for rendering

Differential Revision: D3709400

fbshipit-source-id: a006b60feb3fc5cb55cc2e6f08275fcc8de1d3e1
This commit is contained in:
Scott Buckfelder
2016-08-30 14:15:48 -07:00
committed by Facebook Github Bot 4
parent 5d32075363
commit 16f76d4407
4 changed files with 55 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.bridge;
import java.util.Map;
public interface PerformanceCounter {
public Map<String,Double> getPerformanceCounters();
}

View File

@@ -13,6 +13,8 @@ import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
@@ -143,6 +145,20 @@ public class ReactContext extends ContextWrapper {
mLifecycleEventListeners.remove(listener);
}
public Map<String, Map<String,Double>> getAllPerformanceCounters() {
Map<String, Map<String,Double>> totalPerfMap =
new HashMap<>();
if (mCatalystInstance != null) {
for (NativeModule nativeModule : mCatalystInstance.getNativeModules()) {
if (nativeModule instanceof PerformanceCounter) {
PerformanceCounter perfCounterModule = (PerformanceCounter) nativeModule;
totalPerfMap.put(nativeModule.getName(), perfCounterModule.getPerformanceCounters());
}
}
}
return totalPerfMap;
}
public void addActivityEventListener(ActivityEventListener listener) {
mActivityEventListeners.add(listener);
}