rtwcodemetricsreport_utils.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2016 The MathWorks, Inc.
  2. //Poll for metrics.js on 5 second intervals
  3. function getCodeMetricsByPolling(ctThreshold, intervalPeriod){
  4. if(ctThreshold === undefined){
  5. ctThreshold = 1000;
  6. }
  7. if(intervalPeriod === undefined){
  8. intervalPeriod = 5000;
  9. }
  10. var intervalId;
  11. var ct=0;
  12. //function to get code metrics
  13. function getCodeMetrics(){
  14. cm = CodeMetrics.instance;
  15. var alink = document.getElementById("metricsLocation");
  16. alink.innerHTML = cm.codeMetricsSummary;
  17. }
  18. if (typeof CodeMetrics !== "undefined"){
  19. getCodeMetrics();
  20. }
  21. else{
  22. intervalId = window.setInterval(function(){
  23. //Try reinclude metrics to check if CodeMetrics are available
  24. ct = ct + 1;
  25. if (ct > ctThreshold){
  26. // Clear if elapsed time is 1000x5 seconds
  27. clearInterval(intervalId);
  28. var alink = document.getElementById("metricsLocation");
  29. alink.innerHTML = 'Error generating code metrics';
  30. }
  31. else{
  32. var metricsScript = document.getElementById('metrics');
  33. if(metricsScript !== null){
  34. metricsScript.parentNode.removeChild(metricsScript);
  35. }
  36. var jsElm = document.createElement("script");
  37. jsElm.type = "application/javascript";
  38. jsElm.src = "metrics.js";
  39. jsElm.id = "metrics";
  40. document.getElementsByTagName('head')[0].appendChild(jsElm);
  41. if (typeof CodeMetrics !== "undefined"){
  42. clearInterval(intervalId);
  43. getCodeMetrics();
  44. }
  45. }
  46. }, intervalPeriod);
  47. }
  48. }