Skip to content

Commit

Permalink
Changed the section name for the timer class to be in the start method (
Browse files Browse the repository at this point in the history
#671)

* Changed the section name for the timer class to be in the start method. This follows the more standard android.os.Trace class.

* Set value for sectionName.
  • Loading branch information
L7ColWinters authored and elihart committed Feb 5, 2019
1 parent 6f8e85a commit 50d3ded
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
9 changes: 6 additions & 3 deletions epoxy-adapter/src/main/java/com/airbnb/epoxy/DebugTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DebugTimer implements Timer {

private final String tag;
private long startTime;
private String sectionName;

DebugTimer(String tag) {
this.tag = tag;
Expand All @@ -14,25 +15,27 @@ class DebugTimer implements Timer {

private void reset() {
startTime = -1;
sectionName = null;
}

@Override
public void start() {
public void start(String sectionName) {
if (startTime != -1) {
throw new IllegalStateException("Timer was already started");
}

startTime = System.nanoTime();
this.sectionName = sectionName;
}

@Override
public void stop(String message) {
public void stop() {
if (startTime == -1) {
throw new IllegalStateException("Timer was not started");
}

float durationMs = (System.nanoTime() - startTime) / 1000000f;
Log.d(tag, String.format(message + ": %.3fms", durationMs));
Log.d(tag, String.format(sectionName + ": %.3fms", durationMs));
reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,19 @@ public void run() {

modelsBeingBuilt = new ControllerModelList(getExpectedModelCount());

timer.start();
timer.start("Models built");
buildModels();
addCurrentlyStagedModelIfExists();
timer.stop("Models built");
timer.stop();

runInterceptors();
filterDuplicatesIfNeeded(modelsBeingBuilt);
modelsBeingBuilt.freeze();

timer.start();
timer.start("Models diffed");
adapter.setModels(modelsBeingBuilt);
// This timing is only right if diffing and model building are on the same thread
timer.stop("Models diffed");
timer.stop();

modelsBeingBuilt = null;
hasBuiltModelsEver = true;
Expand Down Expand Up @@ -359,13 +359,13 @@ private void runInterceptors() {
}
}

timer.start();
timer.start("Interceptors executed");

for (Interceptor interceptor : interceptors) {
interceptor.intercept(modelsBeingBuilt);
}

timer.stop("Interceptors executed");
timer.stop();

if (modelInterceptorCallbacks != null) {
for (ModelInterceptorCallback callback : modelInterceptorCallbacks) {
Expand Down Expand Up @@ -537,7 +537,7 @@ private void filterDuplicatesIfNeeded(List<EpoxyModel<?>> models) {
return;
}

timer.start();
timer.start("Duplicates filtered");
Set<Long> modelIds = new HashSet<>(models.size());

ListIterator<EpoxyModel<?>> modelIterator = models.listIterator();
Expand All @@ -562,7 +562,7 @@ private void filterDuplicatesIfNeeded(List<EpoxyModel<?>> models) {
}
}

timer.stop("Duplicates filtered");
timer.stop();
}

private int findPositionOfDuplicate(List<EpoxyModel<?>> models, EpoxyModel<?> duplicateModel) {
Expand Down
4 changes: 2 additions & 2 deletions epoxy-adapter/src/main/java/com/airbnb/epoxy/NoOpTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class NoOpTimer implements Timer {
@Override
public void start() {
public void start(String sectionName) {

}

@Override
public void stop(String message) {
public void stop() {

}
}
4 changes: 2 additions & 2 deletions epoxy-adapter/src/main/java/com/airbnb/epoxy/Timer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.airbnb.epoxy;

interface Timer {
void start();
void stop(String message);
void start(String sectionName);
void stop();
}

0 comments on commit 50d3ded

Please sign in to comment.