browser_profiling-webgl.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests if functions inside a single animation frame are recorded and stored
  5. * for a canvas context profiling.
  6. */
  7. function* ifTestingSupported() {
  8. let currentTime = window.performance.now();
  9. info("Start to estimate WebGL drawArrays function.");
  10. var { target, front } = yield initCanvasDebuggerBackend(WEBGL_DRAW_ARRAYS);
  11. let navigated = once(target, "navigate");
  12. yield front.setup({ reload: true });
  13. ok(true, "The front was setup up successfully.");
  14. yield navigated;
  15. ok(true, "Target automatically navigated when the front was set up.");
  16. let snapshotActor = yield front.recordAnimationFrame();
  17. ok(snapshotActor,
  18. "A snapshot actor was sent after recording.");
  19. let animationOverview = yield snapshotActor.getOverview();
  20. ok(animationOverview,
  21. "An animation overview could be retrieved after recording.");
  22. let functionCalls = animationOverview.calls;
  23. ok(functionCalls,
  24. "An array of function call actors was sent after recording.");
  25. testFunctionCallTimestamp(functionCalls, currentTime);
  26. info("Check triangle and vertex counts in drawArrays()");
  27. is(animationOverview.primitive.tris, 5, "The count of triangles is correct.");
  28. is(animationOverview.primitive.vertices, 26, "The count of vertices is correct.");
  29. is(animationOverview.primitive.points, 4, "The count of points is correct.");
  30. is(animationOverview.primitive.lines, 8, "The count of lines is correct.");
  31. yield removeTab(target.tab);
  32. info("Start to estimate WebGL drawElements function.");
  33. var { target, front } = yield initCanvasDebuggerBackend(WEBGL_DRAW_ELEMENTS);
  34. navigated = once(target, "navigate");
  35. yield front.setup({ reload: true });
  36. ok(true, "The front was setup up successfully.");
  37. yield navigated;
  38. ok(true, "Target automatically navigated when the front was set up.");
  39. snapshotActor = yield front.recordAnimationFrame();
  40. ok(snapshotActor,
  41. "A snapshot actor was sent after recording.");
  42. animationOverview = yield snapshotActor.getOverview();
  43. ok(animationOverview,
  44. "An animation overview could be retrieved after recording.");
  45. functionCalls = animationOverview.calls;
  46. ok(functionCalls,
  47. "An array of function call actors was sent after recording.");
  48. testFunctionCallTimestamp(functionCalls, currentTime);
  49. info("Check triangle and vertex counts in drawElements()");
  50. is(animationOverview.primitive.tris, 5, "The count of triangles is correct.");
  51. is(animationOverview.primitive.vertices, 26, "The count of vertices is correct.");
  52. is(animationOverview.primitive.points, 4, "The count of points is correct.");
  53. is(animationOverview.primitive.lines, 8, "The count of lines is correct.");
  54. yield removeTab(target.tab);
  55. finish();
  56. }
  57. function testFunctionCallTimestamp(functionCalls, currentTime) {
  58. info("Check the timestamps of function calls");
  59. for ( let i = 0; i < functionCalls.length-1; i += 2 ) {
  60. ok( functionCalls[i].timestamp > 0, "The timestamp of the called function is larger than 0." );
  61. ok( functionCalls[i].timestamp < currentTime, "The timestamp has been minus the frame start time." );
  62. ok( functionCalls[i+1].timestamp > functionCalls[i].timestamp, "The timestamp of the called function is correct." );
  63. }
  64. yield removeTab(target.tab);
  65. finish();
  66. }