Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Event Tracing API wrapper #1452

Merged
merged 61 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c7e4279
Start adding event tracing api wrappers
Aug 4, 2020
88fa51b
Cleanup IO code, make stream/storage handles internal
Aug 10, 2020
58a4929
Add C# API wrappers for Span, Item, EventData data operations
Aug 10, 2020
2fe2d9c
Add wrappers for Event Tracer logic
Aug 10, 2020
f2f5474
Add initial Parameter Conversions
Aug 10, 2020
1074952
Initialize internal event tracer parameter array
Aug 10, 2020
94c1113
Cleanup TraceSpan code
Aug 10, 2020
1e022e2
Fix compiler errors, memcpy SpanId to internal representation
Aug 11, 2020
b7df03d
Add static function to get null span id
Aug 11, 2020
6ab6c95
Finish up Event conversion, improve error handling
Aug 11, 2020
7b5c5e2
Merge branch 'develop' into feature/event-tracing-api-wrapper
Aug 11, 2020
0fcc258
Fix item deserialization from stream into native Item struct
Aug 11, 2020
762302a
Merge remote-tracking branch 'origin/feature/event-tracing-api-wrappe…
Aug 11, 2020
09ef2df
Remove fieldHandles property from TraceEventData
Aug 11, 2020
02f2833
Remove GCAllocs when adding data to EventData struct
Aug 11, 2020
5eca43d
Cleanup + refactor item conversion
Aug 12, 2020
41f2c11
Remove unsafe modifier from functions, cleanup code
Aug 12, 2020
9741eae
Fix compiler error when casting from UIntPtr
Aug 12, 2020
202416f
Add method to expose underlying handle for EventData
Aug 13, 2020
71e4c27
Remove unsafe modifier from EventTracer class
Aug 13, 2020
456c0cb
Add method to create a new Span in the EventTracer with a set of causes
Aug 13, 2020
4033ef4
Use closures to convert from external to internal Event
Aug 13, 2020
28936e6
Add Event Tracer parameter conversion closure
Aug 13, 2020
d7d9e66
Add method to create new span in event tracer
Aug 13, 2020
e16c1e0
Fix compiler errors related to unsafe context
Aug 13, 2020
13d4e9d
Change visibility of some methods in Item + cleanup code
Aug 14, 2020
fe44ec8
Mark SpanId with IEquatable, rename Item methods to be more concise
Aug 14, 2020
e0bdd79
Refactor Item struct methods to use thread-local item
Aug 18, 2020
fc0fdd6
Merge branch 'develop' into feature/event-tracing-api-wrapper
Aug 18, 2020
4d9ca87
Fix script compile error with SpanId
Aug 18, 2020
20d6384
Merge branch 'feature/event-tracing-api-wrapper' of github.com:spatia…
Aug 18, 2020
6cb6121
Refactor naming of EventData internal property
Aug 18, 2020
e0e862b
Refactor item conversion code into closure until it's consumed
Aug 18, 2020
6898d81
Fix whitespace lint error
Aug 18, 2020
9da2d08
Add Event Data conversion in item conversion method
Aug 19, 2020
5acbdea
Merge branch 'develop' into feature/event-tracing-api-wrapper
Aug 19, 2020
226c723
Cleanup event data conversion using TraceEventData methods
Aug 19, 2020
92a6762
Merge branch 'feature/event-tracing-api-wrapper' of github.com:spatia…
Aug 19, 2020
7781834
Update Worker SDK IO bindings to support v14.8.0
Aug 19, 2020
50f70be
Refactor EventData API to match native Dictionary more closely
Aug 19, 2020
ec72006
Fix DLL entry point for Create/Destroy EventTracer
Aug 19, 2020
4914aab
Switch to using OpenMode Enum over Uint
Aug 20, 2020
c38485e
Remove intermediate cast for OpenMode Enum
Aug 20, 2020
8c3c6ab
Clean up EventData conversion
Aug 20, 2020
d20bbd2
Fix EventTracerParameter TraceCallback
Aug 20, 2020
fa045d5
Allocate memory to internal causes array
Aug 24, 2020
bee5a62
Replace List with array for WrappedGcHandle usages
Aug 24, 2020
c319eac
Merge branch 'develop' into feature/event-tracing-api-wrapper
Aug 24, 2020
8a3be52
Cleanup conversion of event tracer parameters
Aug 24, 2020
f1013fa
Merge branch 'feature/event-tracing-api-wrapper' of github.com:spatia…
Aug 24, 2020
b89e680
Cleanup EventTracerParameter conversion using stackalloc
Aug 26, 2020
a6e3fb2
Merge remote-tracking branch 'origin/develop' into feature/event-trac…
Aug 26, 2020
635b5ec
Make requested changes for IO, EventTracing APIs
Aug 26, 2020
a794770
Add changelog entry
Aug 26, 2020
26b0cd1
Add TraceEventData constructor for adding metadata on creation
Aug 27, 2020
a8a956a
Merge remote-tracking branch 'origin/develop' into feature/event-trac…
Aug 27, 2020
1bbd023
Merge branch 'develop' into feature/event-tracing-api-wrapper
Aug 27, 2020
f3e8ece
Fix code smell for OpenMode Enum naming
Aug 28, 2020
d752913
Fix code smells
Aug 28, 2020
2300066
Merge branch 'feature/event-tracing-api-wrapper' of github.com:spatia…
Aug 28, 2020
ffc1cb3
Merge branch 'develop' into feature/event-tracing-api-wrapper
Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Added

- Added `MeansImplicitUse` attribute to `RequireAttribute` to reduce warnings in Rider IDE. [#1462](https://github.com/spatialos/gdk-for-unity/pull/1462)
- Added Event Tracing API. [#1452](https://github.com/spatialos/gdk-for-unity/pull/1452)

### Changed

Expand Down
38 changes: 26 additions & 12 deletions workers/unity/Packages/io.improbable.worker.sdk/CEventTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ internal unsafe class CEventTrace
* Data for an event. This is a collection of key-value pairs (fields). Use EventData* functions to
* read or write fields.
*/
public class EventData : CptrHandle
public class EventDataHandle : CptrHandle
{
public EventDataHandle()
{
}

internal EventDataHandle(IntPtr handle)
{
SetHandle(handle);
}

protected override bool ReleaseHandle()
{
EventDataDestroy(handle);
return true;
}

internal IntPtr GetUnderlying()
{
return handle;
}
}

public class EventTracer : CptrHandle
Expand Down Expand Up @@ -100,7 +114,7 @@ public struct Span
*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Trace_EventData_Create")]
public static extern EventData EventDataCreate();
public static extern EventDataHandle EventDataCreate();

/** Frees resources for the event data object.*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
Expand All @@ -113,12 +127,12 @@ public struct Span
*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Trace_EventData_AddStringFields")]
public static extern void EventDataAddStringFields(EventData data, Uint32 count, Char** keys, Char** values);
public static extern void EventDataAddStringFields(EventDataHandle data, Uint32 count, Char** keys, Char** values);

/** Returns the number of fields on the given event data object. */
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Trace_EventData_GetFieldCount")]
public static extern Uint32 EventDataGetFieldCount(EventData data);
public static extern Uint32 EventDataGetFieldCount(EventDataHandle data);

/**
* Returns all the key value pairs in the event data object. keys and values must have capacity for
Expand All @@ -128,12 +142,12 @@ public struct Span
*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Trace_EventData_GetStringFields")]
public static extern void EventDataGetStringFields(EventData data, Char** keys, Char** values);
public static extern void EventDataGetStringFields(EventDataHandle data, Char** keys, Char** values);

/** Returns the value for the given key. */
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Trace_EventData_GetFieldValue")]
public static extern Char* EventDataGetFieldValue(EventData data, Char* key);
public static extern Char* EventDataGetFieldValue(EventDataHandle data, Char* key);

/** Data for an event added to the event-tracer. */
[StructLayout(LayoutKind.Sequential)]
Expand All @@ -153,7 +167,7 @@ public struct Event
public struct Item
{
/** The type of the item, defined using ItemType. */
public Uint8 ItemType;
public ItemType ItemType;

/** An item can either be a Span or an Event. */
public Union ItemUnion;
Expand Down Expand Up @@ -187,12 +201,12 @@ public struct EventTracerParameters

/** Creates an event-tracer. */
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "EventTracerCreate")]
EntryPoint = "Trace_EventTracer_Create")]
public static extern EventTracer EventTracerCreate(EventTracerParameters* parameters);

/** Frees resources for an event-tracer. */
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "EventTracerDestroy")]
EntryPoint = "Trace_EventTracer_Destroy")]
public static extern void EventTracerDestroy(IntPtr eventTracer);

/**
Expand Down Expand Up @@ -234,8 +248,8 @@ public struct EventTracerParameters
* EventTracerGetActiveSpanId will return a null span ID.
*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Trace_EventTracer_UnsetActiveSpanId")]
public static extern void EventTracerUnsetActiveSpanId(EventTracer eventTracer);
EntryPoint = "Trace_EventTracer_ClearActiveSpanId")]
public static extern void EventTracerClearActiveSpanId(EventTracer eventTracer);

/** Gets the active span ID on the event-tracer. */
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
Expand Down Expand Up @@ -272,7 +286,7 @@ public struct EventTracerParameters
* The item is initialized by copying the provided item; pass a NULL item argument to create an
* item in an uninitialized state.
*
* Directly creating a TraceItem object (on the stack or the heap) by other means than calling this
* Directly creating a Item object (on the stack or the heap) by other means than calling this
* method is discouraged as it will lead to undefined behaviour when passing that item to certain
* trace API methods (e.g. SerializeItemToStream).
*/
Expand Down
46 changes: 37 additions & 9 deletions workers/unity/Packages/io.improbable.worker.sdk/CIO.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Runtime.InteropServices;
using Int64 = System.Int64;
using Uint64 = System.UInt64;
Expand Down Expand Up @@ -28,10 +29,31 @@ protected override bool ReleaseHandle()
}
}

public enum OpenMode
[Flags]
public enum OpenModes : Uint32
{
/* Opens the stream in the default mode. */
OpenModeDefault = 0x00,
/**
* Allow input operations on the stream. Input operations always occur at the read position, which
* is initialized to the beginning of the stream.
*/
OpenModeRead = 0x01,

/**
* Allow output operations on the stream. Output operations always occur at the write position,
* which is initialized to the end of the stream.
*/
OpenModeWrite = 0x02,

/**
* Truncates any existing content upon opening. If not set, writes are appended to the end of the
* stream's existing content.
*/
OpenModeTruncate = 0x04,

/**
* Specify that writes should be appended to the stream's existing content, if any exists.
*/
OpenModeAppend = 0x08,
}

/**
Expand Down Expand Up @@ -85,16 +107,14 @@ public enum OpenMode
* The file stream has a conceptually infinite capacity; its true capacity depends on the
* underlying filesystem.
*
* Upon creation of the file stream, the file is created if it does not exist. The file stream is
* initialized to read from the beginning of the file and append to the end, regardless of whether
* it previously existed or not.
* The open_mode argument should be passed as a combination of OpenMode values.
*
* Returns a pointer to a file stream. Never returns NULL. Call StreamGetLastError to check
* if an error occurred during file stream creation.
* Returns a pointer to a file stream. Never returns NULL. You *must* call Io_Stream_GetLastError to
* check if an error occurred during file stream creation.
*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Io_CreateFileStream")]
public static extern StreamHandle CreateFileStream(Char* filename, OpenMode openMode);
public static extern StreamHandle CreateFileStream(Char* filename, OpenModes openModes);

/* Destroys the I/O stream. */
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
Expand Down Expand Up @@ -168,5 +188,13 @@ public enum OpenMode
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Io_Stream_GetLastError")]
public static extern Char* StreamGetLastError(StreamHandle stream);

/**
* Clears the stream's current error such that the next call to Io_Stream_GetLastError returns
* nullptr.
*/
[DllImport(Constants.WorkerLibrary, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "Io_Stream_ClearError")]
public static extern void StreamClearError(StreamHandle stream);
}
}
Loading