brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 9c0d041 Raw
77 lines · cpp
1//===- ActionLogging.cpp -  Logging 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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Debug/Observers/ActionLogging.h"10#include "mlir/Debug/BreakpointManager.h"11#include "mlir/IR/Action.h"12#include "llvm/Support/InterleavedRange.h"13#include "llvm/Support/Threading.h"14#include "llvm/Support/raw_ostream.h"15 16using namespace mlir;17using namespace mlir::tracing;18 19//===----------------------------------------------------------------------===//20// ActionLogger21//===----------------------------------------------------------------------===//22 23bool ActionLogger::shouldLog(const ActionActiveStack *action) {24  // If some condition was set, we ensured it is met before logging.25  if (breakpointManagers.empty())26    return true;27  return llvm::any_of(breakpointManagers,28                      [&](const BreakpointManager *manager) {29                        return manager->match(action->getAction());30                      });31}32 33void ActionLogger::beforeExecute(const ActionActiveStack *action,34                                 Breakpoint *breakpoint, bool willExecute) {35  if (!shouldLog(action))36    return;37  SmallVector<char> name;38  llvm::get_thread_name(name);39  if (name.empty()) {40    llvm::raw_svector_ostream os(name);41    os << llvm::get_threadid();42  }43  os << "[thread " << name << "] ";44  if (willExecute)45    os << "begins ";46  else47    os << "skipping ";48  if (printBreakpoints) {49    if (breakpoint)50      os << "(on breakpoint: " << *breakpoint << ") ";51    else52      os << "(no breakpoint) ";53  }54  os << "Action ";55  if (printActions)56    action->getAction().print(os);57  else58    os << action->getAction().getTag();59  if (printIRUnits)60    os << " (" << llvm::interleaved(action->getAction().getContextIRUnits())61       << ")";62  os << "`\n";63}64 65void ActionLogger::afterExecute(const ActionActiveStack *action) {66  if (!shouldLog(action))67    return;68  SmallVector<char> name;69  llvm::get_thread_name(name);70  if (name.empty()) {71    llvm::raw_svector_ostream os(name);72    os << llvm::get_threadid();73  }74  os << "[thread " << name << "] completed `" << action->getAction().getTag()75     << "`\n";76}77