diff --git a/bootstat/Android.bp b/bootstat/Android.bp index 89b459865..d98a9d7dd 100644 --- a/bootstat/Android.bp +++ b/bootstat/Android.bp @@ -16,7 +16,6 @@ bootstat_lib_src_files = [ "boot_event_record_store.cpp", - "event_log_list_builder.cpp", "histogram_logger.cpp", "uptime_parser.cpp", ] @@ -88,7 +87,6 @@ cc_test { ], srcs: [ "boot_event_record_store_test.cpp", - "event_log_list_builder_test.cpp", "testrunner.cpp", ], } diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index e5ddab3d0..7c0e85dc2 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -35,7 +35,6 @@ #include #include "boot_event_record_store.h" -#include "event_log_list_builder.h" /* ToDo: switch to liblog implementation */ #include "histogram_logger.h" #include "uptime_parser.h" diff --git a/bootstat/event_log_list_builder.cpp b/bootstat/event_log_list_builder.cpp deleted file mode 100644 index ce540a03b..000000000 --- a/bootstat/event_log_list_builder.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2016 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 "event_log_list_builder.h" - -#include -#include -#include - -#include -#include - -namespace { - -const size_t MAX_EVENT_PAYLOAD_SIZE = 512 - 1; // Leave room for final '\n'. -const size_t EVENT_TYPE_SIZE = 1; // Size in bytes of the event type marker. - -} // namespace - -EventLogListBuilder::EventLogListBuilder() - : payload_count_(0), - payload_size_(0), - payload_(std::make_unique(MAX_EVENT_PAYLOAD_SIZE)) { - memset(payload_.get(), 0, MAX_EVENT_PAYLOAD_SIZE); - - // Set up the top-level EventLog data type. - AppendByte(EVENT_TYPE_LIST); - - // Skip over the byte prepresenting the number of items in the list. This - // value is set in Release(). - payload_size_++; -} - -bool EventLogListBuilder::Append(int value) { - DCHECK_NE(static_cast(nullptr), payload_.get()); - - if (!IsSpaceAvailable(sizeof(value) + EVENT_TYPE_SIZE)) { - return false; - } - - AppendByte(EVENT_TYPE_INT); - AppendData(&value, sizeof(value)); - - payload_count_++; - return true; -} - -bool EventLogListBuilder::Append(const std::string& value) { - DCHECK_NE(static_cast(nullptr), payload_.get()); - - int len = value.length(); - if (!IsSpaceAvailable(sizeof(len) + len)) { - return false; - } - - AppendByte(EVENT_TYPE_STRING); - AppendData(&len, sizeof(len)); - AppendData(value.c_str(), len); - - payload_count_++; - return true; -} - -void EventLogListBuilder::Release(std::unique_ptr* log, - size_t* size) { - // Finalize the log payload. - payload_[1] = payload_count_; - - // Return the log payload. - *size = payload_size_; - *log = std::move(payload_); -} - -void EventLogListBuilder::AppendData(const void* data, size_t size) { - DCHECK_LT(payload_size_ + size, MAX_EVENT_PAYLOAD_SIZE); - memcpy(&payload_[payload_size_], data, size); - payload_size_ += size; -} - -void EventLogListBuilder::AppendByte(uint8_t byte) { - DCHECK_LT(payload_size_ + sizeof(byte), MAX_EVENT_PAYLOAD_SIZE); - payload_[payload_size_++] = byte; -} - -bool EventLogListBuilder::IsSpaceAvailable(size_t value_size) { - size_t space_needed = value_size + EVENT_TYPE_SIZE; - if (payload_size_ + space_needed > MAX_EVENT_PAYLOAD_SIZE) { - size_t remaining = MAX_EVENT_PAYLOAD_SIZE - payload_size_; - LOG(WARNING) << "Not enough space for value. remain=" << - remaining << "; needed=" << space_needed; - return false; - } - - return true; -} diff --git a/bootstat/event_log_list_builder.h b/bootstat/event_log_list_builder.h deleted file mode 100644 index 4e29b01ec..000000000 --- a/bootstat/event_log_list_builder.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#ifndef EVENT_LOG_LIST_BUILDER_H_ -#define EVENT_LOG_LIST_BUILDER_H_ - -#include -#include - -#include - -// EventLogListBuilder provides a mechanism to build an EventLog list -// consisting of int and string EventLog values. -// -// NOTE: This class does not provide the ability to append an embedded list, -// i.e., a list containing a list. -class EventLogListBuilder { - public: - EventLogListBuilder(); - - // Append a single value of a specified type. - bool Append(int value); - bool Append(const std::string& value); - - // Finalizes construction of the EventLog list and releases the data - // to the caller. Caller takes ownership of the payload. No further calls - // to append* may be made once the payload is acquired by the caller. - void Release(std::unique_ptr* log, size_t* size); - - private: - // Appends |data| of the given |size| to the payload. - void AppendData(const void* data, size_t size); - - // Appends a single byte to the payload. - void AppendByte(uint8_t byte); - - // Returns true iff the remaining capacity in |payload_| is large enough to - // accommodate |value_size| bytes. The space required to log the event type - // is included in the internal calculation so must not be passed in to - // |value_size|. - bool IsSpaceAvailable(size_t value_size); - - // The number of items in the EventLog list. - size_t payload_count_; - - // The size of the data stored in |payload_|. Used to track where to insert - // new data. - size_t payload_size_; - - // The payload constructed by calls to log*. The payload may only contain - // MAX_EVENT_PAYLOAD (512) bytes. - std::unique_ptr payload_; - - DISALLOW_COPY_AND_ASSIGN(EventLogListBuilder); -}; - - #endif // EVENT_LOG_LIST_BUILDER_H_ diff --git a/bootstat/event_log_list_builder_test.cpp b/bootstat/event_log_list_builder_test.cpp deleted file mode 100644 index 25909b08f..000000000 --- a/bootstat/event_log_list_builder_test.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2016 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 "event_log_list_builder.h" - -#include - -#include -#include -#include - -using testing::ElementsAreArray; - -TEST(EventLogListBuilder, Empty) { - EventLogListBuilder builder; - - const uint8_t EXPECTED_LOG[] = { - EVENT_TYPE_LIST, - 0, // Number of items in the list. - }; - - std::unique_ptr log; - size_t size; - builder.Release(&log, &size); - EXPECT_EQ(2U, size); - - uint8_t* log_data = log.get(); - EXPECT_THAT(std::vector(log_data, log_data + size), - ElementsAreArray(EXPECTED_LOG)); -} - -TEST(EventLogListBuilder, SingleInt) { - EventLogListBuilder builder; - - const uint8_t EXPECTED_LOG[] = { - EVENT_TYPE_LIST, - 1, // Number of items in the list. - EVENT_TYPE_INT, - 42, 0, 0, 0, // 4 byte integer value. - }; - - builder.Append(42); - - std::unique_ptr log; - size_t size; - builder.Release(&log, &size); - EXPECT_EQ(7U, size); - - uint8_t* log_data = log.get(); - EXPECT_THAT(std::vector(log_data, log_data + size), - ElementsAreArray(EXPECTED_LOG)); -} - -TEST(EventLogListBuilder, SingleString) { - EventLogListBuilder builder; - - const uint8_t EXPECTED_LOG[] = { - EVENT_TYPE_LIST, - 1, // Number of items in the list. - EVENT_TYPE_STRING, - 5, 0, 0, 0, // 4 byte length of the string. - 'D', 'r', 'o', 'i', 'd', - }; - - builder.Append("Droid"); - - std::unique_ptr log; - size_t size; - builder.Release(&log, &size); - EXPECT_EQ(12U, size); - - uint8_t* log_data = log.get(); - EXPECT_THAT(std::vector(log_data, log_data + size), - ElementsAreArray(EXPECTED_LOG)); -} - -TEST(EventLogListBuilder, IntThenString) { - EventLogListBuilder builder; - - const uint8_t EXPECTED_LOG[] = { - EVENT_TYPE_LIST, - 2, // Number of items in the list. - EVENT_TYPE_INT, - 42, 0, 0, 0, // 4 byte integer value. - EVENT_TYPE_STRING, - 5, 0, 0, 0, // 4 byte length of the string. - 'D', 'r', 'o', 'i', 'd', - }; - - builder.Append(42); - builder.Append("Droid"); - - std::unique_ptr log; - size_t size; - builder.Release(&log, &size); - EXPECT_EQ(17U, size); - - uint8_t* log_data = log.get(); - EXPECT_THAT(std::vector(log_data, log_data + size), - ElementsAreArray(EXPECTED_LOG)); -} diff --git a/bootstat/histogram_logger.cpp b/bootstat/histogram_logger.cpp index 4f2386c05..6a9ef2bda 100644 --- a/bootstat/histogram_logger.cpp +++ b/bootstat/histogram_logger.cpp @@ -17,27 +17,16 @@ #include "histogram_logger.h" #include -#include #include #include -#include "event_log_list_builder.h" - namespace bootstat { void LogHistogram(const std::string& event, int32_t data) { LOG(INFO) << "Logging histogram: " << event << " " << data; - - EventLogListBuilder log_builder; - log_builder.Append(event); - log_builder.Append(data); - - std::unique_ptr log; - size_t size; - log_builder.Release(&log, &size); - - android_bWriteLog(HISTOGRAM_LOG_TAG, log.get(), size); + android_log_event_context log(HISTOGRAM_LOG_TAG); + log << event << data << LOG_ID_EVENTS; } } // namespace bootstat