简体   繁体   English

android traceview异步事件

[英]android traceview asynchronous events

I'd like to use traceview to measure performance for several asynchronous events. 我想使用traceview来衡量几个异步事件的性能。 The asynchronous events are passed to me in a callback that looks similar to the below code. 异步事件通过类似于以下代码的回调传递给我。

interface EventCallback {

    void onStartEvent(String name);

    void onStopEvent(String name);
}

where every asynchronous event will start with a "onStartEvent" call and end with an "onStopEvent" call. 其中每个异步事件都将以“ onStartEvent”调用开始,并以“ onStopEvent”调用结束。

I'd like to create trace files for every event. 我想为每个事件创建跟踪文件。 From my reading here ( http://developer.android.com/tools/debugging/debugging-tracing.html#creatingtracefiles ), it's not possible to trace asynchronous events since the ordering of the calls must be "structured" in a "stack" like ordering. 根据我在此处的阅读内容( http://developer.android.com/tools/debugging/debugging-tracing.html#creatingtracefiles ),由于必须在“堆栈”中“构造”调用的顺序,因此无法跟踪异步事件像订购。 So, the call to "Debug.stopMethodTracing()" always applies to the most recent call to "Debug.startMethodTracing("calc");" 因此,对“ Debug.stopMethodTracing()”的调用始终适用于对“ Debug.startMethodTracing(“ calc”);“的最新调用。

So, if I receive callbacks in the following order. 因此,如果我按以下顺序收到回调。

onStartEvent(A) onStartEvent(A)

onStartEvent(B) onStartEvent(B)

onStopEvent(A) onStopEvent(A)

onStopEvent(B) onStopEvent(B)

which will get interpreted to 这将被解释为

Debug.startMethodTracing("A"); Debug.startMethodTracing(“ A”);

Debug.startMethodTracing("B"); Debug.startMethodTracing(“ B”);

Debug.stopMethodTracing(); Debug.stopMethodTracing(); // will apply to "B" instead of "A" //将应用于“ B”而不是“ A”

Debug.stopMethodTracing(); Debug.stopMethodTracing(); // will apply to "A" instead of "B" //将应用于“ A”而不是“ B”

Using traceview, is there anyway to do what I want? 使用traceview,有什么可以做我想要的吗? ie trace "non-structured" asynchronous events? 即跟踪“非结构化”异步事件?

traceview might be the wrong tool. traceview可能是错误的工具。 If you really want to go this route you can keep an "active event count", and keep the tracefile open so long as there is an event being handled. 如果您确实想走这条路线,则可以保持“活动事件计数”,并且只要有事件正在处理,就可以保持跟踪文件处于打开状态。 This can result in multiple events being present in the same trace file, but you're tracing method calls in the VM, so there's no simple way around that. 这可能会导致多个事件出现在同一个跟踪文件中,但是您正在跟踪VM中的方法调用,因此没有简单的方法可以解决此问题。

If your events happen on different threads, you could separate them out with a post-processing step. 如果事件发生在不同的线程上,则可以通过后处理步骤将它们分开。 This would require some effort to parse the data and strip out the undesirable records. 这将需要一些努力来解析数据并去除不需要的记录。 (See eg this or this .) (请参见例如thisthis 。)

You don't really say what you're trying to measure. 您并没有真正说出自己要衡量的内容。 For example, if you just want start/end times, you could just write those to a log file of your own and skip all the traceview fun. 例如,如果只需要开始/结束时间,则可以将其写入自己的日志文件中,并跳过所有traceview的乐趣。

Depending on what you're after, systrace may be easier to work with. 根据您的需求, systrace可能更易于使用。 Unfortunately the custom event class ( Trace ) only makes the synchronous event APIs public -- if you don't mind using reflection to access non-public interfaces you can also generate async events . 不幸的是,自定义事件类( Trace )仅使同步事件API公开-如果您不介意使用反射来访问非公共接口,则还可以生成异步事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM