markzhai / markzhai/AndroidPerformanceMonitor

打印主线程堆栈的问题

Open
#94 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
6.7k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

有一个问题:

关于打印主线程堆栈的实现:

StackSampler 的 doSimple 实现如下

`protected void doSample() {
StringBuilder stringBuilder = new StringBuilder();

    for (StackTraceElement stackTraceElement : mCurrentThread.getStackTrace()) {
        stringBuilder
                .append(stackTraceElement.toString())
                .append(BlockInfo.SEPARATOR);
    }
    Log.e(TAG, stringBuilder.toString());

    synchronized (sStackMap) {
        if (sStackMap.size() == mMaxEntryCount && mMaxEntryCount > 0) {
            sStackMap.remove(sStackMap.keySet().iterator().next());
        }
        sStackMap.put(System.currentTimeMillis(), stringBuilder.toString());
    }
}`

当前只是直接 通过调用 mCurrentThread 的 getStackTrace 来获取堆栈信息,但是这个时候如果在这个方法之前有耗时的操作(比如直接sleep(10 * 1000)),那么再去获取主线程堆栈信息的时候是不是可能出现获取的堆栈不是真正出问题的地方?

在我自己测试的情况下,已经是无法正常打印堆栈信息。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at StackSampler.doSample, especially the call to mCurrentThread.getStackTrace(), and reproduce the reported case by placing a 10-second sleep before sampling. Compare the captured stack with the location where the main thread is blocked. Done means the issue's concern about whether the reported stack is accurate is verified and the observed failure has a defined resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.