Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules
**/coverage
build/
proto/
out/
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts"
}
18 changes: 18 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 Google LLC
//
// 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
//
// https://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.

module.exports = {
endOfLine:"auto",
...require('gts/.prettierrc.json')
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@types/tmp": "0.2.0",
"codecov": "^3.0.0",
"deep-copy": "^1.4.2",
"gts": "^1.0.0",
"gts": "^3.0.0",
"js-green-licenses": "^2.0.0",
"linkinator": "^2.0.0",
"mocha": "^8.0.0",
Expand Down
21 changes: 16 additions & 5 deletions system-test/busybench-js/src/busybench.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

const fs = require('fs');
// eslint-disable-next-line node/no-extraneous-require
Comment thread
macieksmuga marked this conversation as resolved.
const pify = require('pify');
// eslint-disable-next-line node/no-missing-require
Comment thread
macieksmuga marked this conversation as resolved.
const pprof = require('pprof');

const writeFilePromise = pify(fs.writeFile);
Expand Down Expand Up @@ -46,8 +48,11 @@ function benchmark(durationSeconds) {
busyLoop(durationSeconds);
}

async function collectAndSaveTimeProfile(durationSeconds, sourceMapper,
lineNumbers) {
async function collectAndSaveTimeProfile(
durationSeconds,
sourceMapper,
lineNumbers
) {
const profile = await pprof.time.profile({
durationMillis: 1000 * durationSeconds,
lineNumbers: lineNumbers,
Expand All @@ -64,13 +69,19 @@ async function collectAndSaveHeapProfile(sourceMapper) {
}

async function collectAndSaveProfiles(collectLineNumberTimeProfile) {
const sourceMapper = await pprof.SourceMapper.create([process.cwd()]);
const sourceMapper = await pprof.SourceMapper.create([process.cwd()]);
collectAndSaveHeapProfile(sourceMapper);
collectAndSaveTimeProfile(durationSeconds/2, sourceMapper, collectLineNumberTimeProfile);
collectAndSaveTimeProfile(
durationSeconds / 2,
sourceMapper,
collectLineNumberTimeProfile
);
}

const durationSeconds = Number(process.argv.length > 2 ? process.argv[2] : 30);
const collectLineNumberTimeProfile = Boolean(process.argv.length > 3 ? process.argv[3] : false);
const collectLineNumberTimeProfile = Boolean(
process.argv.length > 3 ? process.argv[3] : false
);

pprof.heap.start(512 * 1024, 64);
benchmark(durationSeconds);
Expand Down
17 changes: 12 additions & 5 deletions system-test/busybench/src/busybench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

import {writeFile} from 'fs';
// eslint-disable-next-line node/no-extraneous-import
Comment thread
macieksmuga marked this conversation as resolved.
import * as pify from 'pify';
// eslint-disable-next-line node/no-missing-import
import {encode, heap, SourceMapper, time} from 'pprof';

const writeFilePromise = pify(writeFile);
Expand Down Expand Up @@ -47,15 +49,20 @@ function benchmark(durationSeconds: number) {
}

async function collectAndSaveTimeProfile(
durationSeconds: number, sourceMapper: SourceMapper): Promise<void> {
const profile = await time.profile(
{durationMillis: 1000 * durationSeconds, sourceMapper});
durationSeconds: number,
sourceMapper: SourceMapper
): Promise<void> {
const profile = await time.profile({
durationMillis: 1000 * durationSeconds,
sourceMapper,
});
const buf = await encode(profile);
await writeFilePromise('time.pb.gz', buf);
}

async function collectAndSaveHeapProfile(sourceMapper: SourceMapper):
Promise<void> {
async function collectAndSaveHeapProfile(
sourceMapper: SourceMapper
): Promise<void> {
const profile = await heap.profile(undefined, sourceMapper);
const buf = await encode(profile);
await writeFilePromise('heap.pb.gz', buf);
Expand Down
2 changes: 1 addition & 1 deletion ts/src/heap-profiler-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as path from 'path';

import { AllocationProfileNode } from './v8-types';
import {AllocationProfileNode} from './v8-types';

const binary = require('node-pre-gyp');
const bindingPath = binary.find(
Expand Down
14 changes: 7 additions & 7 deletions ts/src/heap-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

import { perftools } from '../../proto/profile';
import {perftools} from '../../proto/profile';

import {
getAllocationProfile,
startSamplingHeapProfiler,
stopSamplingHeapProfiler,
} from './heap-profiler-bindings';
import { serializeHeapProfile } from './profile-serializer';
import { SourceMapper } from './sourcemapper/sourcemapper';
import { AllocationProfileNode } from './v8-types';
import {serializeHeapProfile} from './profile-serializer';
import {SourceMapper} from './sourcemapper/sourcemapper';
import {AllocationProfileNode} from './v8-types';

let enabled = false;
let heapIntervalBytes = 0;
Expand Down Expand Up @@ -58,14 +58,14 @@ export function profile(
// Add node for external memory usage.
// Current type definitions do not have external.
// TODO: remove any once type definition is updated to include external.
// tslint:disable-next-line: no-any
const { external }: { external: number } = process.memoryUsage() as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const {external}: {external: number} = process.memoryUsage() as any;
if (external > 0) {
const externalNode: AllocationProfileNode = {
name: '(external)',
scriptName: '',
children: [],
allocations: [{ sizeBytes: external, count: 1 }],
allocations: [{sizeBytes: external, count: 1}],
};
result.children.push(externalNode);
}
Expand Down
14 changes: 5 additions & 9 deletions ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { writeFileSync } from 'fs';
import {writeFileSync} from 'fs';

import * as heapProfiler from './heap-profiler';
import { encodeSync } from './profile-encoder';
import {encodeSync} from './profile-encoder';
import * as timeProfiler from './time-profiler';
export {
AllocationProfileNode,
TimeProfileNode,
ProfileNode,
} from './v8-types';
export {AllocationProfileNode, TimeProfileNode, ProfileNode} from './v8-types';

export { encode, encodeSync } from './profile-encoder';
export { SourceMapper } from './sourcemapper/sourcemapper';
export {encode, encodeSync} from './profile-encoder';
export {SourceMapper} from './sourcemapper/sourcemapper';

export const time = {
profile: timeProfiler.profile,
Expand Down
4 changes: 2 additions & 2 deletions ts/src/profile-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import * as pify from 'pify';
import { gzip, gzipSync } from 'zlib';
import {gzip, gzipSync} from 'zlib';

import { perftools } from '../../proto/profile';
import {perftools} from '../../proto/profile';

const gzipPromise = pify(gzip);

Expand Down
8 changes: 3 additions & 5 deletions ts/src/profile-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { perftools } from '../../proto/profile';
import {perftools} from '../../proto/profile';
import {
GeneratedLocation,
SourceLocation,
Expand Down Expand Up @@ -111,8 +111,6 @@ function serialize<T extends ProfileNode>(
const samples: perftools.profiles.Sample[] = [];
const locations: perftools.profiles.Location[] = [];
const functions: perftools.profiles.Function[] = [];
const locationMap: Map<number, perftools.profiles.Location> = new Map();
const functionMap: Map<number, perftools.profiles.Function> = new Map();
Comment thread
nolanmar511 marked this conversation as resolved.
const functionIdMap = new Map<string, number>();
const locationIdMap = new Map<string, number>();

Expand All @@ -131,7 +129,7 @@ function serialize<T extends ProfileNode>(
stack.unshift(location.id as number);
appendToSamples(entry, samples);
for (const child of node.children as T[]) {
entries.push({ node: child, stack: stack.slice() });
entries.push({node: child, stack: stack.slice()});
}
}

Expand Down Expand Up @@ -170,7 +168,7 @@ function serialize<T extends ProfileNode>(
profLoc.name,
profLoc.line
);
const location = new perftools.profiles.Location({ id, line: [line] });
const location = new perftools.profiles.Location({id, line: [line]});
locations.push(location);
return location;
}
Expand Down
4 changes: 2 additions & 2 deletions ts/src/sourcemapper/sourcemapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function processSourceMap(
: path.basename(mapPath, MAP_EXT);
const generatedPath = path.resolve(dir, generatedBase);

infoMap.set(generatedPath, { mapFileDir: dir, mapConsumer: consumer });
infoMap.set(generatedPath, {mapFileDir: dir, mapConsumer: consumer});
}

export class SourceMapper {
Expand Down Expand Up @@ -203,7 +203,7 @@ export class SourceMapper {
return location;
}

const generatedPos = { line: location.line, column: location.column };
const generatedPos = {line: location.line, column: location.column};

// TODO: Determine how to remove the explicit cast here.
const consumer: sourceMap.SourceMapConsumer = (entry.mapConsumer as {}) as sourceMap.SourceMapConsumer;
Expand Down
2 changes: 1 addition & 1 deletion ts/src/time-profiler-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as path from 'path';
import { TimeProfile } from './v8-types';
import {TimeProfile} from './v8-types';

const binary = require('node-pre-gyp');
const bindingPath = binary.find(
Expand Down
8 changes: 4 additions & 4 deletions ts/src/time-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import delay from 'delay';

import { serializeTimeProfile } from './profile-serializer';
import { SourceMapper } from './sourcemapper/sourcemapper';
import {serializeTimeProfile} from './profile-serializer';
import {SourceMapper} from './sourcemapper/sourcemapper';
import {
setSamplingInterval,
startProfiling,
Expand Down Expand Up @@ -77,13 +77,13 @@ export function start(
// code. Ideally this should be default behavior. Until then, use the
// undocumented API.
// See https://github.com/nodejs/node/issues/19009#issuecomment-403161559.
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(process as any)._startProfilerIdleNotifier();
startProfiling(runName, lineNumbers);
return function stop() {
profiling = false;
const result = stopProfiling(runName, lineNumbers);
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(process as any)._stopProfilerIdleNotifier();
const profile = serializeTimeProfile(result, intervalMicros, sourceMapper);
return profile;
Expand Down
Loading