web/res/js/tracemanager.js
changeset 1304 10974bff4dae
parent 623 5b7d7ab6baff
equal deleted inserted replaced
1303:20e00017dd60 1304:10974bff4dae
    19  */
    19  */
    20 /* FIXME: properly use require.js feature. This will do for debugging in the meantime */
    20 /* FIXME: properly use require.js feature. This will do for debugging in the meantime */
    21 window.tracemanager = (function($) {
    21 window.tracemanager = (function($) {
    22      // If there are more than MAX_FAILURE_COUNT synchronisation
    22      // If there are more than MAX_FAILURE_COUNT synchronisation
    23      // failures, then disable synchronisation
    23      // failures, then disable synchronisation
    24      MAX_FAILURE_COUNT = 20;
    24     var MAX_FAILURE_COUNT = 20;
    25 
    25 
    26      // If there are more than MAX_BUFFER_SIZE obsels in the buffer,
    26      // If there are more than MAX_BUFFER_SIZE obsels in the buffer,
    27      // then "compress" them as a single "ktbsFullBuffer"
    27      // then "compress" them as a single "ktbsFullBuffer"
    28      MAX_BUFFER_SIZE = 500;
    28     var  MAX_BUFFER_SIZE = 500;
    29 
    29 
       
    30     var _replacement = {
       
    31          ';': '"',
       
    32          '"': ';',
       
    33          '#': '%23',
       
    34          '&': '%26',
       
    35          '?': '%3F'
       
    36      };
    30      var BufferedService_prototype = {
    37      var BufferedService_prototype = {
    31          /*
    38          /*
    32           *  Buffered service for traces
    39           *  Buffered service for traces
    33           */
    40           */
    34          // url: "",
    41          // url: "",
    58                      // prefixing it with c
    65                      // prefixing it with c
    59                      var data = 'c' + JSON.stringify(temp.map(function (o) { return o.toCompactJSON(); }));
    66                      var data = 'c' + JSON.stringify(temp.map(function (o) { return o.toCompactJSON(); }));
    60                      // Swap " (very frequent, which will be
    67                      // Swap " (very frequent, which will be
    61                      // serialized into %22) and ; (rather rare), this
    68                      // serialized into %22) and ; (rather rare), this
    62                      // saves some bytes
    69                      // saves some bytes
    63                      data = data.replace(/[;"#]/g, function(s){ return s == ';' ? '"' : ( s == '"' ? ';' : '%23'); });
    70                      data = data.replace(/[;"#?&]/g, function(s){ return _replacement[s]; });
    64                      // FIXME: check data length (< 2K is safe)
    71                      // FIXME: check data length (< 2K is safe)
    65                      var request=$('<img />').error( function() { this.failureCount += 1; })
    72                      var request=$('<img />').error( function() { this.failureCount += 1; })
    66                          .load( function() { this.failureCount = 0; })
    73                          .load( function() { this.failureCount = 0; })
    67                          .attr('src', this.url + 'trace/?data=' + data);
    74                          .attr('src', this.url + 'trace/?data=' + data);
    68                  }
    75                  }