How to use _forceGC method in Best

Best JavaScript code snippet using best

perflog_metric.js

Source:perflog_metric.js Github

copy

Full Screen

1import { PromiseWrapper, Promise } from 'angular2/src/facade/async';2import {3 isPresent, isBlank, int, BaseException, StringWrapper, Math, RegExpWrapper, NumberWrapper4} from 'angular2/src/facade/lang';5import { ListWrapper, StringMap, StringMapWrapper } from 'angular2/src/facade/collection';6import { bind, OpaqueToken } from 'angular2/di';7import { WebDriverExtension, PerfLogFeatures } from '../web_driver_extension';8import { Metric } from '../metric';9import { Options } from '../common_options';10/**11 * A metric that reads out the performance log12 */13export class PerflogMetric extends Metric {14 // TODO(tbosch): use static values when our transpiler supports them15 static get BINDINGS() { return _BINDINGS; }16 // TODO(tbosch): use static values when our transpiler supports them17 static get SET_TIMEOUT() { return _SET_TIMEOUT; }18 _driverExtension:WebDriverExtension;19 _remainingEvents:List;20 _measureCount:int;21 _setTimeout:Function;22 _microMetrics:StringMap<string, string>;23 _perfLogFeatures:PerfLogFeatures;24 _forceGc:boolean;25 /**26 * @param driverExtension27 * @param setTimeout28 * @param microMetrics Name and description of metrics provided via console.time / console.timeEnd29 **/30 constructor(driverExtension:WebDriverExtension, setTimeout:Function, microMetrics:StringMap<string, string>, forceGc) {31 super();32 this._driverExtension = driverExtension;33 this._remainingEvents = [];34 this._measureCount = 0;35 this._setTimeout = setTimeout;36 this._microMetrics = microMetrics;37 this._perfLogFeatures = driverExtension.perfLogFeatures();38 this._forceGc = forceGc;39 }40 describe():StringMap {41 var res = {42 'scriptTime': 'script execution time in ms, including gc and render',43 'pureScriptTime': 'script execution time in ms, without gc nor render'44 };45 if (this._perfLogFeatures.render) {46 res['renderTime'] = 'render time in ms';47 }48 if (this._perfLogFeatures.gc) {49 res['gcTime'] = 'gc time in ms';50 res['gcAmount'] = 'gc amount in kbytes';51 res['majorGcTime'] = 'time of major gcs in ms';52 if (this._forceGc) {53 res['forcedGcTime'] = 'forced gc time in ms';54 res['forcedGcAmount'] = 'forced gc amount in kbytes';55 }56 }57 StringMapWrapper.forEach(this._microMetrics, (desc, name) => {58 StringMapWrapper.set(res, name, desc);59 });60 return res;61 }62 beginMeasure():Promise {63 var resultPromise = PromiseWrapper.resolve(null);64 if (this._forceGc) {65 resultPromise = resultPromise.then( (_) => this._driverExtension.gc() );66 }67 return resultPromise.then( (_) => this._beginMeasure() );68 }69 endMeasure(restart:boolean):Promise<StringMap> {70 if (this._forceGc) {71 return this._endPlainMeasureAndMeasureForceGc(restart);72 } else {73 return this._endMeasure(restart);74 }75 }76 _endPlainMeasureAndMeasureForceGc(restartMeasure:boolean) {77 return this._endMeasure(true).then( (measurValues) => {78 return this._driverExtension.gc()79 .then( (_) => this._endMeasure(restartMeasure) )80 .then( (forceGcMeasureValues) => {81 StringMapWrapper.set(measurValues, 'forcedGcTime', forceGcMeasureValues['gcTime']);82 StringMapWrapper.set(measurValues, 'forcedGcAmount', forceGcMeasureValues['gcAmount']);83 return measurValues;84 });85 });86 }87 _beginMeasure():Promise {88 return this._driverExtension.timeBegin(this._markName(this._measureCount++));89 }90 _endMeasure(restart:boolean):Promise<StringMap> {91 var markName = this._markName(this._measureCount-1);92 var nextMarkName = restart ? this._markName(this._measureCount++) : null;93 return this._driverExtension.timeEnd(markName, nextMarkName)94 .then( (_) => this._readUntilEndMark(markName) );95 }96 _readUntilEndMark(markName:string, loopCount:int = 0, startEvent = null) {97 if (loopCount > _MAX_RETRY_COUNT) {98 throw new BaseException(`Tried too often to get the ending mark: ${loopCount}`);99 }100 return this._driverExtension.readPerfLog().then( (events) => {101 this._addEvents(events);102 var result = this._aggregateEvents(103 this._remainingEvents, markName104 );105 if (isPresent(result)) {106 this._remainingEvents = events;107 return result;108 }109 var completer = PromiseWrapper.completer();110 this._setTimeout(111 () => completer.resolve(this._readUntilEndMark(markName, loopCount+1)),112 100113 );114 return completer.promise;115 });116 }117 _addEvents(events) {118 var needSort = false;119 ListWrapper.forEach(events, (event) => {120 if (StringWrapper.equals(event['ph'], 'X')) {121 needSort = true;122 var startEvent = {};123 var endEvent = {};124 StringMapWrapper.forEach(event, (value, prop) => {125 startEvent[prop] = value;126 endEvent[prop] = value;127 });128 startEvent['ph'] = 'B';129 endEvent['ph'] = 'E';130 endEvent['ts'] = startEvent['ts'] + startEvent['dur'];131 ListWrapper.push(this._remainingEvents, startEvent);132 ListWrapper.push(this._remainingEvents, endEvent);133 } else {134 ListWrapper.push(this._remainingEvents, event);135 }136 });137 if (needSort) {138 // Need to sort because of the ph==='X' events139 ListWrapper.sort(this._remainingEvents, (a,b) => {140 var diff = a['ts'] - b['ts'];141 return diff > 0142 ? 1143 : diff < 0144 ? -1145 : 0;146 });147 }148 }149 _aggregateEvents(events, markName) {150 var result = {151 'scriptTime': 0,152 'pureScriptTime': 0153 };154 if (this._perfLogFeatures.gc) {155 result['gcTime'] = 0;156 result['majorGcTime'] = 0;157 result['gcAmount'] = 0;158 }159 if (this._perfLogFeatures.render) {160 result['renderTime'] = 0;161 }162 StringMapWrapper.forEach(this._microMetrics, (desc, name) => {163 result[name] = 0;164 });165 var markStartEvent = null;166 var markEndEvent = null;167 var gcTimeInScript = 0;168 var renderTimeInScript = 0;169 var intervalStarts = {};170 events.forEach( (event) => {171 var ph = event['ph'];172 var name = event['name'];173 var microIterations = 1;174 var microIterationsMatch = RegExpWrapper.firstMatch(_MICRO_ITERATIONS_REGEX, name);175 if (isPresent(microIterationsMatch)) {176 name = microIterationsMatch[1];177 microIterations = NumberWrapper.parseInt(microIterationsMatch[2], 10);178 }179 if (StringWrapper.equals(ph, 'b') && StringWrapper.equals(name, markName)) {180 markStartEvent = event;181 } else if (StringWrapper.equals(ph, 'e') && StringWrapper.equals(name, markName)) {182 markEndEvent = event;183 }184 if (isPresent(markStartEvent) && isBlank(markEndEvent) && event['pid'] === markStartEvent['pid']) {185 if (StringWrapper.equals(ph, 'B') || StringWrapper.equals(ph, 'b')) {186 intervalStarts[name] = event;187 } else if ((StringWrapper.equals(ph, 'E') || StringWrapper.equals(ph, 'e')) && isPresent(intervalStarts[name])) {188 var startEvent = intervalStarts[name];189 var duration = (event['ts'] - startEvent['ts']);190 intervalStarts[name] = null;191 if (StringWrapper.equals(name, 'gc')) {192 result['gcTime'] += duration;193 var amount = (startEvent['args']['usedHeapSize'] - event['args']['usedHeapSize']) / 1000;194 result['gcAmount'] += amount;195 var majorGc = event['args']['majorGc'];196 if (isPresent(majorGc) && majorGc) {197 result['majorGcTime'] += duration;198 }199 if (isPresent(intervalStarts['script'])) {200 gcTimeInScript += duration;201 }202 } else if (StringWrapper.equals(name, 'render')) {203 result['renderTime'] += duration;204 if (isPresent(intervalStarts['script'])) {205 renderTimeInScript += duration;206 }207 } else if (StringWrapper.equals(name, 'script')) {208 result['scriptTime'] += duration;209 } else if (isPresent(this._microMetrics[name])) {210 result[name] += duration / microIterations;211 }212 }213 }214 });215 result['pureScriptTime'] = result['scriptTime'] - gcTimeInScript - renderTimeInScript;216 return isPresent(markStartEvent) && isPresent(markEndEvent) ? result : null;217 }218 _markName(index) {219 return `${_MARK_NAME_PREFIX}${index}`;220 }221}222var _MICRO_ITERATIONS_REGEX = RegExpWrapper.create('(.+)\\*(\\d+)$');223var _MAX_RETRY_COUNT = 20;224var _MARK_NAME_PREFIX = 'benchpress';225var _SET_TIMEOUT = new OpaqueToken('PerflogMetric.setTimeout');226var _BINDINGS = [227 bind(PerflogMetric).toFactory(228 (driverExtension, setTimeout, microMetrics, forceGc) =>229 new PerflogMetric(driverExtension, setTimeout, microMetrics, forceGc),230 [WebDriverExtension, _SET_TIMEOUT, Options.MICRO_METRICS, Options.FORCE_GC]231 ),232 bind(_SET_TIMEOUT).toValue( (fn, millis) => PromiseWrapper.setTimeout(fn, millis) )...

Full Screen

Full Screen

sampler.js

Source:sampler.js Github

copy

Full Screen

1import { isPresent, isBlank, Date, DateWrapper } from 'angular2/src/facade/lang';2import { Promise, PromiseWrapper } from 'angular2/src/facade/async';3import { StringMapWrapper, StringMap, List, ListWrapper } from 'angular2/src/facade/collection';4import { bind, OpaqueToken } from 'angular2/di';5import { Metric } from './metric';6import { Validator } from './validator';7import { Reporter } from './reporter';8import { WebDriverExtension } from './web_driver_extension';9import { WebDriverAdapter } from './web_driver_adapter';10import { Options } from './common_options';11import { MeasureValues} from './measure_values';12/**13 * The Sampler owns the sample loop:14 * 1. calls the prepare/execute callbacks,15 * 2. gets data from the metric16 * 3. asks the validator for a valid sample17 * 4. reports the new data to the reporter18 * 5. loop until there is a valid sample19 */20export class Sampler {21 // TODO(tbosch): use static values when our transpiler supports them22 static get BINDINGS() { return _BINDINGS; }23 _driver:WebDriverAdapter;24 _driverExtension:WebDriverExtension;25 _metric:Metric;26 _reporter:Reporter;27 _validator:Validator;28 _forceGc:boolean;29 _prepare:Function;30 _execute:Function;31 _now:Function;32 constructor({33 driver, driverExtension, metric, reporter, validator, forceGc, prepare, execute, now34 }:{35 driver: WebDriverAdapter,36 driverExtension: WebDriverExtension, metric: Metric, reporter: Reporter,37 validator: Validator, prepare: Function, execute: Function, now: Function38 }={}) {39 this._driver = driver;40 this._driverExtension = driverExtension;41 this._metric = metric;42 this._reporter = reporter;43 this._validator = validator;44 this._forceGc = forceGc;45 this._prepare = prepare;46 this._execute = execute;47 this._now = now;48 }49 sample():Promise<SampleState> {50 var loop;51 loop = (lastState) => {52 return this._iterate(lastState)53 .then( (newState) => {54 if (isPresent(newState.validSample)) {55 return newState;56 } else {57 return loop(newState);58 }59 });60 }61 return this._gcIfNeeded().then( (_) => loop(new SampleState([], null)) );62 }63 _gcIfNeeded() {64 if (this._forceGc) {65 return this._driverExtension.gc();66 } else {67 return PromiseWrapper.resolve(null);68 }69 }70 _iterate(lastState) {71 var resultPromise;72 if (isPresent(this._prepare)) {73 resultPromise = this._driver.waitFor(this._prepare)74 .then( (_) => this._gcIfNeeded() );75 } else {76 resultPromise = PromiseWrapper.resolve(null);77 }78 if (isPresent(this._prepare) || lastState.completeSample.length === 0) {79 resultPromise = resultPromise.then( (_) => this._metric.beginMeasure() );80 }81 return resultPromise82 .then( (_) => this._driver.waitFor(this._execute) )83 .then( (_) => this._gcIfNeeded() )84 .then( (_) => this._metric.endMeasure(isBlank(this._prepare)) )85 .then( (measureValues) => this._report(lastState, measureValues) );86 }87 _report(state:SampleState, metricValues:StringMap):Promise<SampleState> {88 var measureValues = new MeasureValues(state.completeSample.length, this._now(), metricValues);89 var completeSample = ListWrapper.concat(state.completeSample, [measureValues]);90 var validSample = this._validator.validate(completeSample);91 var resultPromise = this._reporter.reportMeasureValues(measureValues);92 if (isPresent(validSample)) {93 resultPromise = resultPromise.then( (_) => this._reporter.reportSample(completeSample, validSample) )94 }95 return resultPromise.then( (_) => new SampleState(completeSample, validSample) );96 }97}98export class SampleState {99 completeSample:List;100 validSample:List;101 constructor(completeSample: List, validSample: List) {102 this.completeSample = completeSample;103 this.validSample = validSample;104 }105}106var _BINDINGS = [107 bind(Sampler).toFactory(108 (driver, driverExtension, metric, reporter, validator, forceGc, prepare, execute, now) => new Sampler({109 driver: driver,110 driverExtension: driverExtension,111 reporter: reporter,112 validator: validator,113 metric: metric,114 forceGc: forceGc,115 // TODO(tbosch): DI right now does not support null/undefined objects116 // Mostly because the cache would have to be initialized with a117 // special null object, which is expensive.118 prepare: prepare !== false ? prepare : null,119 execute: execute,120 now: now121 }),122 [123 WebDriverAdapter, WebDriverExtension, Metric, Reporter, Validator,124 Options.FORCE_GC, Options.PREPARE, Options.EXECUTE, Options.NOW125 ]126 )...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var heap = new BestFitHeap(1024);2heap._forceGC();3heap._forceGC();4heap._forceGC();5heap._forceGC();6heap._forceGC();7heap._forceGC();8heap._forceGC();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestieJS = require('bestiejs');2var _forceGC = BestieJS._forceGC;3var arr = new Array(1000000000);4var arr2 = new Array(1000000000);5arr = null;6arr2 = null;7console.log('Garbage collection done');8var BestieJS = require('bestiejs');9var _forceGC = BestieJS._forceGC;10var arr = new Array(1000000000);11var arr2 = new Array(1000000000);12arr = null;13arr2 = null;14console.log('Garbage collection done');15var BestieJS = require('bestiejs');16var _forceGC = BestieJS._forceGC;17var arr = new Array(1000000000);18var arr2 = new Array(1000000000);19arr = null;20arr2 = null;21console.log('Garbage collection done');22var BestieJS = require('bestiejs');23var _forceGC = BestieJS._forceGC;24var arr = new Array(1000000000);25var arr2 = new Array(1000000000);26arr = null;27arr2 = null;28console.log('Garbage collection done');29var BestieJS = require('bestiejs');30var _forceGC = BestieJS._forceGC;31var arr = new Array(1000000000);32var arr2 = new Array(1000000000);33arr = null;34arr2 = null;35console.log('Garbage collection done');36var BestieJS = require('bestiejs');37var _forceGC = BestieJS._forceGC;38var arr = new Array(1000000000);39var arr2 = new Array(

Full Screen

Using AI Code Generation

copy

Full Screen

1var bf = new BestFitHeap(10);2bf._forceGC();3bf._forceGC();4var a = bf.malloc(2);5var b = bf.malloc(2);6var c = bf.malloc(2);7bf.free(a);8bf.free(b);9bf.free(c);10bf._forceGC();11var d = bf.malloc(2);12if (d != a) {13 throw new Error("d should be equal to a");14}15bf.free(d);16bf._forceGC();17var e = bf.malloc(2);18if (e != a) {19 throw new Error("e should be equal to a");20}21bf.free(e);22bf._forceGC();23var f = bf.malloc(2);24if (f != a) {25 throw new Error("f should be equal to a");26}27bf.free(f);28bf._forceGC();29var g = bf.malloc(2);30if (g != a) {31 throw new Error("g should be equal to a");32}33bf.free(g);34bf._forceGC();35var h = bf.malloc(2);36if (h != a) {37 throw new Error("h should be equal to a");38}39bf.free(h);40bf._forceGC();41var i = bf.malloc(2);42if (i != a) {43 throw new Error("i should be equal to a");44}45bf.free(i);46bf._forceGC();47var j = bf.malloc(2);48if (j != a) {49 throw new Error("j should be equal to a");50}51bf.free(j);52bf._forceGC();53var k = bf.malloc(2);54if (k != a) {55 throw new Error("k should be equal to a");56}57bf.free(k);58bf._forceGC();59var l = bf.malloc(2);60if (l != a) {61 throw new Error("l should be equal to a");62}63bf.free(l);64bf._forceGC();65var m = bf.malloc(2);66if (m != a) {67 throw new Error("m should be equal to a");68}69bf.free(m);70bf._forceGC();71var n = bf.malloc(2);72if (n != a) {73 throw new Error("n should be equal to a");74}75bf.free(n);76bf._forceGC();77var o = bf.malloc(2);78if (o != a

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestFitMemoryManager = new BestFitMemoryManager();2var _forceGC = bestFitMemoryManager._forceGC;3var memory = new Memory();4memory.init(256);5var pids = [];6for (var i = 0; i < 4; i++) {7 var pid = _Kernel.krnCreateProcess("test4");8 pids.push(pid);9 _Kernel.krnRunProcess(pid);10}11for (var i = 0; i < 10; i++) {12 _Kernel.krnRunProcess(pids[0]);13}14_forceGC();15for (var i = 0; i < 10; i++) {16 _Kernel.krnRunProcess(pids[1]);17}18_forceGC();19for (var i = 0; i < 10; i++) {20 _Kernel.krnRunProcess(pids[2]);21}22_forceGC();23for (var i = 0; i < 10; i++) {24 _Kernel.krnRunProcess(pids[3]);25}26_forceGC();27for (var i = 0; i < 10; i++) {28 _Kernel.krnRunProcess(pids[0]);29}30_forceGC();31for (var i = 0; i < 10; i++) {32 _Kernel.krnRunProcess(pids[1]);33}34_forceGC();35for (var i = 0; i < 10; i++) {36 _Kernel.krnRunProcess(pids[2]);37}38_forceGC();39for (var i = 0; i < 10; i++) {40 _Kernel.krnRunProcess(pids[3]);41}42_forceGC();43for (var i = 0; i < 10; i++) {44 _Kernel.krnRunProcess(pids[0]);45}46_forceGC();

Full Screen

Using AI Code Generation

copy

Full Screen

1var c4 = new Packages.com.adobe.flex.extras.controls.springgraph.Graph();2c4.setMemoryManager(new Packages.com.adobe.flex.extras.controls.springgraph.BestFitMemoryManager());3c4.setMemoryManager(c4.getMemoryManager());4c4.getMemoryManager()._forceGC();5var c5 = new Packages.com.adobe.flex.extras.controls.springgraph.Graph();6c5.setMemoryManager(new Packages.com.adobe.flex.extras.controls.springgraph.BestFitMemoryManager());7c5.setMemoryManager(c5.getMemoryManager());8c5.getMemoryManager()._forceGC();9var c6 = new Packages.com.adobe.flex.extras.controls.springgraph.Graph();10c6.setMemoryManager(new Packages.com.adobe.flex.extras.controls.springgraph.BestFitMemoryManager());11c6.setMemoryManager(c6.getMemoryManager());12c6.getMemoryManager()._forceGC();13var c7 = new Packages.com.adobe.flex.extras.controls.springgraph.Graph();14c7.setMemoryManager(new Packages.com.adobe.flex.extras.controls.springgraph.BestFitMemoryManager());15c7.setMemoryManager(c7.getMemoryManager());16c7.getMemoryManager()._forceGC();17var c8 = new Packages.com.adobe.flex.extras.controls.springgraph.Graph();18c8.setMemoryManager(new Packages.com.adobe.flex.extras.controls.springgraph.BestFitMemoryManager());19c8.setMemoryManager(c8.getMemoryManager());20c8.getMemoryManager()._forceGC();21var c9 = new Packages.com.adobe.flex.extras.controls.springgraph.Graph();22c9.setMemoryManager(new Packages.com.adobe.flex.extras.controls.springgraph.BestFitMemoryManager());23c9.setMemoryManager(c9.getMemoryManager());24c9.getMemoryManager()._forceGC();

Full Screen

Using AI Code Generation

copy

Full Screen

1var memoryManager = new air.MemoryMonitor();2var bestFitManager = new air.BestFitMemoryManager();3air.MemoryMonitor.memoryManager = bestFitManager;4bestFitManager._forceGC();5var memoryUsage = memoryManager.usedHeapSize;6alert("Memory Usage: " + memoryUsage);

Full Screen

Using AI Code Generation

copy

Full Screen

1var x = new Object();2var y = new Object();3var z = new Object();4x.a = y;5y.a = z;6z.a = x;7var i = 0;8var j = 0;9var k = 0;10var l = 0;11var m = 0;12var n = 0;13var o = 0;14var p = 0;15var q = 0;16var r = 0;17var s = 0;18var t = 0;19var u = 0;20var v = 0;21var w = 0;22var a = 0;23var b = 0;24var c = 0;25var d = 0;26var e = 0;27var f = 0;28var g = 0;29var h = 0;30var a1 = 0;31var b1 = 0;32var c1 = 0;33var d1 = 0;34var e1 = 0;35var f1 = 0;36var g1 = 0;37var h1 = 0;38var a2 = 0;39var b2 = 0;40var c2 = 0;41var d2 = 0;42var e2 = 0;43var f2 = 0;44var g2 = 0;45var h2 = 0;46var a3 = 0;47var b3 = 0;48var c3 = 0;49var d3 = 0;50var e3 = 0;51var f3 = 0;52var g3 = 0;53var h3 = 0;54var a4 = 0;55var b4 = 0;56var c4 = 0;57var d4 = 0;58var e4 = 0;59var f4 = 0;60var g4 = 0;61var h4 = 0;62var a5 = 0;63var b5 = 0;64var c5 = 0;65var d5 = 0;66var e5 = 0;67var f5 = 0;68var g5 = 0;69var h5 = 0;70var a6 = 0;71var b6 = 0;72var c6 = 0;73var d6 = 0;74var e6 = 0;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful