JS 与 trick 代码的运用及解析全攻略
1203
2022-11-03
Log4a 是一个基于 mmap, 高性能、高可用的 Android 日志收集框架
Log4a
(English | 中文)
Log4a is an mmap based, high-performance, highly available Android log collection framework
WHY Log4a:
If you like, welcome to star/fork it or follow me.
Log4a uses file mapping memory(mmap) as a cache, that the integrity of the log can be guaranteed without sacrificing performance. The log will be first written to file mapping memory, based on the mmap feature, even if the user kill the process, the log data will not be lost, and will write back to the log file at the next time Log4a is initialized.
For mobile developers, with some users's online feedback which is difficult to reproduce the problem, analysis of the log is sometimes necessary to solve the problem. However, the collection of logs has always been a pain point, that is, performance and log integrity can not have both. To achieve high-performance log collection, it is bound to use a lot of memory, the first write the log into memory, and then at the right time to write the log which in memory to the file system (flush) If flushing before the user kill the process, then the contents of the memory will be lost. Real-time write log to file can be written to ensure the integrity of the log, but the write file is a IO operation, involves the user mode and kernel state switch, compared to write directly to the memory will be more time-consuming, frequent writes in the UI thread file will cause Caton , Affect the user experience.
HOW:
Use the same way as the android.util.Log, the difference is that you need a simple configuration, of course, also reserves a wealth of interfaces for expansion of use, more advanced configuration can view Sample;
Add dependencies in the build.gradle file:
allprojects { repositories { maven { url 'https://jitpack.io' } }} dependencies { compile 'com.github.pqpo:Log4a:{last-version}'}
Set and initialize Log4a: https://github.com/pqpo/Log4a/blob/master/app/src/main/java/me/pqpo/log4a/LogInit.java Use the same way as the android.util.Log:
Log4a.i(TAG, "Hello,Log4a!");
Choose to refresh the cache ** or ** free the memory at the right time
Log4a.flush();//orLog4a.release();
Performance Testing
you can download Sample APK for testing on your device.。
The following are the test cases for writing 1w logs in Google Pixel and Moto X:
Google pixel on the chart test data as follows (sorted by elapsed time):
device | test type | time consumed | complete? | persistent? | complete after kill the process? |
---|---|---|---|---|---|
Google Pixel | Mem | 13ms | Y | N | N |
Google Pixel | Log4a | 50ms | Y | Y | Y |
Google Pixel | File with Buffer | 61ms | Y | Y | N |
Google Pixel | Android Log | 184ms | N | N | N |
Google Pixel | File no Buffer | 272ms | Y | Y | Y |
Log4a can be seen writing the performance of the log behind direct write memory, and the use of BufferOutputStream write the same file, in fact, in order to ensure multi-threaded security, Log4a write mmap memory are locked, unlocked Case can be closer to write the speed of memory (interested are free to test). BufferOutputStream is the first data cache in memory, and then refresh the file, if the power was removed before the refresh or kill the process, then the memory data will be lost can not be restored. Log4a will restore the log file the next time you start to ensure the integrity of the log.
CHANGE LOG
see change log file
Thanks
Tencent/marsXLog
About Me:
Email: pqponet@gmail.comGitHub: pqpoBlog: pqpo's notesTwitter: PqponetWeChat: pqpo_me
License
Copyright 2017 pqpoLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~