profiling.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <html>
  2. <head>
  3. <title>Customize BJS for a specific Scene</title>
  4. <meta charset="UTF-8">
  5. <script src="../../dist/preview release/babylon.js"></script>
  6. <style>
  7. input.path {width:600px;}
  8. input.filename {width:200px;}
  9. em {color:red;}
  10. </style>
  11. </head>
  12. <body onload="readConfigFile()">
  13. Obtain a performance file by:
  14. <ol>
  15. <li>Make sure scene uses Babylon MAX.</li>
  16. <li>Add the temporary Javascript line <em>window.alert('Turn on Performance Recording')</em> just prior to Engine Instancing line.
  17. <li>Load the scene, turn on performance profiling, &amp; click ok to the temporary alert.</li>
  18. <li>Do anything that might call code in babylon.js not yet encountered.</li>
  19. <li>Stop recording, and save the data as a file.</li>
  20. </ol>
  21. On this page:
  22. <ol>
  23. <li>Select the branch to build the config against. <em>Be sure to change to that branch in repo</em>
  24. <li>Select File with 'Browse' button below, and pick the file saved from above.</li>
  25. <li>Make any changes of name to babylon file names &amp; directory..</li>
  26. <li>Click Generate. Tip: change Firefox Option for Downloads to <em>Always ask me where to save files</em> to avoid having to move config with custom entries to Gulp Directory.</li>
  27. <li>Copy the 'custom.cofig.json' file generated in Downloads directory to the Gulp directory.</li>
  28. <li>Run: 'Gulp build-custom' then test with scene. Tip: test with the generated max version.</li>
  29. <li>If need stuff did not get recorded in performance file, then select file(s) &amp; click Generate again.</li>
  30. </ol>
  31. <form>
  32. BJS Version for Build: <select id="versions" onchange="readConfigFile()">
  33. <option value="https://raw.githubusercontent.com/BabylonJS/Babylon.js/master/Tools/Config/config.json">Master</option>
  34. <option value="https://raw.githubusercontent.com/BabylonJS/Babylon.js/preview/Tools/Config/config.json">Preview</option>
  35. <option value="./config.json">Current Local Branch (Firefox only)</option>
  36. </select><br>
  37. <label>Profiling file: <input type="file" id="upload_file" name="upload" accept="text/*" multiple="" onchange="assignProfile(this.files[0])"/></label><br>
  38. Source of Performance Data:
  39. <input type="radio" name="browser" id="firefox" checked="checked"><label for="firefox"> Firefox</label>
  40. <input type="radio" name="browser" id="chrome" disabled data-toggle="tooltip" title="Not yet implemented, Go for it!"><label for="chrome"> Chrome</label>
  41. <input type="radio" name="browser" id="edge" disabled data-toggle="tooltip" title="Not yet implemented, Go for it!"><label for="edge"> Edge</label><br><br>
  42. Output Directory: <input class="path" type="text" id="directory" maxlength="256" value="C:/"> (clear for default of <em>../../dist/preview release</em>)<br>
  43. Base name: <input class="basename" type="text" id="basename" maxlength="32" value="babylon.custom"> Generates basename.js & basename.max.js
  44. <table border="1">
  45. <tr><th colspan="2"><input type="button" value="Generate Custom Config" onclick="generate()"></th></tr>
  46. <tr><td>Found</td><td>Not Found: (Select those to keep anyway)</td></tr>
  47. <tr>
  48. <td><select id="found" multiple size="50" disabled></select></td>
  49. <td><select id="discards" multiple size="50"></select></td>
  50. </tr>
  51. </table>
  52. </form>
  53. <script>
  54. // each "WorkLoad" is a: [keep: boolean, name: string]
  55. // search is initially the file name without the .js.
  56. var workloads;
  57. // each "File" is a: [workLoad: WorkLoad, fullPath: string, search]
  58. // search is initially the file name without the .js.
  59. var files;
  60. var reg = new RegExp('babylon\\.\\w+'); // all the letters of the base filename, but not including the .js
  61. var FIRE_FOX = 0;
  62. var CHROME = 1;
  63. var EDGE = 3;
  64. var parsedConfig;
  65. function readConfigFile() {
  66. var versions = document.getElementById("versions");
  67. BABYLON.Tools.LoadFile(versions.options[versions.selectedIndex].value,
  68. function(data){
  69. parsedConfig = JSON.parse(data);
  70. allLoads = parsedConfig.buildConfigurations.all;
  71. workloads = new Array();
  72. files = new Array();
  73. for (var i = 0, len = allLoads.length; i < len; i++) {
  74. var wkLoad = [false, allLoads[i]];
  75. workloads.push(wkLoad);
  76. var loadFiles = parsedConfig.workloads[allLoads[i]].files;
  77. for (var z = 0, fLen = loadFiles.length; z < fLen; z++){
  78. var file = loadFiles[z];
  79. var name = file.match(reg)[0].substring(8); // remove the babylon.
  80. files[i] = [wkLoad, file, name];
  81. }
  82. }
  83. }, null, true
  84. );
  85. }
  86. /** add addition conditions to match a file to examples:
  87. * appendSecondarySearches("math.js", "mathtools|color3");
  88. * appendSecondarySearches("freeCamera.js", "freeCamera\\w+");
  89. *
  90. * additionals is a string with all separated with a '|'
  91. * not currently needed
  92. */
  93. function appendSecondarySearches(baseFilename, additionals) {
  94. for (var i = 0, len = files.length; i < len; i++) {
  95. if (files[i][1].indexOf(baseFilename) !== -1) {
  96. files[i][2] += "|" + additionals;
  97. return;
  98. }
  99. }
  100. throw "'" + baseFilename + "' not found as a base file name";
  101. }
  102. function assignProfile(file) {
  103. BABYLON.Tools.ReadFile(file, analyse, null, false);
  104. }
  105. function analyse(data){
  106. // make sure max was used
  107. if (!data.match('\\.max\\.js')) {
  108. alert('babylon.max not detected. File rejected');
  109. return;
  110. }
  111. var browser;
  112. if (document.getElementById("firefox").checked) browser = FIRE_FOX;
  113. if (document.getElementById("chrome" ).checked) browser = CHROME;
  114. if (document.getElementById("edge" ).checked) browser = EDGE;
  115. // clean out for prior runs
  116. for (var i = 0, len = workloads.length; i < len; i++) {
  117. workloads[i][0] = false;
  118. }
  119. for (var i = 0, len = files.length; i < len; i++) {
  120. var file = files[i];
  121. var wkLoad = file[0];
  122. switch(browser) {
  123. case FIRE_FOX:
  124. var exp = new RegExp('"(' + file[2] + ')(\\.prototype|\\.\\w)', 'i');
  125. if (data.match(exp) ) {
  126. wkLoad[0] = true;
  127. }
  128. break;
  129. case CHROME:
  130. case EDGE:
  131. window.alert("Code from your PR goes here!");
  132. return;
  133. }
  134. }
  135. var found = document.getElementById("found");
  136. found.options.length = 0;
  137. var discards = document.getElementById("discards");
  138. discards.options.length = 0;
  139. // add onto the discard select when not found
  140. for (var i = 0, len = workloads.length; i < len; i++) {
  141. var option = document.createElement("option");
  142. option.text = workloads[i][1];
  143. if (!workloads[i][0]){
  144. discards.add(option);
  145. }else {
  146. found.add(option);
  147. }
  148. }
  149. }
  150. function generate() {
  151. // get all the ones from select
  152. var discards = document.getElementById("discards");
  153. var opt;
  154. var asText = "";
  155. for (var i = 0, len = discards.options.length; i < len; i++) {
  156. opt = discards.options[i];
  157. if (opt.selected) {
  158. asText += opt.text;
  159. }
  160. }
  161. var directory = document.getElementById("directory").value;
  162. var basename = document.getElementById("basename" ).value;
  163. if (directory.length === 0) directory = "../../dist/preview release";
  164. parsedConfig.build.outputDirectory = directory;
  165. parsedConfig.build.filename = basename + ".max.js";
  166. parsedConfig.build.minFilename = basename + ".js";
  167. parsedConfig.build.currentConfig = "custom";
  168. var neededLoads = [];
  169. for (var i = 0, len = workloads.length; i < len; i++) {
  170. if (workloads[i][0] || asText.indexOf(workloads[i][1]) !== -1) {
  171. neededLoads.push(workloads[i][1]);
  172. }
  173. }
  174. parsedConfig.buildConfigurations["custom"] = neededLoads;
  175. var blob = new Blob ( [ JSON.stringify(parsedConfig) ], { type : 'text/plain;charset=utf-8' } );
  176. // turn blob into an object URL;
  177. var objectUrl = (window.webkitURL || window.URL).createObjectURL(blob);
  178. var link = window.document.createElement("a");
  179. link.href = objectUrl;
  180. link.download = "config.json";
  181. var click = document.createEvent("MouseEvents");
  182. click.initEvent("click", true, false);
  183. link.dispatchEvent(click);
  184. }
  185. </script>
  186. </body>
  187. </html>