Skip to content

Commit

Permalink
Save profiles when running startLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanmar511 committed Jan 3, 2018
1 parent f2f0cb9 commit a54f748
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

import * as delay from 'delay';
import * as extend from 'extend';
import * as fs from 'fs';
import * as gcpMetadata from 'gcp-metadata';
import * as path from 'path';
import {normalize} from 'path';
import * as pify from 'pify';
import * as zlib from 'zlib';

import {perftools} from '../../proto/profile';
import {AuthenticationConfig, Common, ServiceConfig} from '../third_party/types/common-types';

import {Config, defaultConfig, ProfilerConfig} from './config';
Expand Down Expand Up @@ -148,13 +151,27 @@ export async function startLocal(config: Config = {}): Promise<void> {
if (!config.disableHeap) {
const heap = await profiler.profile(
{name: 'HEAP-Profile' + new Date(), profileType: 'HEAP'});
const decodedBytes = Buffer.from(heap.profileBytes as 'string', 'base64');
fs.writeFile(
`${heap.name.replace(/(\s|:)/g, '')}.pb.gz`, decodedBytes, (err) => {
if (err) {
console.log(err);
}
});
}
if (!config.disableTime) {
const wall = await profiler.profile({
name: 'Time-Profile' + new Date(),
profileType: 'WALL',
duration: '10s'
});
const decodedBytes = Buffer.from(wall.profileBytes as 'string', 'base64');
fs.writeFile(
`${wall.name.replace(/(\s|:)/g, '')}.pb.gz`, decodedBytes, (err) => {
if (err) {
console.log(err);
}
});
}
await delay(1000);
}
Expand Down

0 comments on commit a54f748

Please sign in to comment.