MLIR 22.0.0git
ActionProfiler.h
Go to the documentation of this file.
1//===- ActionProfiler.h - Profiling Actions *- C++ -*-=======================//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_TRACING_OBSERVERS_ACTIONPROFILER_H
10#define MLIR_TRACING_OBSERVERS_ACTIONPROFILER_H
11
13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/raw_ostream.h"
15
16#include <chrono>
17#include <mutex>
18
19namespace mlir {
20namespace tracing {
21
22/// This class defines an observer that profiles events before and after
23/// execution on the provided stream. The events are stored in the Chrome trace
24/// event format.
27 : os(os), startTime(std::chrono::steady_clock::now()) {
28 os << "[";
29 }
30
31 ~ActionProfiler() override { os << "]"; }
32
33 void beforeExecute(const ActionActiveStack *action, Breakpoint *breakpoint,
34 bool willExecute) override;
35 void afterExecute(const ActionActiveStack *action) override;
36
37private:
38 void print(const ActionActiveStack *action, llvm::StringRef phase);
39
40 raw_ostream &os;
41 std::chrono::time_point<std::chrono::steady_clock> startTime;
42 bool printComma = false;
43
44 /// A mutex used to guard profiling.
45 std::mutex mutex;
46};
47
48} // namespace tracing
49} // namespace mlir
50
51#endif // MLIR_TRACING_OBSERVERS_ACTIONPROFILER_H
MLIR_CRUNNERUTILS_EXPORT void printComma()
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
This abstract class represents a breakpoint.
Include the generated interface declarations.
This class is used to keep track of the active actions in the stack.
void beforeExecute(const ActionActiveStack *action, Breakpoint *breakpoint, bool willExecute) override
This method is called before the Action is executed If a breakpoint was hit, it is passed as an argum...
void afterExecute(const ActionActiveStack *action) override
This method is called after the Action is executed, if it was executed.
This abstract class defines the interface used to observe an Action execution.