| // Copyright 2019 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "platform/impl/text_trace_logging_platform.h" |
| |
| #include <limits> |
| #include <sstream> |
| |
| #include "platform/impl/logging.h" |
| #include "util/chrono_helpers.h" |
| #include "util/osp_logging.h" |
| |
| namespace openscreen { |
| |
| using clock_operators::operator<<; |
| |
| bool TextTraceLoggingPlatform::IsTraceLoggingEnabled(TraceCategory category) { |
| return true; |
| } |
| |
| TextTraceLoggingPlatform::TextTraceLoggingPlatform() { |
| StartTracing(this); |
| } |
| |
| TextTraceLoggingPlatform::~TextTraceLoggingPlatform() { |
| StopTracing(); |
| } |
| |
| void TextTraceLoggingPlatform::LogTrace(TraceEvent event, |
| Clock::time_point end_time) { |
| const auto total_runtime = (end_time - event.start_time); |
| std::stringstream ss; |
| ss << "[TRACE" << " (" << std::dec << total_runtime << ")] " << event; |
| LogTraceMessage(ss.str()); |
| } |
| |
| void TextTraceLoggingPlatform::LogAsyncStart(TraceEvent event) { |
| std::stringstream ss; |
| ss << "[ASYNC TRACE START] " << event; |
| LogTraceMessage(ss.str()); |
| } |
| |
| void TextTraceLoggingPlatform::LogAsyncEnd(TraceEvent event) { |
| std::stringstream ss; |
| ss << "[ASYNC TRACE END] " << event; |
| LogTraceMessage(ss.str()); |
| } |
| |
| void TextTraceLoggingPlatform::LogFlow(TraceEvent event, FlowType type) { |
| std::stringstream ss; |
| ss << "[FLOW"; |
| if (!event.flow_ids.empty()) { |
| ss << " #" << std::hex << event.flow_ids[0] << std::dec; |
| } |
| |
| switch (type) { |
| case FlowType::kFlowBegin: |
| ss << " BEGIN"; |
| break; |
| case FlowType::kFlowStep: |
| ss << " STEP"; |
| break; |
| case FlowType::kFlowEnd: |
| ss << " END"; |
| break; |
| } |
| ss << "] " << event.ToString(); |
| LogTraceMessage(ss.str()); |
| } |
| |
| } // namespace openscreen |