简体   繁体   English

Android:Logcat 跳过一些日志?

[英]Android: Logcat skipping some logs?

I am using Logcat to debug my app that uses OpenGL.我正在使用 Logcat 调试使用 OpenGL 的应用程序。 My OpenGL onDraw loop is entered 30 to 60 times per second.我的 OpenGL onDraw 循环每秒输入 30 到 60 次。 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).我在这个循环中放置了“很多”Log.d(大约 30 个)以调试我的应用程序(即查看代码的哪一部分太耗时)。

My problem is that I see that I don't have all my Log.d in the LogCat.我的问题是我发现 LogCat 中没有我所有的 Log.d。 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 ?在 Android Studio 中需要更改任何设置吗? Any workaround ?任何解决方法?

Thanks !谢谢 !

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.你说你为一个帧记录了大约 30 次。 Doing that up to 60 times in a second means 1800 logs a second.每秒最多执行 60 次意味着每秒记录 1800 个日志。 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.除了您在几秒钟内以这种方式溢出 logcat 缓冲区这一事实之外,它不会真正帮助您。

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.也只记录测得的时间,不要依赖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().我还假设您正在调用一些函数或在 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.还要考虑到日志记录本身可能会对性能产生影响,因此在 onDraw() 中投入过多的日志记录可能会返回错误的结果。

edit编辑

There is also this answer which might help you too: https://stackoverflow.com/a/35553778/180538还有这个答案也可能对您有所帮助: https : //stackoverflow.com/a/35553778/180538

edit2编辑2

Your "link" about the issue is 11 years old.您关于该问题的“链接”已有 11 年的历史。 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...我记得我曾经自己写过一个文件记录器,但从未遇到过这个问题,我在一行 for 循环中简单地记录了 10000 行...

In Android Studio, you can filter logcat output.在 Android Studio 中,您可以过滤 logcat 输出。 Just right-click the line in the logcat and select "Filter similar".只需右键单击 logcat 中的行并选择“过滤类似”。 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.我经常使用它。

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.我没有看到它们,因为我在 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 :) Thanks for your help !解决了我的问题 :) 感谢您的帮助!

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

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