Skip to content

Commit

Permalink
chore: run linter (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanmar511 authored May 25, 2021
1 parent 43c3f0b commit 02bc102
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion system-test/busybench/src/busybench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {writeFile} from 'fs';
// eslint-disable-next-line node/no-extraneous-import
import * as pify from 'pify';
// eslint-disable-next-line node/no-missing-import
// eslint-disable-next-line node/no-extraneous-import
import {encode, heap, SourceMapper, time} from 'pprof';

const writeFilePromise = pify(writeFile);
Expand Down
29 changes: 15 additions & 14 deletions ts/src/profile-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,22 @@ export function serializeHeapProfile(
ignoreSamplesPath?: string,
sourceMapper?: SourceMapper
): perftools.profiles.IProfile {
const appendHeapEntryToSamples: AppendEntryToSamples<AllocationProfileNode> = (
entry: Entry<AllocationProfileNode>,
samples: perftools.profiles.Sample[]
) => {
if (entry.node.allocations.length > 0) {
for (const alloc of entry.node.allocations) {
const sample = new perftools.profiles.Sample({
locationId: entry.stack,
value: [alloc.count, alloc.sizeBytes * alloc.count],
// TODO: add tag for allocation size
});
samples.push(sample);
const appendHeapEntryToSamples: AppendEntryToSamples<AllocationProfileNode> =
(
entry: Entry<AllocationProfileNode>,
samples: perftools.profiles.Sample[]
) => {
if (entry.node.allocations.length > 0) {
for (const alloc of entry.node.allocations) {
const sample = new perftools.profiles.Sample({
locationId: entry.stack,
value: [alloc.count, alloc.sizeBytes * alloc.count],
// TODO: add tag for allocation size
});
samples.push(sample);
}
}
}
};
};

const stringTable = new StringTable();
const sampleValueType = createObjectCountValueType(stringTable);
Expand Down
9 changes: 5 additions & 4 deletions ts/src/sourcemapper/sourcemapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ async function processSourceMap(
// TODO: Resolve the cast of `contents as any` (This is needed because the
// type is expected to be of `RawSourceMap` but the existing
// working code uses a string.)
consumer = ((await new sourceMap.SourceMapConsumer(
(contents as {}) as sourceMap.RawSourceMap
)) as {}) as sourceMap.RawSourceMap;
consumer = (await new sourceMap.SourceMapConsumer(
contents as {} as sourceMap.RawSourceMap
)) as {} as sourceMap.RawSourceMap;
} catch (e) {
throw new Error(
'An error occurred while reading the ' +
Expand Down Expand Up @@ -206,7 +206,8 @@ export class SourceMapper {
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;
const consumer: sourceMap.SourceMapConsumer =
entry.mapConsumer as {} as sourceMap.SourceMapConsumer;

const pos = consumer.originalPositionFor(generatedPos);
if (pos.source === null) {
Expand Down
50 changes: 21 additions & 29 deletions ts/test/profiles-for-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ export const timeProfile: perftools.profiles.IProfile = Object.freeze({

// timeProfile is encoded then decoded to convert numbers to longs, in
// decodedTimeProfile
const encodedTimeProfile = perftools.profiles.Profile.encode(
timeProfile
).finish();
const encodedTimeProfile =
perftools.profiles.Profile.encode(timeProfile).finish();
export const decodedTimeProfile = Object.freeze(
perftools.profiles.Profile.decode(encodedTimeProfile)
);
Expand Down Expand Up @@ -340,9 +339,8 @@ export const heapProfile: perftools.profiles.IProfile = Object.freeze({

// heapProfile is encoded then decoded to convert numbers to longs, in
// decodedHeapProfile
const encodedHeapProfile = perftools.profiles.Profile.encode(
heapProfile
).finish();
const encodedHeapProfile =
perftools.profiles.Profile.encode(heapProfile).finish();
export const decodedHeapProfile = Object.freeze(
perftools.profiles.Profile.decode(encodedHeapProfile)
);
Expand Down Expand Up @@ -396,8 +394,8 @@ const heapLocationsWithExternal = [
new perftools.profiles.Location({line: [heapLinesWithExternal[4]], id: 5}),
];

export const heapProfileWithExternal: perftools.profiles.IProfile = Object.freeze(
{
export const heapProfileWithExternal: perftools.profiles.IProfile =
Object.freeze({
sampleType: [
new perftools.profiles.ValueType({type: 1, unit: 2}),
new perftools.profiles.ValueType({type: 3, unit: 4}),
Expand Down Expand Up @@ -452,14 +450,12 @@ export const heapProfileWithExternal: perftools.profiles.IProfile = Object.freez
timeNanos: 0,
periodType: new perftools.profiles.ValueType({type: 3, unit: 4}),
period: 524288,
}
);
});

// heapProfile is encoded then decoded to convert numbers to longs, in
// decodedHeapProfile
const encodedHeapProfileWithExternal = perftools.profiles.Profile.encode(
heapProfile
).finish();
const encodedHeapProfileWithExternal =
perftools.profiles.Profile.encode(heapProfile).finish();
export const decodedHeapProfileWithExternal = Object.freeze(
perftools.profiles.Profile.decode(encodedHeapProfileWithExternal)
);
Expand Down Expand Up @@ -501,8 +497,8 @@ const anonymousFunctionHeapLocations = [
}),
];

export const anonymousFunctionHeapProfile: perftools.profiles.IProfile = Object.freeze(
{
export const anonymousFunctionHeapProfile: perftools.profiles.IProfile =
Object.freeze({
sampleType: [
new perftools.profiles.ValueType({type: 1, unit: 2}),
new perftools.profiles.ValueType({type: 3, unit: 4}),
Expand All @@ -528,8 +524,7 @@ export const anonymousFunctionHeapProfile: perftools.profiles.IProfile = Object.
timeNanos: 0,
periodType: new perftools.profiles.ValueType({type: 3, unit: 4}),
period: 524288,
}
);
});

const anonymousFunctionTimeNode = {
scriptName: 'main',
Expand Down Expand Up @@ -574,8 +569,8 @@ const anonymousFunctionTimeLocations = [
}),
];

export const anonymousFunctionTimeProfile: perftools.profiles.IProfile = Object.freeze(
{
export const anonymousFunctionTimeProfile: perftools.profiles.IProfile =
Object.freeze({
sampleType: [
new perftools.profiles.ValueType({type: 1, unit: 2}),
new perftools.profiles.ValueType({type: 3, unit: 4}),
Expand All @@ -602,8 +597,7 @@ export const anonymousFunctionTimeProfile: perftools.profiles.IProfile = Object.
durationNanos: 10 * 1000 * 1000 * 1000,
periodType: new perftools.profiles.ValueType({type: 3, unit: 4}),
period: 1000,
}
);
});

const heapWithPathLeaf1 = {
name: 'foo2',
Expand Down Expand Up @@ -721,8 +715,8 @@ const heapIncludePathLocations = [
}),
];

export const heapProfileIncludePath: perftools.profiles.IProfile = Object.freeze(
{
export const heapProfileIncludePath: perftools.profiles.IProfile =
Object.freeze({
sampleType: [
new perftools.profiles.ValueType({type: 1, unit: 2}),
new perftools.profiles.ValueType({type: 3, unit: 4}),
Expand Down Expand Up @@ -764,8 +758,7 @@ export const heapProfileIncludePath: perftools.profiles.IProfile = Object.freeze
timeNanos: 0,
periodType: new perftools.profiles.ValueType({type: 3, unit: 4}),
period: 524288,
}
);
});

// heapProfile is encoded then decoded to convert numbers to longs, in
// decodedHeapProfile
Expand Down Expand Up @@ -802,8 +795,8 @@ const heapExcludePathLocations = [
}),
];

export const heapProfileExcludePath: perftools.profiles.IProfile = Object.freeze(
{
export const heapProfileExcludePath: perftools.profiles.IProfile =
Object.freeze({
sampleType: [
new perftools.profiles.ValueType({type: 1, unit: 2}),
new perftools.profiles.ValueType({type: 3, unit: 4}),
Expand All @@ -830,8 +823,7 @@ export const heapProfileExcludePath: perftools.profiles.IProfile = Object.freeze
timeNanos: 0,
periodType: new perftools.profiles.ValueType({type: 3, unit: 4}),
period: 524288,
}
);
});

// heapProfile is encoded then decoded to convert numbers to longs, in
// decodedHeapProfile
Expand Down

0 comments on commit 02bc102

Please sign in to comment.