profile.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {
  2. isChromeTraceArrayFormat,
  3. isEventedProfile,
  4. isJSProfile,
  5. isSampledProfile,
  6. isTypescriptChromeTraceArrayFormat,
  7. } from 'sentry/utils/profiling/guards/profile';
  8. const sampledProfile: Profiling.SampledProfile = {
  9. type: 'sampled',
  10. weights: [],
  11. samples: [],
  12. name: 'profile',
  13. unit: 'milliseconds',
  14. threadID: 0,
  15. endValue: 0,
  16. startValue: 100,
  17. };
  18. const eventedProfile: Profiling.EventedProfile = {
  19. type: 'evented',
  20. events: [],
  21. name: 'profile',
  22. unit: 'milliseconds',
  23. threadID: 0,
  24. endValue: 0,
  25. startValue: 100,
  26. };
  27. const jsProfile: JSSelfProfiling.Trace = {
  28. resources: [],
  29. frames: [],
  30. stacks: [],
  31. samples: [],
  32. };
  33. const typescriptTraceProfile: ChromeTrace.ArrayFormat = [
  34. {
  35. args: {},
  36. cat: '',
  37. name: 'thread_name',
  38. ph: 'B',
  39. pid: 579,
  40. tid: 259,
  41. ts: 0,
  42. },
  43. {
  44. args: {},
  45. cat: '',
  46. name: 'thread_name',
  47. ph: 'E',
  48. pid: 579,
  49. tid: 259,
  50. ts: 0,
  51. },
  52. ];
  53. const chrometraceArrayFormat: ChromeTrace.ArrayFormat = [
  54. {cat: '', ph: 'P', name: 'ProfileChunk', args: {}, pid: 579, tid: 259, ts: 0},
  55. ];
  56. describe('profile', () => {
  57. it('is sampled', () => expect(isSampledProfile(sampledProfile)).toBe(true));
  58. it('is evented', () => expect(isEventedProfile(eventedProfile)).toBe(true));
  59. it('is js self profile', () => expect(isJSProfile(jsProfile)).toBe(true));
  60. it('is ts profile', () => {
  61. // Since these are the same format, just different contents, we test both to make
  62. // sure that one does not pass through the other.
  63. expect(isTypescriptChromeTraceArrayFormat(typescriptTraceProfile)).toBe(true);
  64. expect(isTypescriptChromeTraceArrayFormat(chrometraceArrayFormat)).toBe(false);
  65. });
  66. it('is chrometrace format', () => {
  67. // Since these are the same format, just different contents, we test both to make
  68. // sure that one does not pass through the other.
  69. expect(isChromeTraceArrayFormat(chrometraceArrayFormat)).toBe(true);
  70. expect(isChromeTraceArrayFormat(typescriptTraceProfile)).toBe(false);
  71. });
  72. });