Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Allow for unlimited data capture size
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed May 10, 2016
1 parent 1f07e00 commit 21ef3b2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
5 changes: 3 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ module.exports = {
// gathered on large object. A value of 0 disables the limit.
maxProperties: 0,

// Total 'size' if data to gather. This is NOT the number of bytes of data
// Total 'size' of data to gather. This is NOT the number of bytes of data
// that are sent over the wire, but instead a very very coarse approximation
// based on the length of names and values of the properties. This should
// be somewhat proportional to the amount of processing needed to capture
// the data and subsequently the network traffic.
// the data and subsequently the network traffic. A value of 0 disables the
// limit.
maxDataSize: 20000,

// To limit the size of the buffer, we truncate long strings.
Expand Down
3 changes: 2 additions & 1 deletion lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ StateResolver.prototype.capture_ = function() {

// Now resolve the variables
var index = MESSAGE_TABLE.length; // skip the sentinel values
var noLimit = that.config_.capture.maxDataSize === 0;
while (index < that.rawVariableTable_.length && // NOTE: length changes in loop
that.totalSize_ < that.config_.capture.maxDataSize) {
(that.totalSize_ < that.config_.capture.maxDataSize || noLimit)) {
assert(!that.resolvedVariableTable_[index]); // shouldn't have it resolved yet
that.resolvedVariableTable_[index] =
that.resolveMirror_(that.rawVariableTable_[index]);
Expand Down
85 changes: 85 additions & 0 deletions test/standalone/test-max-data-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
/*2*/'use strict';
/*3*/function foo(n) {
/*4*/ var A = new Array(3); return n+42+A[0];
/*5*/}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

process.env.GCLOUD_DIAGNOSTICS_CONFIG = 'test/fixtures/test-config.js';

var assert = require('assert');
var logModule = require('@google/cloud-diagnostics-common').logger;
var v8debugapi = require('../../lib/v8debugapi.js');
var scanner = require('../../lib/scanner.js');
var config = require('../../config.js');
var api;

var breakpointInFoo = {
id: 'fake-id-123',
location: { path: 'test-max-data-size.js', line: 4 }
};

describe('maxDataSize', function() {
before(function(done) {
if (!api) {
var logger = logModule.create(config.logLevel);
scanner.scan(true, config.workingDirectory, function(err, fileStats, hash) {
assert(!err);
api = v8debugapi.create(logger, config, fileStats);
done();
});
} else {
done();
}
});

it('should limit data reported', function(done) {
config.capture.maxDataSize = 5;
// clone a clean breakpointInFoo
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
api.set(bp, function(err) {
assert.ifError(err);
api.wait(bp, function(err) {
assert.ifError(err);
assert(bp.variableTable.some(function(v) {
return v.status.description.format === 'Max data size reached';
}));
api.clear(bp);
done();
});
process.nextTick(function() {foo(2);});
});
});

it('should be unlimited if 0', function(done) {
config.capture.maxDataSize = 0;
// clone a clean breakpointInFoo
var bp = {id: breakpointInFoo.id, location: breakpointInFoo.location};
api.set(bp, function(err) {
assert.ifError(err);
api.wait(bp, function(err) {
assert.ifError(err);
assert(bp.variableTable.reduce(function(acc, elem) {
return acc && elem.status.description.format !== 'Max data size reached';
}), true);
api.clear(bp);
done();
});
process.nextTick(function() {foo(2);});
});
});
});

0 comments on commit 21ef3b2

Please sign in to comment.