chromeTrace.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
  2. declare namespace ChromeTrace {
  3. interface ObjectFormat {
  4. traceEvents: ReadonlyArray<Event>;
  5. displayTimeUnit: 'ms' | 'ns';
  6. /**
  7. * Linux ftrace data or Windows ETW trace data.
  8. * This data must start with # tracer: and adhere to the
  9. * Linux ftrace format or adhere to Windows ETW format.
  10. */
  11. systemTraceEvents: string;
  12. otherData: Record<string, string>;
  13. powerTraceAsString: string;
  14. /**
  15. * string that specifies which trace data comes from tracing controller.
  16. * Its value should be the key for that specific trace data. For example,
  17. * {..., "controllerTraceDataKey": "traceEvents"} means the data for traceEvents
  18. * comes from the tracing controller. This is mainly for the purpose of clock synchronization.
  19. */
  20. controllerTraceDataKey?: string;
  21. stackFrames: ReadonlyArray<any>;
  22. samples: ReadonlyArray<any>;
  23. }
  24. type ArrayFormat = Array<Event | ProfileEvent>;
  25. type DurationEvent = 'B' | 'E';
  26. // Instant event
  27. type CompleteEvent = 'X';
  28. type InstantEvent = 'i';
  29. type DeprecatedInstantEvent = 'I';
  30. type CounterEvent = 'C';
  31. // b = nestable start, n = nestable instant, e = nestable end
  32. type AsyncEvent = 'b' | 'n' | 'e';
  33. // S = start, T = step into, p = step past, F = end
  34. type DeprecatedAsyncEvent = 'S' | 'T' | 'p' | 'F';
  35. // s = start, t = step, f = end
  36. type FlowEvent = 's' | 't' | 'f';
  37. type SampleEvent = 'P';
  38. // N = created, O = snapshot, D = destroyed
  39. type ObjectEvent = 'N' | 'O' | 'D';
  40. type MetadataEvent = 'M';
  41. // V = global, v = process
  42. type MemoryDumpEvent = 'V' | 'v';
  43. type MarkEvent = 'R';
  44. type ClockSyncEvent = 'c';
  45. type ContextEvents = '(,)';
  46. interface Event {
  47. name: string;
  48. cat: string;
  49. ph:
  50. | DurationEvent
  51. | CompleteEvent
  52. | InstantEvent
  53. | DeprecatedInstantEvent
  54. | CounterEvent
  55. | AsyncEvent
  56. | DeprecatedAsyncEvent
  57. | FlowEvent
  58. | SampleEvent
  59. | ObjectEvent
  60. | MetadataEvent
  61. | MemoryDumpEvent
  62. | MarkEvent
  63. | ClockSyncEvent
  64. | ContextEvents;
  65. ts: number;
  66. // Thread clock timestamp
  67. tts?: number;
  68. dur?: number;
  69. tdur?: number;
  70. pid: number;
  71. tid: number;
  72. id?: string;
  73. cname?: string;
  74. args: Record<string, any | Record<string, any>>;
  75. }
  76. // Thread metadata event
  77. interface ThreadMetadataEvent extends Event {
  78. cat: '__metadata';
  79. name: 'thread_name';
  80. ph: 'M';
  81. args: {name: string};
  82. }
  83. interface ProfileEvent extends Event {
  84. cat: string;
  85. id: string;
  86. name: 'Profile';
  87. ph: 'P';
  88. pid: number;
  89. tid: number;
  90. ts: number;
  91. tts: number;
  92. args: {data: CpuProfile};
  93. }
  94. interface ProfileChunkEvent extends Event {
  95. cat: string;
  96. id: string;
  97. name: 'ProfileChunk';
  98. ph: 'P';
  99. pid: number;
  100. tid: number;
  101. ts: number;
  102. tts: number;
  103. args: {data: {cpuProfile: CpuProfile}};
  104. }
  105. // https://github.com/v8/v8/blob/b8626ca445554b8376b5a01f651b70cb8c01b7dd/src/inspector/js_protocol.json#L1496
  106. interface PositionTickInfo {
  107. line: number;
  108. ticks: number;
  109. }
  110. // https://github.com/v8/v8/blob/b8626ca445554b8376b5a01f651b70cb8c01b7dd/src/inspector/js_protocol.json#L2292
  111. interface CallFrame {
  112. functionName: string;
  113. scriptId: string;
  114. url: string;
  115. lineNumber: number;
  116. columnNumber: number;
  117. // This seems to be present in some profiles with value "JS"
  118. codeType?: string;
  119. }
  120. // https://github.com/v8/v8/blob/b8626ca445554b8376b5a01f651b70cb8c01b7dd/src/inspector/js_protocol.json#L1399
  121. interface ProfileNode {
  122. id: number;
  123. callFrame: CPUProfileCallFrame;
  124. hitCount: number;
  125. children?: number[];
  126. parent?: CPUProfileNode;
  127. deoptReason?: string;
  128. positionTicks?: PositionTickInfo[];
  129. }
  130. // https://github.com/v8/v8/blob/b8626ca445554b8376b5a01f651b70cb8c01b7dd/src/inspector/js_protocol.json#L1453
  131. interface CpuProfile {
  132. nodes: ProfileNode[];
  133. startTime: number;
  134. endTime: number;
  135. samples?: number[];
  136. timeDeltas?: number[];
  137. }
  138. type ProfileType = ArrayFormat | ObjectFormat;
  139. }