blob: 38e8d820509e0aed013e62c92d5ac4eefaa79c19 [file] [log] [blame]
// Copyright 2021 The Pigweed Authors
// 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
// 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 "pw_trace_tokenized/trace_rpc_service_nanopb.h"
#include "pw_log/log.h"
#include "pw_preprocessor/util.h"
#include "pw_trace_tokenized/trace_buffer.h"
#include "pw_trace_tokenized/trace_tokenized.h"
namespace pw::trace {
pw::Status TraceService::Enable(const pw_trace_TraceEnableMessage& request,
pw_trace_TraceEnableMessage& response) {
response.enable = TokenizedTrace::Instance().IsEnabled();
return PW_STATUS_OK;
pw::Status TraceService::IsEnabled(const pw_trace_Empty&,
pw_trace_TraceEnableMessage& response) {
response.enable = TokenizedTrace::Instance().IsEnabled();
return PW_STATUS_OK;
void TraceService::GetTraceData(
const pw_trace_Empty&, ServerWriter<pw_trace_TraceDataMessage>& writer) {
pw_trace_TraceDataMessage buffer = pw_trace_TraceDataMessage_init_default;
size_t size = 0;
pw::ring_buffer::PrefixedEntryRingBuffer* trace_buffer =
while (trace_buffer->PeekFront(as_writable_bytes(span(,
&size) != pw::Status::OutOfRange()) {
.IgnoreError(); // TODO(b/242598609): Handle Status properly = size;
pw::Status status = writer.Write(buffer);
if (!status.ok()) {
PW_LOG_ERROR("Error sending trace; abandoning trace dump. Error: %s",
writer.Finish().IgnoreError(); // TODO(b/242598609): Handle Status properly
} // namespace pw::trace