Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/profiler

Package Overview
Dependencies
Maintainers
4
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/profiler - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

3

out/src/config.d.ts

@@ -31,2 +31,3 @@ /**

heapMaxStackDepth?: number;
ignoreHeapSamplesPath?: string;
backoffMultiplier?: number;

@@ -55,2 +56,3 @@ initialBackoffMillis?: number;

heapMaxStackDepth: number;
ignoreHeapSamplesPath: string;
initialBackoffMillis: number;

@@ -73,2 +75,3 @@ backoffCapMillis: number;

heapMaxStackDepth: number;
ignoreHeapSamplesPath: string;
initialBackoffMillis: number;

@@ -75,0 +78,0 @@ backoffCapMillis: number;

2

out/src/config.js

@@ -19,3 +19,2 @@ "use strict";

const parseDuration = require('parse-duration');
const extend = require('extend');
// Default values for configuration for a profiler.

@@ -30,2 +29,3 @@ exports.defaultConfig = {

heapMaxStackDepth: 64,
ignoreHeapSamplesPath: '@google-cloud/profiler',
initialBackoffMillis: 60 * 1000,

@@ -32,0 +32,0 @@ backoffCapMillis: parseDuration('1h'),

@@ -16,2 +16,3 @@ /**

*/
import * as consoleLogLevel from 'console-log-level';
import { SemVer } from 'semver';

@@ -48,2 +49,3 @@ import { Config } from './config';

export declare function start(config?: Config): Promise<void>;
export declare function logLevelToName(level?: number): consoleLogLevel.LogLevelNames;
/**

@@ -50,0 +52,0 @@ * For debugging purposes. Collects profiles and discards the collected

@@ -26,4 +26,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@google-cloud/common");
const delay = require("delay");
const consoleLogLevel = require("console-log-level");
const delay_1 = require("delay");
const extend = require("extend");

@@ -57,3 +57,2 @@ const fs = require("fs");

function initConfigLocal(config) {
config = common_1.util.normalizeArguments(null, config);
const envConfig = {

@@ -186,4 +185,22 @@ projectId: process.env.GCLOUD_PROJECT,

exports.start = start;
const LEVEL_NAMES = ['fatal', 'error', 'warn', 'info', 'debug', 'trace'];
function logLevelToName(level) {
if (level === undefined) {
level = config_1.defaultConfig.logLevel;
}
else if (level < 0) {
level = 0;
}
else if (level > 4) {
level = 4;
}
return LEVEL_NAMES[level];
}
exports.logLevelToName = logLevelToName;
function logError(msg, config) {
const logger = new common_1.Logger({ level: common_1.Logger.LEVELS[config.logLevel || 2], tag: pjson.name });
const logger = consoleLogLevel({
stderr: true,
prefix: pjson.name,
level: logLevelToName(config.logLevel)
});
logger.error(msg);

@@ -206,3 +223,7 @@ }

// Set up periodic logging.
const logger = new common_1.Logger({ level: common_1.Logger.LEVELS[profiler.config.logLevel], tag: pjson.name });
const logger = consoleLogLevel({
stderr: true,
prefix: pjson.name,
level: logLevelToName(config.logLevel)
});
let heapProfileCount = 0;

@@ -225,3 +246,3 @@ let timeProfileCount = 0;

}
yield delay(profiler.config.localProfilingPeriodMillis / 2);
yield delay_1.default(profiler.config.localProfilingPeriodMillis / 2);
if (!config.disableTime) {

@@ -228,0 +249,0 @@ const wall = yield profiler.profile({

@@ -27,6 +27,9 @@ "use strict";

const common_1 = require("@google-cloud/common");
const consoleLogLevel = require("console-log-level");
const pify = require("pify");
const msToStr = require("pretty-ms");
const teeny_request_1 = require("teeny-request");
const zlib = require("zlib");
const profile_1 = require("../../proto/profile");
const index_1 = require("./index");
const heapProfiler = require("./profilers/heap-profiler");

@@ -194,3 +197,3 @@ const time_profiler_1 = require("./profilers/time-profiler");

constructor(config) {
config = common_1.util.normalizeArguments(null, config);
config = config || {};
const serviceConfig = {

@@ -200,6 +203,17 @@ baseUrl: config.baseApiUrl,

packageJson: pjson,
// tslint:disable-next-line: no-any
requestModule: teeny_request_1.teenyRequest,
};
super({ parent: new common_1.Service(serviceConfig, config), baseUrl: '/' });
super({
parent: new common_1.Service(serviceConfig, config),
baseUrl: '/',
// tslint:disable-next-line: no-any
requestModule: teeny_request_1.teenyRequest
});
this.config = config;
this.logger = new common_1.Logger({ level: common_1.Logger.LEVELS[config.logLevel], tag: pjson.name });
this.logger = consoleLogLevel({
stderr: true,
prefix: pjson.name,
level: index_1.logLevelToName(this.config.logLevel)
});
const labels = { language: 'nodejs' };

@@ -206,0 +220,0 @@ if (this.config.zone) {

@@ -17,3 +17,3 @@ /**

import { perftools } from '../../../proto/profile';
export declare function profile(): perftools.profiles.IProfile;
export declare function profile(ignoreSamplePath?: string): perftools.profiles.IProfile;
/**

@@ -20,0 +20,0 @@ * Starts heap profiling. If heap profiling has already been started with

@@ -27,3 +27,3 @@ "use strict";

*/
function profile() {
function profile(ignoreSamplePath) {
if (!enabled) {

@@ -39,10 +39,12 @@ throw new Error('Heap profiler is not enabled.');

const { external } = process.memoryUsage();
const externalNode = {
name: '(external)',
scriptName: '',
children: [],
allocations: [{ sizeBytes: external, count: 1 }],
};
result.children.push(externalNode);
return profile_serializer_1.serializeHeapProfile(result, startTimeNanos, heapIntervalBytes);
if (external > 0) {
const externalNode = {
name: '(external)',
scriptName: '',
children: [],
allocations: [{ sizeBytes: external, count: 1 }],
};
result.children.push(externalNode);
}
return profile_serializer_1.serializeHeapProfile(result, startTimeNanos, heapIntervalBytes, ignoreSamplePath);
}

@@ -49,0 +51,0 @@ exports.profile = profile;

@@ -36,2 +36,2 @@ /**

*/
export declare function serializeHeapProfile(prof: AllocationProfileNode, startTimeNanos: number, intervalBytes: number): perftools.profiles.IProfile;
export declare function serializeHeapProfile(prof: AllocationProfileNode, startTimeNanos: number, intervalBytes: number, ignoreSamplesPath?: string): perftools.profiles.IProfile;

@@ -55,3 +55,3 @@ "use strict";

*/
function serialize(profile, root, appendToSamples, stringTable) {
function serialize(profile, root, appendToSamples, stringTable, ignoreSamplesPath) {
const samples = [];

@@ -68,2 +68,5 @@ const locations = [];

const node = entry.node;
if (ignoreSamplesPath && node.scriptName.indexOf(ignoreSamplesPath) > -1) {
continue;
}
const stack = entry.stack;

@@ -198,3 +201,3 @@ const location = getLocation(node);

*/
function serializeHeapProfile(prof, startTimeNanos, intervalBytes) {
function serializeHeapProfile(prof, startTimeNanos, intervalBytes, ignoreSamplesPath) {
const appendHeapEntryToSamples = (entry, samples) => {

@@ -221,3 +224,3 @@ if (entry.node.allocations.length > 0) {

};
serialize(profile, prof, appendHeapEntryToSamples, stringTable);
serialize(profile, prof, appendHeapEntryToSamples, stringTable, ignoreSamplesPath);
return profile;

@@ -224,0 +227,0 @@ }

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const delay = require("delay");
const delay_1 = require("delay");
const profile_serializer_1 = require("./profile-serializer");

@@ -54,3 +54,3 @@ const profiler = require('bindings')('time_profiler');

profiler.startProfiling(runName);
yield delay(durationMillis);
yield delay_1.default(durationMillis);
const result = profiler.stopProfiling(runName);

@@ -57,0 +57,0 @@ // tslint:disable-next-line no-any

{
"name": "@google-cloud/profiler",
"version": "0.2.0",
"description": "Adds support for Google Cloud Profiler to node.js applications",
"version": "0.2.1",
"description": "Adds support for Stackdriver Profiler to node.js applications",
"repository": "GoogleCloudPlatform/cloud-profiler-nodejs",

@@ -10,3 +10,3 @@ "main": "out/src/index.js",

"install": "node-gyp rebuild",
"test": "nyc mocha --require source-map-support/register out/test/test-*.js && nyc --no-clean mocha --require source-map-support/register out/system-test/test-*.js --timeout=60000",
"test": "nyc mocha out/test/test-*.js && nyc --no-clean mocha out/system-test/test-*.js --timeout=60000",
"check": "gts check",

@@ -30,5 +30,6 @@ "clean": "gts clean",

"dependencies": {
"@google-cloud/common": "^0.20.3",
"@google-cloud/common": "^0.23.0",
"bindings": "^1.2.1",
"delay": "^3.0.0",
"console-log-level": "^1.4.0",
"delay": "^3.1.0",
"extend": "^3.0.1",

@@ -38,11 +39,10 @@ "gcp-metadata": "^0.7.0",

"parse-duration": "^0.1.1",
"pify": "^3.0.0",
"pify": "^4.0.0",
"pretty-ms": "^3.1.0",
"protobufjs": "~6.8.6",
"request": "^2.83.0",
"retry-request": "^4.0.0",
"semver": "^5.5.0"
"semver": "^5.5.0",
"teeny-request": "^3.3.0"
},
"devDependencies": {
"@types/delay": "^2.0.0",
"@types/console-log-level": "^1.4.0",
"@types/extend": "^3.0.0",

@@ -55,3 +55,3 @@ "@types/long": "^4.0.0",

"@types/pretty-ms": "^3.0.0",
"@types/request": "^2.0.7",
"@types/request": "^2.47.1",
"@types/semver": "^5.5.0",

@@ -62,10 +62,11 @@ "@types/sinon": "^5.0.1",

"gts": "^0.8.0",
"intelli-espower-loader": "^1.0.1",
"js-green-licenses": "^0.5.0",
"mocha": "^5.0.0",
"nock": "^9.0.22",
"nyc": "^12.0.2",
"nyc": "^13.0.0",
"sinon": "^6.0.0",
"source-map-support": "^0.5.0",
"source-map-support": "^0.5.6",
"ts-mockito": "^2.2.5",
"typescript": "~2.9.0"
"typescript": "~3.0.0"
},

@@ -72,0 +73,0 @@ "files": [

# Google Cloud Profiler
[![Greenkeeper badge](https://badges.greenkeeper.io/GoogleCloudPlatform/cloud-profiler-nodejs.svg)](https://greenkeeper.io/)
[![NPM Version][npm-image]][npm-url]
[![Build Status][circle-image]][circle-url]
[![Dependency Status][david-image]][david-url]

@@ -9,5 +9,5 @@ [![devDependency Status][david-dev-image]][david-dev-url]

> **Alpha**. *This is an Alpha release of Stackdriver Profiler Node.js
profiling agent. This feature might be changed in backward-incompatible ways
and is not recommended for production use. It is not subject to any SLA or
> **Alpha**. *This is an Alpha release of Stackdriver Profiler Node.js
profiling agent. This feature might be changed in backward-incompatible ways
and is not recommended for production use. It is not subject to any SLA or
deprecation policy.*

@@ -33,3 +33,3 @@

1. You will need a project in the [Google Developers Console][cloud-console].
1. You will need a project in the [Google Developers Console][cloud-console].
Your application can run anywhere, but the profiler data is associated with a

@@ -41,3 +41,3 @@ particular project.

1. Install `@google-cloud/profiler` with [`npm`](https://www.npmjs.com) or add
1. Install `@google-cloud/profiler` with [`npm`](https://www.npmjs.com) or add
to your [`package.json`](https://docs.npmjs.com/files/package.json#dependencies).

@@ -51,3 +51,3 @@

2. Include and start the profiler at the beginning of your application:
```js

@@ -57,11 +57,11 @@ var profiler = require('@google-cloud/profiler').start();

Some environments require a configuration to be passed to the `start()`
function. For more details on this, see instructions for running
[outside of Google Cloud Platform](#running-elsewhere), on
[App Engine flexible environment](#running-on-app-engine-flexible-environment),
on [Google Compute Engine](#running-on-google-compute-engine),
and on [Google Container Engine](#running-on-google-container-engine).
Some environments require a configuration to be passed to the `start()`
function. For more details on this, see instructions for running
[outside of Google Cloud Platform](#running-elsewhere), on
[App Engine flexible environment](#running-on-app-engine-flexible-environment),
on [Google Compute Engine](#running-on-google-compute-engine),
and on [Google Container Engine](#running-on-google-container-engine).
3. If you are running your application locally, or on a machine where you are
using the [Google Cloud SDK][gcloud-sdk], make sure to log in with the
3. If you are running your application locally, or on a machine where you are
using the [Google Cloud SDK][gcloud-sdk], make sure to log in with the
application default credentials:

@@ -72,4 +72,4 @@

```
Alternatively, you can set `GOOGLE_APPLICATION_CREDENTIALS`. For more
Alternatively, you can set `GOOGLE_APPLICATION_CREDENTIALS`. For more
details on this, see [Running elsewhere](#running-elsewhere)

@@ -79,4 +79,4 @@

See [the default configuration](ts/src/config.ts) for a list of possible
configuration options. These options can be passed to the agent through the
See [the default configuration](ts/src/config.ts) for a list of possible
configuration options. These options can be passed to the agent through the
object argument to the start command shown below:

@@ -88,7 +88,7 @@

Alternatively, you can provide the configuration through a config file. This
can be useful if you want to load our module using `--require` on the command
line (which requires and starts the agent) instead of editing your main script.
The `GCLOUD_PROFILER_CONFIG` environment variable should point to your
configuration file.
Alternatively, you can provide the configuration through a config file. This
can be useful if you want to load our module using `--require` on the command
line (which requires and starts the agent) instead of editing your main script.
The `GCLOUD_PROFILER_CONFIG` environment variable should point to your
configuration file.

@@ -101,9 +101,9 @@ ```bash

The profiler writes log statements to the console log for diagnostic purposes.
By default, the log level is set to warn. You can adjust this by setting
`logLevel` in the config. Setting `logLevel` to 0 will disable logging, 1 sets
log level to error, 2 sets it to warn, 3 sets it to info, and 4 sets it to
debug.
The profiler writes log statements to the console log for diagnostic purposes.
By default, the log level is set to warn. You can adjust this by setting
`logLevel` in the config. Setting `logLevel` to 0 will disable logging, 1 sets
log level to error, 2 sets it to warn, 3 sets it to info, and 4 sets it to
debug.
So, for example, to start the profiler with the log level at debug, you would
So, for example, to start the profiler with the log level at debug, you would
do this:

@@ -117,5 +117,5 @@

By default, the profiler collects both heap profiles, which show memory
allocations, and time profiles, which capture how much wall-clock time is spent
in different locations of the code. Using the configuration, it is possible to
By default, the profiler collects both heap profiles, which show memory
allocations, and time profiles, which capture how much wall-clock time is spent
in different locations of the code. Using the configuration, it is possible to
disable the collection of either type of profile.

@@ -135,9 +135,9 @@

## Running on Google Cloud Platform
## Running on Google Cloud Platform
There are three different services that can host Node.js applications within
Google Cloud Platform: Google App Engine flexible environment, Google Compute
Engine, and Google Container Engine. After installing `@google-cloud/profiler`
in your project and ensuring that the environment you are using uses Node.js
version 6.12.3 or greater, or Node.js 8.9.4 or greater, follow the
There are three different services that can host Node.js applications within
Google Cloud Platform: Google App Engine flexible environment, Google Compute
Engine, and Google Container Engine. After installing `@google-cloud/profiler`
in your project and ensuring that the environment you are using uses Node.js
version 6.12.3 or greater, or Node.js 8.9.4 or greater, follow the
service-specific instructions to enable the profiler.

@@ -147,4 +147,4 @@

To enable the profiling agent for a Node.js program running in the App Engine
flexible environment, import the agent at the top of your application’s main
To enable the profiling agent for a Node.js program running in the App Engine
flexible environment, import the agent at the top of your application’s main
script or entry point by including the following code snippet:

@@ -156,3 +156,3 @@

You can specify which version of Node.js you're using by adding a snippet like
You can specify which version of Node.js you're using by adding a snippet like
the following to your `package.json`:

@@ -171,4 +171,4 @@

To enable the profiling agent for a Node.js program running in the Google
Compute Engine environment, import the agent at the top of your application’s
To enable the profiling agent for a Node.js program running in the Google
Compute Engine environment, import the agent at the top of your application’s
main script or entry point by including the following code snippet:

@@ -194,4 +194,4 @@

To enable the profiling agent for a Node.js program running in the Google
Container Engine environment, import the agent at the top of your application’s
To enable the profiling agent for a Node.js program running in the Google
Container Engine environment, import the agent at the top of your application’s
main script or entry point by including the following code snippet:

@@ -208,12 +208,12 @@

You may also need to add `build-essential` to your environment.
You may also need to add `build-essential` to your environment.
## Running elsewhere
You can still use `@google-cloud/profiler` if your application is running
outside of Google Cloud Platform, for example, running locally, on-premise, or
on another cloud provider.
You can still use `@google-cloud/profiler` if your application is running
outside of Google Cloud Platform, for example, running locally, on-premise, or
on another cloud provider.
1. You will need to specify your project id and the service you want the
collected profiles to be associated with, and (optionally) the version of
1. You will need to specify your project id and the service you want the
collected profiles to be associated with, and (optionally) the version of
the service when starting the profiler:

@@ -230,25 +230,25 @@

```
2. You will need to provide credential for your application.
* If you are running your application on a development machine or test
2. You will need to provide credential for your application.
* If you are running your application on a development machine or test
environment where you are using the [`gcloud` command line tools][gcloud-sdk],
and are logged using `gcloud beta auth application-default login`, you
already have sufficient credentials, and a service account key is not
and are logged using `gcloud beta auth application-default login`, you
already have sufficient credentials, and a service account key is not
required.
* You can provide credentials via
[Application Default Credentials][app-default-credentials]. This is the
* You can provide credentials via
[Application Default Credentials][app-default-credentials]. This is the
reccomended method.
1. [Create a new JSON service account key][service-account].
2. Copy the key somewhere your application can access it. Be sure not
2. Copy the key somewhere your application can access it. Be sure not
to expose the key publicly.
3. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to
the full path to the key. The profiler will automatically look for
3. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to
the full path to the key. The profiler will automatically look for
this environment variable.
* You may set the `keyFilename` or `credentials` configuration field to the
full path or contents to the key file, respectively. Setting either of these
fields will override either setting `GOOGLE_APPLICATION_CREDENTIALS` or
logging in using `gcloud`.
* You may set the `keyFilename` or `credentials` configuration field to the
full path or contents to the key file, respectively. Setting either of these
fields will override either setting `GOOGLE_APPLICATION_CREDENTIALS` or
logging in using `gcloud`.
This is how you would set `keyFilename`:

@@ -280,3 +280,5 @@ ```js

```
[app-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials
[app-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials
[circle-image]: https://circleci.com/gh/GoogleCloudPlatform/cloud-profiler-nodejs.svg?style=svg
[circle-url]: https://circleci.com/gh/GoogleCloudPlatform/cloud-profiler-nodejs
[cloud-console]: https://console.cloud.google.com

@@ -283,0 +285,0 @@ [coveralls-image]: https://coveralls.io/repos/GoogleCloudPlatform/cloud-profiler-nodejs/badge.svg?branch=master&service=github

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc