trace_event_collector.h 1.8 KB
Newer Older
L
liutiexing 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.

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. */

#pragma once

#include <list>
L
liutiexing 已提交
18 19
#include <string>
#include <unordered_map>
20
#include "paddle/fluid/platform/profiler/trace_event.h"
L
liutiexing 已提交
21 22 23 24

namespace paddle {
namespace platform {

25 26 27
class TraceEventCollector {
 public:
  void AddHostEvent(HostTraceEvent&& event) { host_events_.push_back(event); }
L
liutiexing 已提交
28

29 30 31
  void AddRuntimeEvent(RuntimeTraceEvent&& event) {
    runtime_events_.push_back(event);
  }
L
liutiexing 已提交
32

33 34 35
  void AddDeviceEvent(DeviceTraceEvent&& event) {
    device_events_.push_back(event);
  }
L
liutiexing 已提交
36

L
liutiexing 已提交
37 38 39 40
  void AddThreadName(uint64_t tid, const std::string& name) {
    thread_names_[tid] = name;
  }

41
  const std::list<HostTraceEvent>& HostEvents() const { return host_events_; }
L
liutiexing 已提交
42

43 44
  const std::list<RuntimeTraceEvent>& RuntimeEvents() const {
    return runtime_events_;
L
liutiexing 已提交
45 46
  }

47 48
  const std::list<DeviceTraceEvent>& DeviceEvents() const {
    return device_events_;
L
liutiexing 已提交
49 50
  }

L
liutiexing 已提交
51 52 53 54
  const std::unordered_map<uint64_t, std::string>& ThreadNames() const {
    return thread_names_;
  }

L
liutiexing 已提交
55
 private:
L
liutiexing 已提交
56
  std::unordered_map<uint64_t, std::string> thread_names_;
57 58 59
  std::list<HostTraceEvent> host_events_;
  std::list<RuntimeTraceEvent> runtime_events_;
  std::list<DeviceTraceEvent> device_events_;
L
liutiexing 已提交
60 61 62 63
};

}  // namespace platform
}  // namespace paddle