Last active
January 29, 2019 18:07
-
-
Save apptects/0ff64d8324b7837ef5a71ecfb4ef1fac to your computer and use it in GitHub Desktop.
Native plugin for os_signposts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <os/signpost.h> | |
| // We need to specify a subsystem | |
| #define SUBSYSTEM "de.apptects.signposts" | |
| // Categories helps us structuring the data in Instruments | |
| #define CATEGORY_ASSETLOADING "Asset Loading" | |
| #define CATEGORY_INPUT "Input" | |
| // Interval names | |
| #define INTERVAL_LOAD_ASSET "Load Asset" | |
| // Event names | |
| #define EVENT_INPUT_TAP "Tap" | |
| // Store values for log-handles | |
| static os_log_t s_logHandleAssetLoading; | |
| static os_log_t s_logHandlePointsOfInterest; | |
| extern "C" | |
| { | |
| // Initialize log-handles at the beginning | |
| void initialize_log_handles() | |
| { | |
| s_logHandleAssetLoading = os_log_create(SUBSYSTEM, CATEGORY_ASSETLOADING); | |
| s_logHandlePointsOfInterest = os_log_create(SUBSYSTEM, OS_LOG_CATEGORY_POINTS_OF_INTEREST); | |
| } | |
| // Start load asset interval with asset path as metadata and return unique signpost-id | |
| unsigned long long start_interval_load_asset(const char* _assetPath) | |
| { | |
| unsigned long long signpostId = os_signpost_id_generate(s_logHandleAssetLoading); | |
| os_signpost_interval_begin(s_logHandleAssetLoading, signpostId, INTERVAL_LOAD_ASSET, "Asset Path: %{public}s", _assetPath); | |
| return signpostId; | |
| } | |
| // Stop load asset interval with its unique signpost-id | |
| void stop_interval_load_asset(unsigned long long _signpostId) | |
| { | |
| os_signpost_interval_end(s_logHandleAssetLoading, _signpostId, INTERVAL_LOAD_ASSET); | |
| } | |
| // Stop load asset interval with its unique signpost-id and custom metadata ("Failed") | |
| void stop_interval_load_asset_failed(unsigned long long _signpostId) | |
| { | |
| os_signpost_interval_end(s_logHandleAssetLoading, _signpostId, INTERVAL_LOAD_ASSET, "Failed"); | |
| } | |
| // Trigger signpost event for tap event, passing x/y coordinates as metadata | |
| void event_input_tap(int _x, int _y) | |
| { | |
| unsigned long long sid = os_signpost_id_generate(s_logHandlePointsOfInterest); | |
| os_signpost_event_emit(s_logHandlePointsOfInterest, sid, EVENT_INPUT_TAP, "x: %d, y: %d", _x, _y); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment