use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class AppStateMonitorTest method updatePerfSession_isAfterSendingForegroundOrBackgroundSession.
@Test
public void updatePerfSession_isAfterSendingForegroundOrBackgroundSession() {
AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
monitor.registerForAppState(SessionManager.getInstance().getAppStateCallback());
monitor.setStopTime(new Timer(currentTime));
monitor.setIsColdStart(false);
// Mandatory due to circular dependencies of singletons AppStateMonitor and SessionManager
AppStateMonitor.getInstance().setIsColdStart(false);
// Foreground -> Background, sends _fs
PerfSession currentSession = SessionManager.getInstance().perfSession().build();
monitor.onActivityResumed(activity1);
verify(transportManager, times(1)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
PerfSession sentSession = argTraceMetric.getValue().getPerfSessions(0);
Assert.assertEquals(currentSession, sentSession);
// Background -> Foreground, sends _bs
currentSession = SessionManager.getInstance().perfSession().build();
monitor.onActivityStopped(activity1);
verify(transportManager, times(2)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
sentSession = argTraceMetric.getValue().getPerfSessions(0);
Assert.assertEquals(currentSession, sentSession);
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class AppStateMonitorTest method setUp.
@Before
public void setUp() {
currentTime = 0;
initMocks(this);
doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(clock).getTime();
activity1 = createFakeActivity(/* isHardwareAccelerated= */
true);
activity2 = createFakeActivity(/* isHardwareAccelerated= */
true);
DeviceCacheManager.clearInstance();
ConfigResolver.clearInstance();
ConfigResolver configResolver = ConfigResolver.getInstance();
configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class FragmentStateMonitorTest method setUp.
@Before
public void setUp() {
currentTime = 0;
initMocks(this);
doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(clock).getTime();
DeviceCacheManager.clearInstance();
when(configResolver.isPerformanceMonitoringEnabled()).thenReturn(true);
doNothing().when(recorder).start();
doNothing().when(recorder).startFragment(any());
activity = createFakeActivity(true);
// Sample frame counts.
frameCounts1 = new PerfFrameMetrics(9, 5, 3);
frameCounts2 = new PerfFrameMetrics(14, 9, 4);
savedInstanceState = mock(Bundle.class);
appStateMonitor = mock(AppStateMonitor.class);
mockFragment1 = mock(Fragment.class);
mockFragment2 = mock(Fragment.class);
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class FirebasePerfOkHttpClient method execute.
@Keep
public static Response execute(final Call call) throws IOException {
final Response response;
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
Timer timer = new Timer();
long startTimeMicros = timer.getMicros();
try {
response = call.execute();
long responseCompletedTimeMicros = timer.getDurationMicros();
sendNetworkMetric(response, builder, startTimeMicros, responseCompletedTimeMicros);
} catch (IOException e) {
Request request = call.request();
if (request != null) {
HttpUrl url = request.url();
if (url != null) {
builder.setUrl(url.url().toString());
}
String method = request.method();
if (method != null) {
builder.setHttpMethod(request.method());
}
}
builder.setRequestStartTimeMicros(startTimeMicros);
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
NetworkRequestMetricBuilderUtil.logError(builder);
throw e;
}
return response;
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class Trace method startStage.
/**
* Start a stage. If a stage is already running, it is stopped.
*
* @param name Name to be given to the stage.
* @hide
*/
void startStage(@NonNull String name) {
Timer currentTime = clock.getTime();
setEndTimeOfLastStage(currentTime);
subtraces.add(new Trace(this, name, currentTime, null, null, null, null));
}
Aggregations