diff options
-rw-r--r-- | init/property_service.cpp | 4 | ||||
-rw-r--r-- | libstats/socket/Android.bp | 21 | ||||
-rw-r--r-- | libstats/socket/benchmark/main.cpp | 19 | ||||
-rw-r--r-- | libstats/socket/benchmark/stats_event_benchmark.cpp | 54 | ||||
-rw-r--r-- | libstats/socket/include/stats_event.h | 3 | ||||
-rw-r--r-- | libstats/socket/stats_event.c | 13 | ||||
-rw-r--r-- | libstats/socket/tests/stats_event_test.cpp | 2 | ||||
-rw-r--r-- | logd/ChattyLogBuffer.cpp | 13 | ||||
-rw-r--r-- | logd/CommandListener.cpp | 2 | ||||
-rw-r--r-- | logd/SimpleLogBuffer.cpp | 66 | ||||
-rw-r--r-- | shell_and_utilities/Android.bp | 2 |
11 files changed, 39 insertions, 160 deletions
diff --git a/init/property_service.cpp b/init/property_service.cpp index 82f5b8c5d..612854d80 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -711,8 +711,8 @@ static void LoadProperties(char* data, const char* filter, const char* filename, if (it == properties->end()) { (*properties)[key] = value; } else if (it->second != value) { - LOG(WARNING) << "Overriding previous 'ro.' property '" << key << "':'" - << it->second << "' with new value '" << value << "'"; + LOG(WARNING) << "Overriding previous property '" << key << "':'" << it->second + << "' with new value '" << value << "'"; it->second = value; } } else { diff --git a/libstats/socket/Android.bp b/libstats/socket/Android.bp index 2bf0261b2..bf79ea244 100644 --- a/libstats/socket/Android.bp +++ b/libstats/socket/Android.bp @@ -89,25 +89,6 @@ cc_library_headers { min_sdk_version: "29", } -cc_benchmark { - name: "libstatssocket_benchmark", - srcs: [ - "benchmark/main.cpp", - "benchmark/stats_event_benchmark.cpp", - ], - cflags: [ - "-Wall", - "-Werror", - ], - static_libs: [ - "libstatssocket_private", - ], - shared_libs: [ - "libcutils", - "libgtest_prod", - ], -} - cc_test { name: "libstatssocket_test", srcs: [ @@ -128,7 +109,7 @@ cc_test { ], test_suites: ["device-tests", "mts"], test_config: "libstatssocket_test.xml", - //TODO(b/153588990): Remove when the build system properly separates + //TODO(b/153588990): Remove when the build system properly separates. //32bit and 64bit architectures. compile_multilib: "both", multilib: { diff --git a/libstats/socket/benchmark/main.cpp b/libstats/socket/benchmark/main.cpp deleted file mode 100644 index 5ebdf6e9a..000000000 --- a/libstats/socket/benchmark/main.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed 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://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed 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 and - * limitations under the License. - */ - -#include <benchmark/benchmark.h> - -BENCHMARK_MAIN(); diff --git a/libstats/socket/benchmark/stats_event_benchmark.cpp b/libstats/socket/benchmark/stats_event_benchmark.cpp deleted file mode 100644 index 3fc6e551f..000000000 --- a/libstats/socket/benchmark/stats_event_benchmark.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed 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://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed 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 and - * limitations under the License. - */ - -#include "benchmark/benchmark.h" -#include "stats_event.h" - -static AStatsEvent* constructStatsEvent() { - AStatsEvent* event = AStatsEvent_obtain(); - AStatsEvent_setAtomId(event, 100); - - // randomly sample atom size - int numElements = rand() % 800; - for (int i = 0; i < numElements; i++) { - AStatsEvent_writeInt32(event, i); - } - - return event; -} - -static void BM_stats_event_truncate_buffer(benchmark::State& state) { - while (state.KeepRunning()) { - AStatsEvent* event = constructStatsEvent(); - AStatsEvent_build(event); - AStatsEvent_write(event); - AStatsEvent_release(event); - } -} - -BENCHMARK(BM_stats_event_truncate_buffer); - -static void BM_stats_event_full_buffer(benchmark::State& state) { - while (state.KeepRunning()) { - AStatsEvent* event = constructStatsEvent(); - AStatsEvent_truncateBuffer(event, false); - AStatsEvent_build(event); - AStatsEvent_write(event); - AStatsEvent_release(event); - } -} - -BENCHMARK(BM_stats_event_full_buffer); diff --git a/libstats/socket/include/stats_event.h b/libstats/socket/include/stats_event.h index 601a1815a..3d3baf9cf 100644 --- a/libstats/socket/include/stats_event.h +++ b/libstats/socket/include/stats_event.h @@ -157,9 +157,6 @@ uint32_t AStatsEvent_getAtomId(AStatsEvent* event); uint8_t* AStatsEvent_getBuffer(AStatsEvent* event, size_t* size); uint32_t AStatsEvent_getErrors(AStatsEvent* event); -// exposed for benchmarking only -void AStatsEvent_truncateBuffer(struct AStatsEvent* event, bool truncate); - #ifdef __cplusplus } #endif // __CPLUSPLUS diff --git a/libstats/socket/stats_event.c b/libstats/socket/stats_event.c index a94b3a1ed..f3e808756 100644 --- a/libstats/socket/stats_event.c +++ b/libstats/socket/stats_event.c @@ -76,7 +76,6 @@ struct AStatsEvent { uint32_t numElements; uint32_t atomId; uint32_t errors; - bool truncate; bool built; size_t bufSize; }; @@ -95,7 +94,6 @@ AStatsEvent* AStatsEvent_obtain() { event->numElements = 0; event->atomId = 0; event->errors = 0; - event->truncate = true; // truncate for both pulled and pushed atoms event->built = false; event->bufSize = MAX_PUSH_EVENT_PAYLOAD; event->buf = (uint8_t*)calloc(event->bufSize, 1); @@ -318,10 +316,6 @@ uint32_t AStatsEvent_getErrors(AStatsEvent* event) { return event->errors; } -void AStatsEvent_truncateBuffer(AStatsEvent* event, bool truncate) { - event->truncate = truncate; -} - static void build_internal(AStatsEvent* event, const bool push) { if (event->numElements > MAX_BYTE_VALUE) event->errors |= ERROR_TOO_MANY_FIELDS; if (0 == event->atomId) event->errors |= ERROR_NO_ATOM_ID; @@ -341,13 +335,6 @@ static void build_internal(AStatsEvent* event, const bool push) { } event->buf[POS_NUM_ELEMENTS] = event->numElements; - - // Truncate the buffer to the appropriate length in order to limit our - // memory usage. - if (event->truncate) { - event->buf = (uint8_t*)realloc(event->buf, event->numBytesWritten); - event->bufSize = event->numBytesWritten; - } } void AStatsEvent_build(AStatsEvent* event) { diff --git a/libstats/socket/tests/stats_event_test.cpp b/libstats/socket/tests/stats_event_test.cpp index cc2552119..9a1fac89f 100644 --- a/libstats/socket/tests/stats_event_test.cpp +++ b/libstats/socket/tests/stats_event_test.cpp @@ -18,7 +18,7 @@ #include <gtest/gtest.h> #include <utils/SystemClock.h> -// Keep in sync stats_event.c. Consider moving to separate header file to avoid duplication. +// Keep in sync with stats_event.c. Consider moving to separate header file to avoid duplication. /* ERRORS */ #define ERROR_NO_TIMESTAMP 0x1 #define ERROR_NO_ATOM_ID 0x2 diff --git a/logd/ChattyLogBuffer.cpp b/logd/ChattyLogBuffer.cpp index f92fe65c8..c21344866 100644 --- a/logd/ChattyLogBuffer.cpp +++ b/logd/ChattyLogBuffer.cpp @@ -327,7 +327,6 @@ class LogBufferElementLast { // bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { LogReaderThread* oldest = nullptr; - bool busy = false; bool clearAll = pruneRows == ULONG_MAX; auto reader_threads_lock = std::lock_guard{reader_list()->reader_threads_lock()}; @@ -359,17 +358,16 @@ bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_u } if (oldest && oldest->start() <= element.sequence()) { - busy = true; KickReader(oldest, id, pruneRows); - break; + return false; } it = Erase(it); if (--pruneRows == 0) { - break; + return true; } } - return busy; + return true; } // prune by worst offenders; by blacklist, UID, and by PID of system UID @@ -440,7 +438,6 @@ bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_u LogBufferElement& element = *it; if (oldest && oldest->start() <= element.sequence()) { - busy = true; // Do not let chatty eliding trigger any reader mitigation break; } @@ -577,7 +574,6 @@ bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_u } if (oldest && oldest->start() <= element.sequence()) { - busy = true; if (!whitelist) KickReader(oldest, id, pruneRows); break; } @@ -605,7 +601,6 @@ bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_u } if (oldest && oldest->start() <= element.sequence()) { - busy = true; KickReader(oldest, id, pruneRows); break; } @@ -615,5 +610,5 @@ bool ChattyLogBuffer::Prune(log_id_t id, unsigned long pruneRows, uid_t caller_u } } - return (pruneRows > 0) && busy; + return pruneRows == 0 || it == logs().end(); } diff --git a/logd/CommandListener.cpp b/logd/CommandListener.cpp index 9764c443e..39c54904b 100644 --- a/logd/CommandListener.cpp +++ b/logd/CommandListener.cpp @@ -82,7 +82,7 @@ int CommandListener::ClearCmd::runCommand(SocketClient* cli, int argc, return 0; } - cli->sendMsg(buf()->Clear((log_id_t)id, uid) ? "busy" : "success"); + cli->sendMsg(buf()->Clear((log_id_t)id, uid) ? "success" : "busy"); return 0; } diff --git a/logd/SimpleLogBuffer.cpp b/logd/SimpleLogBuffer.cpp index 292a7e405..ec08d54d4 100644 --- a/logd/SimpleLogBuffer.cpp +++ b/logd/SimpleLogBuffer.cpp @@ -212,46 +212,38 @@ bool SimpleLogBuffer::FlushTo( return true; } -// clear all rows of type "id" from the buffer. bool SimpleLogBuffer::Clear(log_id_t id, uid_t uid) { - bool busy = true; - // If it takes more than 4 tries (seconds) to clear, then kill reader(s) - for (int retry = 4;;) { - if (retry == 1) { // last pass - // Check if it is still busy after the sleep, we say prune - // one entry, not another clear run, so we are looking for - // the quick side effect of the return value to tell us if - // we have a _blocked_ reader. - { - auto lock = std::lock_guard{lock_}; - busy = Prune(id, 1, uid); - } - // It is still busy, blocked reader(s), lets kill them all! - // otherwise, lets be a good citizen and preserve the slow - // readers and let the clear run (below) deal with determining - // if we are still blocked and return an error code to caller. - if (busy) { - auto reader_threads_lock = std::lock_guard{reader_list_->reader_threads_lock()}; - for (const auto& reader_thread : reader_list_->reader_threads()) { - if (reader_thread->IsWatching(id)) { - LOG(WARNING) << "Kicking blocked reader, " << reader_thread->name() - << ", from LogBuffer::clear()"; - reader_thread->release_Locked(); - } - } - } - } + // Try three times to clear, then disconnect the readers and try one final time. + for (int retry = 0; retry < 3; ++retry) { { auto lock = std::lock_guard{lock_}; - busy = Prune(id, ULONG_MAX, uid); + if (Prune(id, ULONG_MAX, uid)) { + return true; + } } - - if (!busy || !--retry) { - break; + sleep(1); + } + // Check if it is still busy after the sleep, we try to prune one entry, not another clear run, + // so we are looking for the quick side effect of the return value to tell us if we have a + // _blocked_ reader. + bool busy = false; + { + auto lock = std::lock_guard{lock_}; + busy = !Prune(id, 1, uid); + } + // It is still busy, disconnect all readers. + if (busy) { + auto reader_threads_lock = std::lock_guard{reader_list_->reader_threads_lock()}; + for (const auto& reader_thread : reader_list_->reader_threads()) { + if (reader_thread->IsWatching(id)) { + LOG(WARNING) << "Kicking blocked reader, " << reader_thread->name() + << ", from LogBuffer::clear()"; + reader_thread->release_Locked(); + } } - sleep(1); // Let reader(s) catch up after notification } - return busy; + auto lock = std::lock_guard{lock_}; + return Prune(id, ULONG_MAX, uid); } // get the total space allocated to "id" @@ -313,16 +305,16 @@ bool SimpleLogBuffer::Prune(log_id_t id, unsigned long prune_rows, uid_t caller_ if (oldest && oldest->start() <= element.sequence()) { KickReader(oldest, id, prune_rows); - return true; + return false; } stats_->Subtract(element.ToLogStatisticsElement()); it = Erase(it); if (--prune_rows == 0) { - return false; + return true; } } - return false; + return true; } std::list<LogBufferElement>::iterator SimpleLogBuffer::Erase( diff --git a/shell_and_utilities/Android.bp b/shell_and_utilities/Android.bp index b5a5fb6ce..f83c43ea3 100644 --- a/shell_and_utilities/Android.bp +++ b/shell_and_utilities/Android.bp @@ -36,7 +36,7 @@ phony { "sh.recovery", "toolbox.recovery", "toybox.recovery", - "unzip.recovery", + "ziptool.recovery", ], } |