QuickPerformanceLogger.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict
  9. */
  10. 'use strict';
  11. const AUTO_SET_TIMESTAMP = -1;
  12. const DUMMY_INSTANCE_KEY = 0;
  13. const QuickPerformanceLogger = {
  14. markerStart(
  15. markerId: number,
  16. instanceKey: number = DUMMY_INSTANCE_KEY,
  17. timestamp: number = AUTO_SET_TIMESTAMP,
  18. ): void {
  19. if (global.nativeQPLMarkerStart) {
  20. global.nativeQPLMarkerStart(markerId, instanceKey, timestamp);
  21. }
  22. },
  23. markerEnd(
  24. markerId: number,
  25. actionId: number,
  26. instanceKey: number = DUMMY_INSTANCE_KEY,
  27. timestamp: number = AUTO_SET_TIMESTAMP,
  28. ): void {
  29. if (global.nativeQPLMarkerEnd) {
  30. global.nativeQPLMarkerEnd(markerId, instanceKey, actionId, timestamp);
  31. }
  32. },
  33. markerTag(
  34. markerId: number,
  35. tag: string,
  36. instanceKey: number = DUMMY_INSTANCE_KEY,
  37. ): void {
  38. if (global.nativeQPLMarkerTag) {
  39. global.nativeQPLMarkerTag(markerId, instanceKey, tag);
  40. }
  41. },
  42. markerAnnotate(
  43. markerId: number,
  44. annotationKey: string,
  45. annotationValue: string,
  46. instanceKey: number = DUMMY_INSTANCE_KEY,
  47. ): void {
  48. if (global.nativeQPLMarkerAnnotate) {
  49. global.nativeQPLMarkerAnnotate(
  50. markerId,
  51. instanceKey,
  52. annotationKey,
  53. annotationValue,
  54. );
  55. }
  56. },
  57. markerCancel(
  58. markerId: number,
  59. instanceKey?: number = DUMMY_INSTANCE_KEY,
  60. ): void {
  61. if (global.nativeQPLMarkerCancel) {
  62. global.nativeQPLMarkerCancel(markerId, instanceKey);
  63. }
  64. },
  65. markerPoint(
  66. markerId: number,
  67. name: string,
  68. instanceKey: number = DUMMY_INSTANCE_KEY,
  69. timestamp: number = AUTO_SET_TIMESTAMP,
  70. ): void {
  71. if (global.nativeQPLMarkerPoint) {
  72. global.nativeQPLMarkerPoint(markerId, name, instanceKey, timestamp);
  73. }
  74. },
  75. markerDrop(
  76. markerId: number,
  77. instanceKey?: number = DUMMY_INSTANCE_KEY,
  78. ): void {
  79. if (global.nativeQPLMarkerDrop) {
  80. global.nativeQPLMarkerDrop(markerId, instanceKey);
  81. }
  82. },
  83. currentTimestamp(): number {
  84. if (global.nativeQPLTimestamp) {
  85. return global.nativeQPLTimestamp();
  86. }
  87. return 0;
  88. },
  89. };
  90. module.exports = QuickPerformanceLogger;