androidx.core.os.TraceCompat Java Examples

The following examples show how to use androidx.core.os.TraceCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystraceTestActivity.java    From AndroidAll with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TraceCompat.beginSection("TraceInit");

    InitHelper.initStetho(this);
    InitHelper.initWeex(this);
    InitHelper.initJPush(this);
    InitHelper.initFresco(this);
    InitHelper.initAMap(this);
    InitHelper.initUmeng(this);
    InitHelper.initBugly(this);

    TraceCompat.endSection();


}
 
Example #2
Source File: L.java    From lottie-android with Apache License 2.0 6 votes vote down vote up
public static float endSection(String section) {
  if (depthPastMaxDepth > 0) {
    depthPastMaxDepth--;
    return 0;
  }
  if (!traceEnabled) {
    return 0;
  }
  traceDepth--;
  if (traceDepth == -1) {
    throw new IllegalStateException("Can't end trace section. There are none.");
  }
  if (!section.equals(sections[traceDepth])) {
    throw new IllegalStateException("Unbalanced trace call " + section +
        ". Expected " + sections[traceDepth] + ".");
  }
  TraceCompat.endSection();
  return (System.nanoTime() - startTimeNs[traceDepth]) / 1000000f;
}
 
Example #3
Source File: L.java    From lottie-android with Apache License 2.0 5 votes vote down vote up
public static void beginSection(String section) {
  if (!traceEnabled) {
    return;
  }
  if (traceDepth == MAX_DEPTH) {
    depthPastMaxDepth++;
    return;
  }
  sections[traceDepth] = section;
  startTimeNs[traceDepth] = System.nanoTime();
  TraceCompat.beginSection(section);
  traceDepth++;
}
 
Example #4
Source File: GapWorker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void prefetchInnerRecyclerViewWithDeadline(@Nullable RecyclerView innerView,
        long deadlineNs) {
    if (innerView == null) {
        return;
    }

    if (innerView.mDataSetHasChangedAfterLayout
            && innerView.mChildHelper.getUnfilteredChildCount() != 0) {
        // RecyclerView has new data, but old attached views. Clear everything, so that
        // we can prefetch without partially stale data.
        innerView.removeAndRecycleViews();
    }

    // do nested prefetch!
    final LayoutPrefetchRegistryImpl innerPrefetchRegistry = innerView.mPrefetchRegistry;
    innerPrefetchRegistry.collectPrefetchPositionsFromView(innerView, true);

    if (innerPrefetchRegistry.mCount != 0) {
        try {
            TraceCompat.beginSection(RecyclerView.TRACE_NESTED_PREFETCH_TAG);
            innerView.mState.prepareForNestedPrefetch(innerView.mAdapter);
            for (int i = 0; i < innerPrefetchRegistry.mCount * 2; i += 2) {
                // Note that we ignore immediate flag for inner items because
                // we have lower confidence they're needed next frame.
                final int innerPosition = innerPrefetchRegistry.mPrefetchArray[i];
                prefetchPositionWithDeadline(innerView, innerPosition, deadlineNs);
            }
        } finally {
            TraceCompat.endSection();
        }
    }
}
 
Example #5
Source File: GapWorker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        TraceCompat.beginSection(RecyclerView.TRACE_PREFETCH_TAG);

        if (mRecyclerViews.isEmpty()) {
            // abort - no work to do
            return;
        }

        // Query most recent vsync so we can predict next one. Note that drawing time not yet
        // valid in animation/input callbacks, so query it here to be safe.
        final int size = mRecyclerViews.size();
        long latestFrameVsyncMs = 0;
        for (int i = 0; i < size; i++) {
            RecyclerView view = mRecyclerViews.get(i);
            if (view.getWindowVisibility() == View.VISIBLE) {
                latestFrameVsyncMs = Math.max(view.getDrawingTime(), latestFrameVsyncMs);
            }
        }

        if (latestFrameVsyncMs == 0) {
            // abort - either no views visible, or couldn't get last vsync for estimating next
            return;
        }

        long nextFrameNs = TimeUnit.MILLISECONDS.toNanos(latestFrameVsyncMs) + mFrameIntervalNs;

        prefetch(nextFrameNs);

        // TODO: consider rescheduling self, if there's more work to do
    } finally {
        mPostTimeNs = 0;
        TraceCompat.endSection();
    }
}
 
Example #6
Source File: GapWorker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void prefetchInnerRecyclerViewWithDeadline(@Nullable RecyclerView innerView,
        long deadlineNs) {
    if (innerView == null) {
        return;
    }

    if (innerView.mDataSetHasChangedAfterLayout
            && innerView.mChildHelper.getUnfilteredChildCount() != 0) {
        // RecyclerView has new data, but old attached views. Clear everything, so that
        // we can prefetch without partially stale data.
        innerView.removeAndRecycleViews();
    }

    // do nested prefetch!
    final LayoutPrefetchRegistryImpl innerPrefetchRegistry = innerView.mPrefetchRegistry;
    innerPrefetchRegistry.collectPrefetchPositionsFromView(innerView, true);

    if (innerPrefetchRegistry.mCount != 0) {
        try {
            TraceCompat.beginSection(RecyclerView.TRACE_NESTED_PREFETCH_TAG);
            innerView.mState.prepareForNestedPrefetch(innerView.mAdapter);
            for (int i = 0; i < innerPrefetchRegistry.mCount * 2; i += 2) {
                // Note that we ignore immediate flag for inner items because
                // we have lower confidence they're needed next frame.
                final int innerPosition = innerPrefetchRegistry.mPrefetchArray[i];
                prefetchPositionWithDeadline(innerView, innerPosition, deadlineNs);
            }
        } finally {
            TraceCompat.endSection();
        }
    }
}
 
Example #7
Source File: GapWorker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        TraceCompat.beginSection(RecyclerView.TRACE_PREFETCH_TAG);

        if (mRecyclerViews.isEmpty()) {
            // abort - no work to do
            return;
        }

        // Query most recent vsync so we can predict next one. Note that drawing time not yet
        // valid in animation/input callbacks, so query it here to be safe.
        final int size = mRecyclerViews.size();
        long latestFrameVsyncMs = 0;
        for (int i = 0; i < size; i++) {
            RecyclerView view = mRecyclerViews.get(i);
            if (view.getWindowVisibility() == View.VISIBLE) {
                latestFrameVsyncMs = Math.max(view.getDrawingTime(), latestFrameVsyncMs);
            }
        }

        if (latestFrameVsyncMs == 0) {
            // abort - either no views visible, or couldn't get last vsync for estimating next
            return;
        }

        long nextFrameNs = TimeUnit.MILLISECONDS.toNanos(latestFrameVsyncMs) + mFrameIntervalNs;

        prefetch(nextFrameNs);

        // TODO: consider rescheduling self, if there's more work to do
    } finally {
        mPostTimeNs = 0;
        TraceCompat.endSection();
    }
}
 
Example #8
Source File: MainActivity.java    From DelayLoadSample with Apache License 2.0 4 votes vote down vote up
private void updateText() {
    TraceCompat.beginSection("updateText");
    imageWidthTxt.setText("image : w=" + zhihuImg.getWidth());
    imageHeightTxt.setText("image : h=" + zhihuImg.getWidth());
    TraceCompat.endSection();
}
 
Example #9
Source File: LinearLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The magic functions :). Fills the given layout, defined by the layoutState. This is fairly
 * independent from the rest of the {@link LinearLayoutManager}
 * and with little change, can be made publicly available as a helper class.
 *
 * @param recycler        Current recycler that is attached to RecyclerView
 * @param layoutState     Configuration on how we should fill out the available space.
 * @param state           Context passed by the RecyclerView to control scroll steps.
 * @param stopOnFocusable If true, filling stops in the first focusable new child
 * @return Number of pixels that it added. Useful for scroll functions.
 */
int fill(RecyclerView.Recycler recycler, LayoutState layoutState,
        RecyclerView.State state, boolean stopOnFocusable) {
    // max offset we should set is mFastScroll + available
    final int start = layoutState.mAvailable;
    if (layoutState.mScrollingOffset != LayoutState.SCROLLING_OFFSET_NaN) {
        // TODO ugly bug fix. should not happen
        if (layoutState.mAvailable < 0) {
            layoutState.mScrollingOffset += layoutState.mAvailable;
        }
        recycleByLayoutState(recycler, layoutState);
    }
    int remainingSpace = layoutState.mAvailable + layoutState.mExtraFillSpace;
    LayoutChunkResult layoutChunkResult = mLayoutChunkResult;
    while ((layoutState.mInfinite || remainingSpace > 0) && layoutState.hasMore(state)) {
        layoutChunkResult.resetInternal();
        if (RecyclerView.VERBOSE_TRACING) {
            TraceCompat.beginSection("LLM LayoutChunk");
        }
        layoutChunk(recycler, state, layoutState, layoutChunkResult);
        if (RecyclerView.VERBOSE_TRACING) {
            TraceCompat.endSection();
        }
        if (layoutChunkResult.mFinished) {
            break;
        }
        layoutState.mOffset += layoutChunkResult.mConsumed * layoutState.mLayoutDirection;
        /**
         * Consume the available space if:
         * * layoutChunk did not request to be ignored
         * * OR we are laying out scrap children
         * * OR we are not doing pre-layout
         */
        if (!layoutChunkResult.mIgnoreConsumed || layoutState.mScrapList != null
                || !state.isPreLayout()) {
            layoutState.mAvailable -= layoutChunkResult.mConsumed;
            // we keep a separate remaining space because mAvailable is important for recycling
            remainingSpace -= layoutChunkResult.mConsumed;
        }

        if (layoutState.mScrollingOffset != LayoutState.SCROLLING_OFFSET_NaN) {
            layoutState.mScrollingOffset += layoutChunkResult.mConsumed;
            if (layoutState.mAvailable < 0) {
                layoutState.mScrollingOffset += layoutState.mAvailable;
            }
            recycleByLayoutState(recycler, layoutState);
        }
        if (stopOnFocusable && layoutChunkResult.mFocusable) {
            break;
        }
    }
    if (DEBUG) {
        validateChildOrder();
    }
    return start - layoutState.mAvailable;
}
 
Example #10
Source File: LinearLayoutManager.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The magic functions :). Fills the given layout, defined by the layoutState. This is fairly
 * independent from the rest of the {@link LinearLayoutManager}
 * and with little change, can be made publicly available as a helper class.
 *
 * @param recycler        Current recycler that is attached to RecyclerView
 * @param layoutState     Configuration on how we should fill out the available space.
 * @param state           Context passed by the RecyclerView to control scroll steps.
 * @param stopOnFocusable If true, filling stops in the first focusable new child
 * @return Number of pixels that it added. Useful for scroll functions.
 */
int fill(RecyclerView.Recycler recycler, LayoutState layoutState,
        RecyclerView.State state, boolean stopOnFocusable) {
    // max offset we should set is mFastScroll + available
    final int start = layoutState.mAvailable;
    if (layoutState.mScrollingOffset != LayoutState.SCROLLING_OFFSET_NaN) {
        // TODO ugly bug fix. should not happen
        if (layoutState.mAvailable < 0) {
            layoutState.mScrollingOffset += layoutState.mAvailable;
        }
        recycleByLayoutState(recycler, layoutState);
    }
    int remainingSpace = layoutState.mAvailable + layoutState.mExtraFillSpace;
    LayoutChunkResult layoutChunkResult = mLayoutChunkResult;
    while ((layoutState.mInfinite || remainingSpace > 0) && layoutState.hasMore(state)) {
        layoutChunkResult.resetInternal();
        if (RecyclerView.VERBOSE_TRACING) {
            TraceCompat.beginSection("LLM LayoutChunk");
        }
        layoutChunk(recycler, state, layoutState, layoutChunkResult);
        if (RecyclerView.VERBOSE_TRACING) {
            TraceCompat.endSection();
        }
        if (layoutChunkResult.mFinished) {
            break;
        }
        layoutState.mOffset += layoutChunkResult.mConsumed * layoutState.mLayoutDirection;
        /**
         * Consume the available space if:
         * * layoutChunk did not request to be ignored
         * * OR we are laying out scrap children
         * * OR we are not doing pre-layout
         */
        if (!layoutChunkResult.mIgnoreConsumed || layoutState.mScrapList != null
                || !state.isPreLayout()) {
            layoutState.mAvailable -= layoutChunkResult.mConsumed;
            // we keep a separate remaining space because mAvailable is important for recycling
            remainingSpace -= layoutChunkResult.mConsumed;
        }

        if (layoutState.mScrollingOffset != LayoutState.SCROLLING_OFFSET_NaN) {
            layoutState.mScrollingOffset += layoutChunkResult.mConsumed;
            if (layoutState.mAvailable < 0) {
                layoutState.mScrollingOffset += layoutState.mAvailable;
            }
            recycleByLayoutState(recycler, layoutState);
        }
        if (stopOnFocusable && layoutChunkResult.mFocusable) {
            break;
        }
    }
    if (DEBUG) {
        validateChildOrder();
    }
    return start - layoutState.mAvailable;
}