profiler.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.lang.aspect.profiler"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.lang.aspect.profiler"] = true;
  8. dojo.provide("dojox.lang.aspect.profiler");
  9. (function(){
  10. var aop = dojox.lang.aspect,
  11. uniqueNumber = 0;
  12. var Profiler = function(title){
  13. this.args = title ? [title] : [];
  14. this.inCall = 0;
  15. };
  16. dojo.extend(Profiler, {
  17. before: function(/*arguments*/){
  18. if(!(this.inCall++)){
  19. console.profile.apply(console, this.args);
  20. }
  21. },
  22. after: function(/*excp*/){
  23. if(!--this.inCall){
  24. console.profileEnd();
  25. }
  26. }
  27. });
  28. aop.profiler = function(/*String?*/ title){
  29. // summary:
  30. // Returns an object, which can be used to time calls to methods.
  31. //
  32. // title:
  33. // The optional name of the profile section.
  34. return new Profiler(title); // Object
  35. };
  36. })();
  37. }