ASLog.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // ASLog.h
  3. // AsyncDisplayKit
  4. //
  5. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  6. // This source code is licensed under the BSD-style license found in the
  7. // LICENSE file in the root directory of this source tree. An additional grant
  8. // of patent rights can be found in the PATENTS file in the same directory.
  9. //
  10. #pragma once
  11. #import "ASAvailability.h"
  12. #define ASMultiplexImageNodeLogDebug(...)
  13. #define ASMultiplexImageNodeCLogDebug(...)
  14. #define ASMultiplexImageNodeLogError(...)
  15. #define ASMultiplexImageNodeCLogError(...)
  16. // Note: `<sys/kdebug_signpost.h>` only exists in Xcode 8 and later.
  17. #if PROFILE && __has_include("<sys/kdebug_signpost.h>")
  18. #import <sys/kdebug_signpost.h>
  19. // These definitions are required to build the backward-compatible kdebug trace
  20. // on the iOS 10 SDK. The kdebug_trace function crashes if run on iOS 9 and earlier.
  21. // It's valuable to support trace signposts on iOS 9, because A5 devices don't support iOS 10.
  22. #ifndef DBG_MACH_CHUD
  23. #define DBG_MACH_CHUD 0x0A
  24. #define DBG_FUNC_START 1
  25. #define DBG_FUNC_END 2
  26. #define DBG_APPS 33
  27. #define SYS_kdebug_trace 180
  28. #define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
  29. #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
  30. #endif
  31. #define ASProfilingSignpost(x) \
  32. AS_AT_LEAST_IOS10 ? kdebug_signpost(x, 0, 0, 0, (uint32_t)(x % 4)) \
  33. : syscall(SYS_kdebug_trace, APPSDBG_CODE(DBG_MACH_CHUD, x) | DBG_FUNC_NONE, 0, 0, 0, (uint32_t)(x % 4));
  34. #define ASProfilingSignpostStart(x, y) \
  35. AS_AT_LEAST_IOS10 ? kdebug_signpost_start((uint32_t)x, (uintptr_t)y, 0, 0, (uint32_t)(x % 4)) \
  36. : syscall(SYS_kdebug_trace, APPSDBG_CODE(DBG_MACH_CHUD, x) | DBG_FUNC_START, (uintptr_t)y, 0, 0, (uint32_t)(x % 4));
  37. #define ASProfilingSignpostEnd(x, y) \
  38. AS_AT_LEAST_IOS10 ? kdebug_signpost_end((uint32_t)x, (uintptr_t)y, 0, 0, (uint32_t)(x % 4)) \
  39. : syscall(SYS_kdebug_trace, APPSDBG_CODE(DBG_MACH_CHUD, x) | DBG_FUNC_END, (uintptr_t)y, 0, 0, (uint32_t)(x % 4));
  40. #else
  41. #define ASProfilingSignpost(x)
  42. #define ASProfilingSignpostStart(x, y)
  43. #define ASProfilingSignpostEnd(x, y)
  44. #endif