Android: 有些日志被跳过了吗?

huangapple go评论80阅读模式
英文:

Android: Logcat skipping some logs?

问题

我正在使用Logcat来调试使用OpenGL的应用程序。我的OpenGL onDraw循环每秒进入30到60次。我在此循环中放置了'许多'Log.d(大约30个),以便调试我的应用程序(即查看哪些代码部分耗时较长)。

我的问题是,我发现LogCat中并没有显示我所有的Log.d。它们在每帧中被随机忽略了。

这个问题似乎已经有人知道了,例如这里

是否有任何解决方案来避免这个问题?还有其他日志工具吗?在Android Studio中有任何要更改的设置吗?是否有任何变通方法?

谢谢!

英文:

I am using Logcat to debug my app that uses OpenGL. My OpenGL onDraw loop is entered 30 to 60 times per second. I placed 'many' Log.d (around 30) in this loop in order to debug my app (namely to see which part of the code are too time consuming).

My problem is that I see that I don't have all my Log.d in the LogCat. They are randomly ignored on each frame.

This problem seems already known, for example here.

Is there any solution in order to avoid this problem ? Any other log tool ? Any settings to change in Android studio ? Any workaround ?

Thanks !

答案1

得分: 1

有一个轻量级的日志记录框架,你可以使用它来记录日志,它还可以将日志记录到文件中。

我建议要么将日志记录到文件中,要么减少日志记录。你说你针对单个帧进行了大约30次日志记录。如果在一秒钟内做这样的操作达到60次,那就意味着每秒钟有1800条日志。因此,大约每半毫秒你就会记录一次日志。

除了在几秒钟内溢出logcat缓冲区之外,这种做法实际上并不会帮助你。

我建议你为时间测量定义一个起点和一个终点,并对其进行修改,以找到耗时过长的部分。同时,只记录测量时间,不要依赖于logcat中日志的时间戳。因此,不要记录“start”和“stop”时间戳,只记录实际持续时间。

我还假设你在onDraw()中调用了一些函数或进行了一些循环。这些是开始分别进行测量的好地方。此外,要考虑到日志记录本身可能会影响性能,因此在onDraw()中进行过多的日志记录可能会返回错误的结果。

编辑

还有这个答案可能对你有帮助:https://stackoverflow.com/a/35553778/180538

编辑2

关于这个问题的“链接”已经有11年的历史了。很可能这个“问题”已经被修复了。我记得我曾经自己写过一个文件日志记录器,从未遇到过这个问题,我甚至在一个单行循环中记录了10000行日志…

英文:

There is a lightweight logger framework that you can use that is also capable of logging into a file.

I would recommend doing either logging into a file or reducing your logging. You said you log around 30 times for a single frame. Doing that up to 60 times in a second means 1800 logs a second. So around every half millisecond you log something.

Beside the fact that you overflow the logcat buffer this way in a few seconds, it will not really help you.

I would recommend to define a start and an endpoint for your time measurement and modify it to find the part that is too time consuming. Also only log the measured time, do not rely on the timestamp of the log in the logcat. So don't log "start" and "stop" timestamps, only the real duration.

I also assume that you are calling some functions or do some loops in your onDraw(). These are a good place to start separate measuring. Also consider that logging itself might have an effect on the performance so throwing too much logging into the onDraw() will likely return wrong results.

edit

There is also this answer which might help you too: https://stackoverflow.com/a/35553778/180538

edit2

Your "link" about the issue is 11 years old. It is very likely that this "issue" is already fixed. I do remember that I wrote a file logger once myself and never experienced this issue and I plain logged 10000 lines in a one line for loop...

答案2

得分: 0

在Android Studio中,您可以过滤logcat输出。只需在logcat中右键单击该行,然后选择“过滤类似项”。然后,对过滤规则进行微调。

抱歉,我现在在手机上,所以不太确定具体的命名,但它绝对存在。我经常使用它。

英文:

In Android Studio, you can filter logcat output. Just right-click the line in the logcat and select "Filter similar". Then fine-tune your filtering rule.

Sorry, I'm on phone, so not sure of exact naming, but it's definitely there. I use it often.

答案3

得分: 0

解决了我的问题。实际上,问题是因为我在应用程序的其他部分生成了许多其他日志。由于LogCat中有一个过滤器,我没有看到它们。移除过滤器后,我能够看到所有的日志,我发现有很多日志来自其他线程;我注释了这些其他日志。问题解决了 Android: 有些日志被跳过了吗? 感谢你的帮助!

英文:

Solved my problem. Actually, the problem was due to the fact that I had a lot of other logs generated in other parts of my app. I didn't see them as I had a filter in LogCat. Removing the filter allowed me to see all my logs, I saw that I had a lot of logs coming from other threads ; I commented these other logs. Solved my issue Android: 有些日志被跳过了吗? Thanks for your help !

huangapple
  • 本文由 发表于 2020年9月30日 20:19:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64137437.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定