Umberto,

Thank you for the suggestion. I had actually done that before, but was looking for a less intrusive way of setting this up.

As it turns out I was close, this is what I finally ended up with:

    function decorateOpenLayersAjax(f) {
       return function() {
         var startT = new Data();
         var answer = f.apply(OpenLayers.Request, arguments);
         try {
           var deltaT = ((new Date()).getTime() -
                         startT.getTime())/1000.0;
           logtime(deltaT);
         }
         finally {
           return answer;
         }
      };
    }

Then this works:

    OpenLayers.Request.issue =
      decorateOpenLayersAjax(OpenLayers.Request.issue);

Its a nice clean what of doing this so you intercept all ajax requests independently of how your application is built.

-Steve

On 2/2/2013 3:50 AM, Umberto Nicoletti wrote:
I would use an event listener instead:

start the timer on complete event

stop andlog  it on success or failure

hth,
Umberto

On Saturday, February 2, 2013, Stephen Woodbridge wrote:

    Hi All,

    I am trying to add some tracking code to my OpenLayers app so I can
    track performance of ajax requests. So my plan was to decorate the
    OpenLayers.Request.issue function to log the time before and after
    the issue().

    Something like:

    function decorateOpenLayersAjax(f) {
       var startT = new Data();
       var answer = f.apply(this, arguments);
       try {
         var deltaT = ((new Date()).getTime() - startT.getTime())/1000.0;
         logtime(deltaT);
       }
       finally {
         return answer;
       }
    }

    And then in my init() function:

    OpenLayers.Request.issue =
    decorateOpenLayersAjax(__OpenLayers.Request.issue);

    My page loads fine, but on the first ajax request I get the error:

    TypeError: a.headers is undefined

    which implies that my decoration is breaking the code in:

    "ol212/lib/OpenLayers/Request.__js" line 165

         issue: function(config) {
             // apply default config - proxy host may have changed
             var defaultConfig = OpenLayers.Util.extend(
                 this.DEFAULT_CONFIG,
                 {proxy: OpenLayers.ProxyHost}
             );
             config = OpenLayers.Util.applyDefaults(__config,
    defaultConfig);

    It seems that this.DEFAULT_CONFIG no longer points to the original
    object where it is defined.

    Any ideas on how to do this, or a better way to do this would be
    appreciated.

    -Steve
    _________________________________________________
    Users mailing list
    [email protected]
    http://lists.osgeo.org/__mailman/listinfo/openlayers-__users
    <http://lists.osgeo.org/mailman/listinfo/openlayers-users>


_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to