Project import generated by Copybara.
PiperOrigin-RevId: 253489161
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
// Copyright 2019 The MediaPipe 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
|
||||
//
|
||||
// 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 MEDIAPIPE_FRAMEWORK_PROFILER_TRACE_BUFFER_H_
|
||||
#define MEDIAPIPE_FRAMEWORK_PROFILER_TRACE_BUFFER_H_
|
||||
|
||||
#include "absl/time/time.h"
|
||||
#include "mediapipe/framework/calculator_profile.pb.h"
|
||||
#include "mediapipe/framework/packet.h"
|
||||
#include "mediapipe/framework/profiler/circular_buffer.h"
|
||||
#include "mediapipe/framework/timestamp.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
// Packet content identifier.
|
||||
using PacketDataId = const void*;
|
||||
|
||||
namespace packet_internal {
|
||||
// Returns the packet data address for a packet data holder.
|
||||
inline const void* GetPacketDataId(const HolderBase* holder) {
|
||||
return (holder == nullptr)
|
||||
? nullptr
|
||||
: &(static_cast<const Holder<int>*>(holder)->data());
|
||||
}
|
||||
} // namespace packet_internal
|
||||
|
||||
// Packet trace log event.
|
||||
struct TraceEvent {
|
||||
using EventType = GraphTrace::EventType;
|
||||
// GraphTrace::EventType constants, repeated here to match GraphProfilerStub.
|
||||
static const EventType UNKNOWN, OPEN, PROCESS, CLOSE, NOT_READY,
|
||||
READY_FOR_PROCESS, READY_FOR_CLOSE, THROTTLED, UNTHROTTLED, CPU_TASK_USER,
|
||||
CPU_TASK_SYSTEM, GPU_TASK, DSP_TASK, TPU_TASK;
|
||||
absl::Time event_time;
|
||||
EventType event_type = UNKNOWN;
|
||||
bool is_finish = false;
|
||||
Timestamp input_ts = Timestamp::Unset();
|
||||
Timestamp packet_ts = Timestamp::Unset();
|
||||
int node_id = -1;
|
||||
const std::string* stream_id = nullptr;
|
||||
PacketDataId packet_data_id = 0;
|
||||
int thread_id = 0;
|
||||
|
||||
TraceEvent(const EventType& event_type) : event_type(event_type) {}
|
||||
TraceEvent() {}
|
||||
|
||||
inline TraceEvent& set_event_time(absl::Time event_time) {
|
||||
this->event_time = event_time;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_event_type(const EventType& event_type) {
|
||||
this->event_type = event_type;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_node_id(int node_id) {
|
||||
this->node_id = node_id;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_stream_id(const std::string* stream_id) {
|
||||
this->stream_id = stream_id;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_input_ts(Timestamp input_ts) {
|
||||
this->input_ts = input_ts;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_packet_ts(Timestamp packet_ts) {
|
||||
this->packet_ts = packet_ts;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_packet_data_id(const Packet* packet) {
|
||||
this->packet_data_id =
|
||||
packet_internal::GetPacketDataId(packet_internal::GetHolder(*packet));
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_thread_id(int thread_id) {
|
||||
this->thread_id = thread_id;
|
||||
return *this;
|
||||
}
|
||||
inline TraceEvent& set_is_finish(bool is_finish) {
|
||||
this->is_finish = is_finish;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// Packet trace log buffer.
|
||||
using TraceBuffer = CircularBuffer<TraceEvent>;
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
#endif // MEDIAPIPE_FRAMEWORK_PROFILER_TRACE_BUFFER_H_
|
||||
Reference in New Issue
Block a user