2 * Copyright (c) 2019 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef OctagonSignPosts_h
25 #define OctagonSignPosts_h
27 #import <Foundation/Foundation.h>
28 #import <os/activity.h>
30 #import <os/signpost.h>
31 #import <os/signpost_private.h>
33 NS_ASSUME_NONNULL_BEGIN
35 typedef struct octagon_signpost_s
{
36 const os_signpost_id_t identifier
;
37 const uint64_t timestamp
;
40 #define OctagonSignpostNamePerformEscrowRecovery "OctagonSignpostNamePerformEscrowRecovery"
41 #define OctagonSignpostNamePerformRecoveryFromSBD "OctagonSignpostNamePerformRecoveryFromSBD"
42 #define OctagonSignpostNamePerformBottleRecovery "OctagonSignpostNamePerformBottleRecovery"
43 #define OctagonSignpostNamePerformResetAndEstablishAfterFailedBottle "OctagonSignpostNamePerformResetAndEstablishAfterFailedBottle"
44 #define OctagonSignpostNameFetchEgoPeer "OctagonSignpostNameFetchEgoPeer"
45 #define OctagonSignpostNameEstablish "OctagonSignpostNameEstablish"
46 #define OctagonSignpostNameResetAndEstablish "OctagonSignpostNameResetAndEstablish"
47 #define OctagonSignpostNameMakeNewFriends "OctagonSignpostNameMakeNewFriends"
48 #define OctagonSignpostNameFetchCliqueStatus "OctagonSignpostNameFetchCliqueStatus"
49 #define OctagonSignpostNameRemoveFriendsInClique "OctagonSignpostNameRemoveFriendsInClique"
50 #define OctagonSignpostNameLeaveClique "OctagonSignpostNameLeaveClique"
51 #define OctagonSignpostNamePeerDeviceNamesByPeerID "OctagonSignpostNamePeerDeviceNamesByPeerID"
52 #define OctagonSignpostNameJoinAfterRestore "OctagonSignpostNameJoinAfterRestore"
53 #define OctagonSignpostNameSafariPasswordSyncingEnabled "OctagonSignpostNameSafariPasswordSyncingEnabled"
54 #define OctagonSignpostNameWaitForInitialSync "OctagonSignpostNameWaitForInitialSync"
55 #define OctagonSignpostNameCopyViewUnawarePeerInfo "OctagonSignpostNameCopyViewUnawarePeerInfo"
56 #define OctagonSignpostNameViewSet "OctagonSignpostNameViewSet"
57 #define OctagonSignpostNameSetUserCredentialsAndDSID "OctagonSignpostNameSetUserCredentialsAndDSID"
58 #define OctagonSignpostNameTryUserCredentialsAndDSID "OctagonSignpostNameTryUserCredentialsAndDSID"
59 #define OctagonSignpostNameCopyPeerPeerInfo "OctagonSignpostNameCopyPeerPeerInfo"
60 #define OctagonSignpostNamePeersHaveViewsEnabled "OctagonSignpostNamePeersHaveViewsEnabled"
61 #define OctagonSignpostNameRequestToJoinCircle "OctagonSignpostNameRequestToJoinCircle"
62 #define OctagonSignpostNameAccountUserKeyAvailable "OctagonSignpostNameAccountUserKeyAvailable"
63 #define OctagonSignpostNameFindOptimalBottleIDsWithContextData "OctagonSignpostNameFindOptimalBottleIDsWithContextData"
64 #define OctagonSignpostNameFetchEscrowContents "OctagonSignpostNameFetchEscrowContents"
65 #define OctagonSignpostNameSetNewRecoveryKeyWithData "OctagonSignpostNameSetNewRecoveryKeyWithData"
66 #define OctagonSignpostNameRecoverOctagonUsingData "OctagonSignpostNameRecoverOctagonUsingData"
67 #define OctagonSignpostNamePerformedCDPStateMachineRun "OctagonSignpostNamePerformedCDPStateMachineRun"
68 #define OctagonSignpostNameWaitForOctagonUpgrade "OctagonSignpostNameWaitForOctagonUpgrade"
70 #define SOSSignpostNameAssertUserCredentialsAndOptionalDSID "SOSSignpostNameAssertUserCredentialsAndOptionalDSID"
71 #define SOSSignpostNameSOSCCTryUserCredentials "SOSSignpostNameSOSCCTryUserCredentials"
72 #define SOSSignpostNameSOSCCCanAuthenticate "SOSSignpostNameSOSCCCanAuthenticate"
73 #define SOSSignpostNameSOSCCRequestToJoinCircle "SOSSignpostNameSOSCCRequestToJoinCircle"
74 #define SOSSignpostNameSOSCCRequestToJoinCircleAfterRestore "SOSSignpostNameSOSCCRequestToJoinCircleAfterRestore"
75 #define SOSSignpostNameSOSCCResetToOffering "SOSSignpostNameSOSCCResetToOffering"
76 #define SOSSignpostNameSOSCCResetToEmpty "SOSSignpostNameSOSCCResetToEmpty"
77 #define SOSSignpostNameSOSCCRemoveThisDeviceFromCircle "SOSSignpostNameSOSCCRemoveThisDeviceFromCircle"
78 #define SOSSignpostNameSOSCCRemovePeersFromCircle "SOSSignpostNameSOSCCRemovePeersFromCircle"
79 #define SOSSignpostNameSOSCCLoggedOutOfAccount "SOSSignpostNameSOSCCLoggedOutOfAccount"
80 #define SOSSignpostNameSOSCCCopyApplicantPeerInfo "SOSSignpostNameSOSCCCopyApplicantPeerInfo"
81 #define SOSSignpostNameFlush "SOSSignpostNameFlush"
82 #define SOSSignpostNameSyncKVSAndWait "SOSSignpostNameSyncKVSAndWait"
83 #define SOSSignpostNameSyncTheLastDataToKVS "SOSSignpostNameSyncTheLastDataToKVS"
84 #define SOSSignpostNameSOSCCViewSet "SOSSignpostNameSOSCCViewSet"
85 #define SOSSignpostNameSOSCCCopyValidPeerPeerInfo "SOSSignpostNameSOSCCCopyValidPeerPeerInfo"
86 #define SOSSignpostNameSOSCCValidateUserPublic "SOSSignpostNameSOSCCValidateUserPublic"
87 #define SOSSignpostNameSOSCCCopyViewUnawarePeerInfo "SOSSignpostNameSOSCCCopyViewUnawarePeerInfo"
88 #define SOSSignpostNameSOSCCWaitForInitialSync "SOSSignpostNameSOSCCWaitForInitialSync"
89 #define SOSSignpostNameSOSCCAcceptApplicants "SOSSignpostNameSOSCCAcceptApplicants"
90 #define SOSSignpostNameSOSCCRejectApplicants "SOSSignpostNameSOSCCRejectApplicants"
91 #define SOSSignpostNameSOSCCCopyConcurringPeerPeerInfo "SOSSignpostNameSOSCCCopyConcurringPeerPeerInfo"
92 #define SOSSignpostNameSOSCCCopyMyPeerInfo "SOSSignpostNameSOSCCCopyMyPeerInfo"
93 #define SOSSignpostNameSOSCCSetNewPublicBackupKey "SOSSignpostNameSOSCCSetNewPublicBackupKey"
94 #define SOSSignpostNameSOSCCRegisterSingleRecoverySecret "SOSSignpostNameSOSCCRegisterSingleRecoverySecret"
95 #define SOSSignpostNameSOSCCProcessEnsurePeerRegistration "SOSSignpostNameSOSCCProcessEnsurePeerRegistration"
96 #define SOSSignpostNameSOSCCProcessSyncWithPeers "SOSSignpostNameSOSCCProcessSyncWithPeers"
97 #define SOSSignpostNameSOSCCProcessSyncWithAllPeers "SOSSignpostNameSOSCCProcessSyncWithAllPeers"
98 #define SOSSignpostNameSOSCCRequestSyncWithPeersList "SOSSignpostNameSOSCCRequestSyncWithPeersList"
99 #define SOSSignpostNameSOSCCRequestSyncWithBackupPeerList "SOSSignpostNameSOSCCRequestSyncWithBackupPeerList"
100 #define SOSSignpostNameSOSCCEnsurePeerRegistration "SOSSignpostNameSOSCCEnsurePeerRegistration"
101 #define SOSSignpostNameSOSCCHandleUpdateMessage "SOSSignpostNameSOSCCHandleUpdateMessage"
102 #define SOSSignpostNameSOSCCCopyApplication "SOSSignpostNameSOSCCCopyApplication"
103 #define SOSSignpostNameSOSCCCopyCircleJoiningBlob "SOSSignpostNameSOSCCCopyCircleJoiningBlob"
104 #define SOSSignpostNameSOSCCCopyInitialSyncData "SOSSignpostNameSOSCCCopyInitialSyncData"
105 #define SOSSignpostNameSOSCCJoinWithCircleJoiningBlob "SOSSignpostNameSOSCCJoinWithCircleJoiningBlob"
106 #define SOSSignpostNameSOSCCPeersHaveViewsEnabled "SOSSignpostNameSOSCCPeersHaveViewsEnabled"
107 #define SOSSignpostNameSOSCCRegisterRecoveryPublicKey "SOSSignpostNameSOSCCRegisterRecoveryPublicKey"
108 #define SOSSignpostNameSOSCCCopyRecoveryPublicKey "SOSSignpostNameSOSCCCopyRecoveryPublicKey"
109 #define SOSSignpostNameSOSCCMessageFromPeerIsPending "SOSSignpostNameSOSCCMessageFromPeerIsPending"
110 #define SOSSignpostNameSOSCCSendToPeerIsPending "SOSSignpostNameSOSCCSendToPeerIsPending"
112 #define OctagonSignpostString1(label) " "#label"=%{public,signpost.telemetry:string1,name="#label"}@ "
113 #define OctagonSignpostString2(label) " "#label"=%{public,signpost.telemetry:string2,name="#label"}@ "
114 #define OctagonSignpostNumber1(label) " "#label"=%{public,signpost.telemetry:number1,name="#label"}d "
115 #define OctagonSignpostNumber2(label) " "#label"=%{public,signpost.telemetry:number2,name="#label"}d "
117 // Used to begin tracking a timed event.
118 #define OctagonSignpostBegin(name) _OctagonSignpostBegin(_OctagonSignpostLogSystem(), name, OS_SIGNPOST_ENABLE_TELEMETRY)
120 // For marking a significant event.
121 #define OctagonSignpostEvent(signpost, name, ...) _OctagonSignpostEvent(_OctagonSignpostLogSystem(), signpost, name, __VA_ARGS__)
123 // For completing a timed event associated with the given signpost.
124 #define OctagonSignpostEnd(signpost, name, ...) _OctagonSignpostEnd(_OctagonSignpostLogSystem(), signpost, name, __VA_ARGS__)
126 extern os_log_t
_OctagonSignpostLogSystem(void);
128 extern OctagonSignpost
_OctagonSignpostCreate(os_log_t subsystem
);
129 extern uint64_t _OctagonSignpostGetNanoseconds(OctagonSignpost signpost
);
131 #define _OctagonSignpostBegin(subsystem, name, ...) __extension__({ \
132 OctagonSignpost internalSignpost = _OctagonSignpostCreate(subsystem); \
133 os_signpost_interval_begin(subsystem, internalSignpost.identifier, name, __VA_ARGS__); \
134 os_log(subsystem, "BEGIN [%lld]: " name " " _OctagonSwizzle1(internalSignpost.identifier, __VA_ARGS__)); \
138 #define _OctagonSignpostEvent(subsystem, signpost, name, ...) __extension__({ \
139 double interval = ((double)_OctagonSignpostGetNanoseconds(_signpost) / NSEC_PER_SEC); \
140 os_signpost_event_emit(subsystem, signpost.identifier, name, __VA_ARGS__); \
141 os_log(subsystem, "EVENT [%lld] %fs: " name " " _OctagonSwizzle2(signpost.identifier, interval, __VA_ARGS__)); \
144 #define _OctagonSignpostEnd(subsystem, signpost, name, ...) __extension__({ \
145 double interval = ((double)_OctagonSignpostGetNanoseconds(signpost) / NSEC_PER_SEC); \
146 os_signpost_interval_end(subsystem, signpost.identifier, name, __VA_ARGS__); \
147 os_log(subsystem, "END [%lld] %fs: " name " " _OctagonSwizzle2(signpost.identifier, interval, __VA_ARGS__)); \
150 #define _OctagonSwizzle1(x, a, ...) a, x, ##__VA_ARGS__
151 #define _OctagonSwizzle2(x, y, a, ...) a, x, y, ##__VA_ARGS__
153 NS_ASSUME_NONNULL_END
155 #endif /* OctagonSignPosts_h */