Android7.1 logd 日志记录缓冲区大小
作者:互联网
Android logd日志原理 http://gityuan.com/2018/01/27/android-log/
一.先看上层
1.1. 布局 KEY
private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size"; private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
1.2. writeLogdSizeOption()
updateLogpersistValues()
private void writeLogdSizeOption(Object newValue) { boolean disable = (newValue != null) && (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)); String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); if (currentTag == null) { currentTag = ""; } // filter clean and unstack all references to our setting String newTag = currentTag.replaceAll( ",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst( "^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll( ",+", ",").replaceFirst( ",+$", ""); if (disable) { newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE; // Make sure snet_event_log get through first, but do not override String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY); if ((snetValue == null) || (snetValue.length() == 0)) { snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY); if ((snetValue == null) || (snetValue.length() == 0)) { SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I"); } } // Silence all log sources, security logs notwithstanding if (newTag.length() != 0) { newTag = "," + newTag; } // Stack settings, stack to help preserve original value newTag = SELECT_LOGD_TAG_SILENCE + newTag; } if (!newTag.equals(currentTag)) { SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag); } String defaultValue = defaultLogdSizeValue(); final String size = ((newValue != null) && (newValue.toString().length() != 0)) ? newValue.toString() : defaultValue; SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size); SystemProperties.set("ctl.start", "logd-reinit"); pokeSystemProperties(); updateLogdSizeValues(); } private void updateLogdSizeValues() { if (mLogdSize != null) { String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY); if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE; } if (mLogpersist != null) { String currentLogpersistEnable = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE); if ((currentLogpersistEnable == null) || !currentLogpersistEnable.equals("true") || currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) { writeLogpersistOption(null, true); mLogpersist.setEnabled(false); } else if (mLastEnabledState) { mLogpersist.setEnabled(true); } } if ((currentValue == null) || (currentValue.length() == 0)) { currentValue = defaultLogdSizeValue(); } //gatsby 加载res 资源 String[] values = getResources().getStringArray(R.array.select_logd_size_values); String[] titles = getResources().getStringArray(R.array.select_logd_size_titles); int index = 2; // punt to second entry if not found if (SystemProperties.get("ro.config.low_ram").equals("true")) { mLogdSize.setEntries(R.array.select_logd_size_lowram_titles); titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles); index = 1; } String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries); for (int i = 0; i < titles.length; i++) { if (currentValue.equals(values[i]) || currentValue.equals(titles[i])) { index = i; break; } } mLogdSize.setValue(values[index]); mLogdSize.setSummary(summaries[index]); mLogdSize.setOnPreferenceChangeListener(this); } }
二.LogBuffer.cpp
persist.logd.size
persist.logd.size
ro.logd.size
LOG_BUFFER_SIZE, 即256k
LOG_BUFFER_MIN_SIZE, 即64k
三.默认512K
--- a/frameworks/base/packages/SettingsLib/res/values-zh-rCN/arrays.xml +++ b/frameworks/base/packages/SettingsLib/res/values-zh-rCN/arrays.xml @@ -62,6 +62,7 @@ <item msgid="8665206199209698501">"关闭"</item> <item msgid="1593289376502312923">"64K"</item> <item msgid="487545340236145324">"256K"</item> + <item msgid="487545340236145324">"512K"</item> <item msgid="2423528675294333831">"1M"</item> <item msgid="180883774509476541">"4M"</item> <item msgid="2803199102589126938">"16M"</item> @@ -76,6 +77,7 @@ <item msgid="6921048829791179331">"关闭"</item> <item msgid="2969458029344750262">"每个日志缓冲区 64K"</item> <item msgid="1342285115665698168">"每个日志缓冲区 256K"</item> + <item>"每个日志缓冲区 512K"</item> <item msgid="1314234299552254621">"每个日志缓冲区 1M"</item> <item msgid="3606047780792894151">"每个日志缓冲区 4M"</item> <item msgid="5431354956856655120">"每个日志缓冲区 16M"</item> diff --git a/frameworks/base/packages/SettingsLib/res/values/arrays.xml b/frameworks/base/packages/SettingsLib/res/values/arrays.xml old mode 100644 new mode 100755 index 920e061..b57115b --- a/frameworks/base/packages/SettingsLib/res/values/arrays.xml +++ b/frameworks/base/packages/SettingsLib/res/values/arrays.xml @@ -122,6 +122,7 @@ <string-array name="select_logd_size_values" translatable="false" > <item>32768</item> <item>65536</item> + <item>524288</item> <item>262144</item> <item>1048576</item> <item>4194304</item> diff --git a/system/core/logd/LogBuffer.cpp b/system/core/logd/LogBuffer.cpp old mode 100644 new mode 100755 index 0497a89..5a2a597 --- a/system/core/logd/LogBuffer.cpp +++ b/system/core/logd/LogBuffer.cpp @@ -97,14 +97,20 @@ void LogBuffer::init() { static const char global_tuneable[] = "persist.logd.size"; // Settings App static const char global_default[] = "ro.logd.size"; // BoardConfig.mk + SLOGE("gatsby LogBuffer init"); + unsigned long default_size = property_get_size(global_tuneable); + SLOGE("000 gatsby default_size -> %lu .",default_size); if (!default_size) { + SLOGE("000 gatsby !!!default_size aaa -> %lu .",default_size); default_size = property_get_size(global_default); + SLOGE("000 gatsby !!!default_size bbb -> %lu .",default_size); if (!default_size) { default_size = property_get_bool("ro.config.low_ram", BOOL_DEFAULT_FALSE) ? LOG_BUFFER_MIN_SIZE // 64K : LOG_BUFFER_SIZE; // 256K + SLOGE("000 gatsby !!!!!default_size ccc -> %lu .",default_size); } } @@ -116,24 +122,32 @@ void LogBuffer::init() { snprintf(key, sizeof(key), "%s.%s", global_tuneable, android_log_id_to_name(i)); + //getprop persist.logd.size unsigned long property_size = property_get_size(key); if (!property_size) { snprintf(key, sizeof(key), "%s.%s", global_default, android_log_id_to_name(i)); property_size = property_get_size(key); + SLOGE("111 gatsby global_tuneable -> %s . android_log_id_to_name(i) -> %s .",global_tuneable,android_log_id_to_name(i)); + SLOGE("111 gatsby property_size -> %lu .",property_size); } if (!property_size) { property_size = default_size; + SLOGE("2222 gatsby property_size -> %lu .",property_size); } if (!property_size) { + //256k property_size = LOG_BUFFER_SIZE; + SLOGE("333 gatsby property_size -> %lu .",property_size); } if (setSize(i, property_size)) { + //64k setSize(i, LOG_BUFFER_MIN_SIZE); + SLOGE("444 gatsby property_size -> %lu .",property_size); } } bool lastMonotonic = monotonic;
标签:default,LOGD,Android7.1,logd,缓冲区,property,SELECT,size 来源: https://www.cnblogs.com/crushgirl/p/14721722.html