diff options
author | mukesh agrawal <quiche@google.com> | 2016-11-15 00:18:08 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-15 00:18:08 +0000 |
commit | f4250e255d214182c61299e46e64658b6ff26707 (patch) | |
tree | c78df2031713290651e26abacb930338c25512fb | |
parent | 45bb5255af1ee54a4ce68e71a427e9b1b6c2d5f8 (diff) | |
parent | 0baa8b81806fe277967453cedd1ac552d2dd2485 (diff) | |
download | wifilogd-f4250e255d214182c61299e46e64658b6ff26707.tar.gz |
CommandProcessor: add setters for TimestampHeader am: 188f047fb8 am: 93eb4de57a am: 766aa0b7e8
am: 0baa8b8180
Change-Id: I1e37330d0f651bdfc0637822962a88575ae938cc
-rw-r--r-- | command_processor.cpp | 64 | ||||
-rw-r--r-- | command_processor.h | 11 |
2 files changed, 45 insertions, 30 deletions
diff --git a/command_processor.cpp b/command_processor.cpp index 67484de..64e1489 100644 --- a/command_processor.cpp +++ b/command_processor.cpp @@ -41,6 +41,46 @@ using local_utils::GetMaxVal; namespace { +uint32_t NsecToUsec(uint32_t nsec); + +class TimestampHeader { + public: + TimestampHeader& set_since_boot_awake_only(Os::Timestamp new_value) { + since_boot_awake_only = new_value; + return *this; + } + + TimestampHeader& set_since_boot_with_sleep(Os::Timestamp new_value) { + since_boot_with_sleep = new_value; + return *this; + } + + TimestampHeader& set_since_epoch(Os::Timestamp new_value) { + since_epoch = new_value; + return *this; + } + + // Returns a string with a formatted representation of the timestamps + // contained within this header. + std::string ToString() const { + const auto& awake_time = since_boot_awake_only; + const auto& up_time = since_boot_with_sleep; + const auto& wall_time = since_epoch; + return base::StringPrintf("%" PRIu32 ".%06" PRIu32 + " " + "%" PRIu32 ".%06" PRIu32 + " " + "%" PRIu32 ".%06" PRIu32, + awake_time.secs, NsecToUsec(awake_time.nsecs), + up_time.secs, NsecToUsec(up_time.nsecs), + wall_time.secs, NsecToUsec(wall_time.nsecs)); + } + + Os::Timestamp since_boot_awake_only; + Os::Timestamp since_boot_with_sleep; + Os::Timestamp since_epoch; // non-monotonic +}; + constexpr char kUnprintableCharReplacement = '?'; std::string MakeSanitizedString(const uint8_t* buf, size_t buf_len); @@ -121,20 +161,6 @@ bool CommandProcessor::ProcessCommand(const void* input_buffer, // Private methods below. -std::string CommandProcessor::TimestampHeader::ToString() const { - const auto& awake_time = since_boot_awake_only; - const auto& up_time = since_boot_with_sleep; - const auto& wall_time = since_epoch; - return base::StringPrintf("%" PRIu32 ".%06" PRIu32 - " " - "%" PRIu32 ".%06" PRIu32 - " " - "%" PRIu32 ".%06" PRIu32, - awake_time.secs, NsecToUsec(awake_time.nsecs), - up_time.secs, NsecToUsec(up_time.nsecs), - wall_time.secs, NsecToUsec(wall_time.nsecs)); -} - bool CommandProcessor::CopyCommandToLog(const void* command_buffer, size_t command_len_in) { const uint16_t command_len = @@ -157,11 +183,11 @@ bool CommandProcessor::CopyCommandToLog(const void* command_buffer, } CHECK(current_log_buffer_.CanFitNow(total_size)); - TimestampHeader tstamp_header; - tstamp_header.since_boot_awake_only = os_->GetTimestamp(CLOCK_MONOTONIC); - tstamp_header.since_boot_with_sleep = os_->GetTimestamp(CLOCK_BOOTTIME); - tstamp_header.since_epoch = os_->GetTimestamp(CLOCK_REALTIME); - + const auto& tstamp_header = + TimestampHeader() + .set_since_boot_awake_only(os_->GetTimestamp(CLOCK_MONOTONIC)) + .set_since_boot_with_sleep(os_->GetTimestamp(CLOCK_BOOTTIME)) + .set_since_epoch(os_->GetTimestamp(CLOCK_REALTIME)); const auto& message_buf = ByteBuffer<sizeof(TimestampHeader) + protocol::kMaxMessageSize>() .AppendOrDie(&tstamp_header, sizeof(tstamp_header)) diff --git a/command_processor.h b/command_processor.h index 24ac21f..ae9d91c 100644 --- a/command_processor.h +++ b/command_processor.h @@ -55,17 +55,6 @@ class CommandProcessor { int fd); private: - class TimestampHeader { - public: - // Returns a string with a formatted representation of the timestamps - // contained within this header. - std::string ToString() const; - - Os::Timestamp since_boot_awake_only; - Os::Timestamp since_boot_with_sleep; - Os::Timestamp since_epoch; // non-monotonic - }; - // Copies |command_buffer| into the log buffer. Returns true if the // command was copied. If |command_len| exceeds protocol::kMaxMessageSize, // copies the first protocol::kMaxMessageSize of |command_buffer|, and returns |