mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The code goes into its own sub-tree under 'tools' but tests go under 'test', so that running 'check-swift' will also run all the SourceKit tests. SourceKit is disabled on non-darwin platforms.
82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
#include "SourceKit/Support/Tracing.h"
|
|
|
|
#include "swift/Frontend/Frontend.h"
|
|
|
|
#include "llvm/Support/TimeValue.h"
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
using namespace SourceKit;
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
// General
|
|
//----------------------------------------------------------------------------//
|
|
|
|
static std::atomic<bool> tracing_enabled(false);
|
|
static std::atomic<uint64_t> operation_id(0);
|
|
|
|
//----------------------------------------------------------------------------//
|
|
// Copnsumers
|
|
//----------------------------------------------------------------------------//
|
|
struct TraceConsumerListNode {
|
|
trace::TraceConsumer *const Consumer;
|
|
TraceConsumerListNode *Next;
|
|
};
|
|
static std::atomic<TraceConsumerListNode *> consumers(nullptr);
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
// Trace commands
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// Is tracing enabled
|
|
bool trace::enabled() {
|
|
return tracing_enabled;
|
|
}
|
|
|
|
void trace::enable() {
|
|
tracing_enabled = true;
|
|
}
|
|
|
|
void trace::disable() {
|
|
tracing_enabled = false;
|
|
}
|
|
|
|
// Trace start of perform sema call, returns OpId
|
|
uint64_t trace::startOpertation(trace::OperationKind OpKind,
|
|
const trace::SwiftInvocation &Inv,
|
|
const trace::StringPairs &OpArgs) {
|
|
auto OpId = ++operation_id;
|
|
if (trace::enabled()) {
|
|
auto Node = consumers.load(std::memory_order_acquire);
|
|
while (Node) {
|
|
Node->Consumer->opertationStarted(OpId, OpKind, Inv, OpArgs);
|
|
Node = Node->Next;
|
|
}
|
|
}
|
|
return OpId;
|
|
}
|
|
|
|
// Operation previously started with startXXX has finished
|
|
void trace::operationFinished(uint64_t OpId) {
|
|
if (trace::enabled()) {
|
|
auto Node = consumers.load(std::memory_order_acquire);
|
|
while (Node) {
|
|
Node->Consumer->operationFinished(OpId);
|
|
Node = Node->Next;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Register trace consumer
|
|
void trace::registerConsumer(trace::TraceConsumer *Consumer) {
|
|
TraceConsumerListNode *Node = new TraceConsumerListNode {Consumer, nullptr};
|
|
do {
|
|
Node->Next = consumers.load(std::memory_order_relaxed);
|
|
} while(!consumers.compare_exchange_weak(Node->Next, Node,
|
|
std::memory_order_release,
|
|
std::memory_order_relaxed));
|
|
}
|