1

自動テストの実行中に、Android フォンで Systrace レポートを取得したいと考えています。テストにかかる時間は不明であるため、Systrace の--time期間を指定することはできません。

systrace.py をさらに掘り下げると、systraceatrace使用してカーネル ログを取得していることがわかりました。

adb shell atrace --help私は次の出力を使用して得ました:

usage: atrace [options] [categories...]
options include:
  -a appname      enable app-level tracing for a comma separated list of cmdlines
  -b N            use a trace buffer size of N KB
  -c              trace into a circular buffer
  -k fname,...    trace the listed kernel functions
  -n              ignore signals
  -s N            sleep for N seconds before tracing [default 0]
  -t N            trace for N seconds [defualt 5]
  -z              compress the trace dump
  --async_start   start circular trace and return immediatly
  --async_dump    dump the current contents of circular trace buffer
  --async_stop    stop tracing and dump the current contents of circular
                    trace buffer
  --list_categories
                  list the available tracing categories

自動テストの開始時にatraceを使用してトレースを開始し、自動テストの終了時にトレースとカーネル ログのダンプを停止するにはどうすればよいですか?

以下のコマンドを使ってみましたが、うまく動かないと思います。async_dump だけがログにいくつかのデータを提供します。async_stop ダンプのログにはコンテンツがありません。トレースを適切に開始し、ダンプしてから停止するにはどうすればよいですか?

adb shell atrace -b 10000 -c am shedgfx view --async_start > C:\Users\user1\Desktop\log.txt 

adb shell atrace -b 10000 -c am shedgfx view --async_dump  > C:\Users\user1\Desktop\log.txt 

adb shell atrace -b 10000 -c am shedgfx view --async_stop > C:\Users\user1\Desktop\log.txt 
4

1 に答える 1

0
  1. schedgfxおそらく 2 つの別個の呼び出しである必要があります: schedgfx. 実行時にデバイスからの出力を確認します。

    $ adb shell atrace --list_categories

  2. カテゴリはコマンド ラインの最後の部分にする必要があります (コマンドでは、カテゴリはasync_*オプションの前に配置されます)。

    $ adb shell atrace --help usage: atrace [options] [categories...] options include: -a appname enable app-level tracing for a comma separated list of cmdlines -b N use a trace buffer size of N KB -c trace into a circular buffer -k fname,... trace the listed kernel functions -n ignore signals -s N sleep for N seconds before tracing [default 0] -t N trace for N seconds [defualt 5] -z compress the trace dump --async_start start circular trace and return immediatly --async_dump dump the current contents of circular trace buffer --async_stop stop tracing and dump the current contents of circular trace buffer --list_categories list the available tracing categories

  3. このツールは循環バッファーで実行されるため、dump コマンドを実行するたびに、その時点でバッファーにある内容のみが取得されます。Espressorules:0.5パッケージ (Espresso を使用していると仮定) には、次のメソッドAtraceLoggerを呼び出すことにより、テスト ハーネスの一部としてこれを自動化するのに役立つクラスがあります。atraceStart(...)

    public void atraceStart(Set<String> traceCategoriesSet, int atraceBufferSize, int dumpIntervalSecs, File destDirectory, String traceFileName) throws IOException

    @Rule または @ClassRule を作成するか、TestRunner などの他の方法でフックすることで、これを行うことができます。

    @Override
    protected void before() throws Throwable {
        mAtrace = AtraceLogger.getAtraceLoggerInstance(InstrumentationRegistry.getInstrumentation());
        mAtrace.atraceStart(new HashSet<>(Arrays.asList("gfx", "sched", ...)),
                1024 /* bufferSize */, 1 /* dump interval */,
                RuleLoggingUtils.getTestRunDir(), "filename");
    }
    
    @Override
    protected void after() {
        try {
            mAtrace.atraceStop();
        } catch (IOException e) {
            Log.w(TAG, "Failed to stop Atrace", e);
        } catch (InterruptedException e) {
            Log.w(TAG, "Failed to stop Atrace", e);
        }
    }
    

    このRuleLoggingUtils.getTestRunDir()メソッドは、キャプチャされたダンプ ファイルをアプリの外部ファイル パスに配置するため、テストの終了後に次を使用してこれらのファイルを取得できます。

    $ adb pull /sdcard/Android/data/com.yourcompany.package/files/testdata/

そして、各 atrace ファイルは、--from-file=<trace file>オプションを指定して systrace を実行することにより、systrace ビューアーを使用して調べることができます。

于 2016-05-12T15:53:28.763 に答える