Expose runtime APIs for runtime function counters in such a way that they can be used from C

This commit is contained in:
Roman Levenstein
2017-09-18 12:50:59 -07:00
parent 8027fa2b0a
commit 460de35b82

View File

@@ -18,11 +18,23 @@
#ifndef SWIFT_STDLIB_RUNTIME_INVOCATIONS_TRACKING_H
#define SWIFT_STDLIB_RUNTIME_INVOCATIONS_TRACKING_H
#include "swift/Runtime/Config.h"
#if defined(__cplusplus)
namespace swift {
struct HeapObject;
struct RuntimeFunctionCountersState;
} // end namespace swift
using namespace swift;
#else
struct HeapObject;
struct RuntimeFunctionCountersState;
#endif
/// The name of a helper function for tracking the calls of a runtime function.
#define SWIFT_RT_TRACK_INVOCATION_NAME(RT_FUNCTION) \
swift_trackRuntimeInvocation_##RT_FUNCTION
@@ -35,9 +47,8 @@ struct RuntimeFunctionCountersState;
#define SWIFT_RT_TRACK_INVOCATION(OBJ, RT_FUNCTION) \
SWIFT_RT_TRACK_INVOCATION_NAME(RT_FUNCTION)(OBJ)
#define FUNCTION_TO_TRACK(RT_FUNCTION) \
extern void SWIFT_RT_TRACK_INVOCATION_NAME(RT_FUNCTION)(swift::HeapObject * \
OBJ);
#define FUNCTION_TO_TRACK(RT_FUNCTION) \
extern void SWIFT_RT_TRACK_INVOCATION_NAME(RT_FUNCTION)(HeapObject * OBJ);
/// Declarations of external functions for invocations tracking.
#include "RuntimeInvocationsTracking.def"
@@ -53,54 +64,54 @@ struct RuntimeFunctionCountersState;
/// function.
using RuntimeFunctionCountersUpdateHandler =
__attribute__((swiftcall))
void (*)(swift::HeapObject *object, int64_t runtimeFunctionID);
void (*)(HeapObject *object, int64_t runtimeFunctionID);
/// Public APIs
/// Get the runtime object state associated with an object and store it
/// into the result.
extern "C" void
getObjectRuntimeFunctionCounters(swift::HeapObject *object,
swift::RuntimeFunctionCountersState *result);
SWIFT_RT_ENTRY_VISIBILITY void
getObjectRuntimeFunctionCounters(HeapObject *object,
RuntimeFunctionCountersState *result);
/// Get the global runtime state containing the total numbers of invocations for
/// each runtime function of interest and store it into the result.
extern "C" void
SWIFT_RT_ENTRY_VISIBILITY void
getGlobalRuntimeFunctionCounters(swift::RuntimeFunctionCountersState *result);
/// Return the names of the runtime functions being tracked.
/// Their order is the same as the order of the counters in the
/// RuntimeObjectState structure.
extern "C" const char **getRuntimeFunctionNames();
SWIFT_RT_ENTRY_VISIBILITY const char **getRuntimeFunctionNames();
/// Return the offsets of the runtime function counters being tracked.
/// Their order is the same as the order of the counters in the
/// RuntimeFunctionCountersState structure.
extern "C" const uint16_t *getRuntimeFunctionCountersOffsets();
SWIFT_RT_ENTRY_VISIBILITY const uint16_t *getRuntimeFunctionCountersOffsets();
/// Return the number of runtime functions being tracked.
extern "C" uint64_t getNumRuntimeFunctionCounters();
SWIFT_RT_ENTRY_VISIBILITY uint64_t getNumRuntimeFunctionCounters();
/// Dump all per-object runtime function pointers.
extern "C" void dumpObjectsRuntimeFunctionPointers();
SWIFT_RT_ENTRY_VISIBILITY void dumpObjectsRuntimeFunctionPointers();
/// Set mode for global runtime function counters.
/// Return the old value of this flag.
extern "C" int setPerObjectRuntimeFunctionCountersMode(int mode);
SWIFT_RT_ENTRY_VISIBILITY int setPerObjectRuntimeFunctionCountersMode(int mode);
/// Set mode for per object runtime function counters.
/// Return the old value of this flag.
extern "C" int setGlobalRuntimeFunctionCountersMode(int mode);
SWIFT_RT_ENTRY_VISIBILITY int setGlobalRuntimeFunctionCountersMode(int mode);
/// Set the global runtime state of function pointers from a provided state.
extern "C" void
SWIFT_RT_ENTRY_VISIBILITY void
setGlobalRuntimeFunctionCounters(swift::RuntimeFunctionCountersState *state);
/// Set the runtime object state associated with an object from a provided
/// state.
extern "C" void
setObjectRuntimeFunctionCounters(swift::HeapObject *object,
swift::RuntimeFunctionCountersState *state);
SWIFT_RT_ENTRY_VISIBILITY void
setObjectRuntimeFunctionCounters(HeapObject *object,
RuntimeFunctionCountersState *state);
/// Set the global runtime function counters update handler.
extern "C" RuntimeFunctionCountersUpdateHandler