1 /*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <LogSize.h>
18
19 #include <array>
20 #include <optional>
21 #include <string>
22
23 #include <android-base/parseint.h>
24 #include <android-base/properties.h>
25
IsValidBufferSize(size_t value)26 bool IsValidBufferSize(size_t value) {
27 return kLogBufferMinSize <= value && value <= kLogBufferMaxSize;
28 }
29
30 /*
31 static std::optional<size_t> GetBufferSizeProperty(const std::string& key) {
32 std::string value = android::base::GetProperty(key, "");
33 if (value.empty()) {
34 return {};
35 }
36
37 uint32_t size;
38 if (!android::base::ParseByteCount(value, &size)) {
39 return {};
40 }
41
42 if (!IsValidBufferSize(size)) {
43 return {};
44 }
45
46 return size;
47 }
48 */
49
GetBufferSizeFromProperties(log_id_t)50 size_t GetBufferSizeFromProperties(log_id_t /*log_id*/) {
51 /*
52 * http://b/196856709
53 *
54 * We've been seeing timeouts from logcat in bugreports for years, but the
55 * rate has gone way up lately. The suspicion is that this is because we
56 * have a lot of dogfooders who still have custom (large) log sizes but
57 * the new compressed logging is cramming way more in. The bugreports I've seen
58 * have had 1,000,000+ lines, so taking 10s to collect that much logging seems
59 * plausible. Of course, it's also possible that logcat is timing out because
60 * the log is being *spammed* as it's being read. But temporarily disabling
61 * custom log sizes like this should help us confirm (or deny) whether the
62 * problem really is this simple.
63 *
64 std::string buffer_name = android_log_id_to_name(log_id);
65 std::array<std::string, 4> properties = {
66 "persist.logd.size." + buffer_name,
67 "ro.logd.size." + buffer_name,
68 "persist.logd.size",
69 "ro.logd.size",
70 };
71
72 for (const auto& property : properties) {
73 if (auto size = GetBufferSizeProperty(property)) {
74 return *size;
75 }
76 }
77 */
78
79 if (android::base::GetBoolProperty("ro.config.low_ram", false)) {
80 return kLogBufferMinSize;
81 }
82
83 return kDefaultLogBufferSize;
84 }
85