diff options
Diffstat (limited to 'node_modules/chrome-trace-event')
| -rw-r--r-- | node_modules/chrome-trace-event/CHANGES.md | 26 | ||||
| -rw-r--r-- | node_modules/chrome-trace-event/LICENSE.txt | 23 | ||||
| -rw-r--r-- | node_modules/chrome-trace-event/README.md | 31 | ||||
| -rw-r--r-- | node_modules/chrome-trace-event/dist/trace-event.d.ts | 52 | ||||
| -rw-r--r-- | node_modules/chrome-trace-event/dist/trace-event.js | 170 | ||||
| -rw-r--r-- | node_modules/chrome-trace-event/package.json | 38 |
6 files changed, 340 insertions, 0 deletions
diff --git a/node_modules/chrome-trace-event/CHANGES.md b/node_modules/chrome-trace-event/CHANGES.md new file mode 100644 index 00000000..889d7de4 --- /dev/null +++ b/node_modules/chrome-trace-event/CHANGES.md @@ -0,0 +1,26 @@ +# node-trace-event changelog + +## 1.3.1 (not yet released) + +(nothing yet) + + +## 1.3.0 + +- Add `.child(<fields>)` option to `trace_event.createBunyanTracer()` object. + + +## 1.2.0 + +- Add `trace_event.createBunyanLogger()` usage for some sugar. See the + README.md for details. + + +## 1.1.0 + +- Rename to 'trace-event', which is a much more accurate name. + + +## 1.0.0 + +First release. diff --git a/node_modules/chrome-trace-event/LICENSE.txt b/node_modules/chrome-trace-event/LICENSE.txt new file mode 100644 index 00000000..427a1364 --- /dev/null +++ b/node_modules/chrome-trace-event/LICENSE.txt @@ -0,0 +1,23 @@ +# This is the MIT license + +Copyright (c) 2015 Joyent Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/node_modules/chrome-trace-event/README.md b/node_modules/chrome-trace-event/README.md new file mode 100644 index 00000000..8bd20774 --- /dev/null +++ b/node_modules/chrome-trace-event/README.md @@ -0,0 +1,31 @@ +[](https://travis-ci.org/samccone/chrome-trace-event) + +chrome-trace-event: A node library for creating trace event logs of program +execution according to [Google's Trace Event +format](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU). +These logs can then be visualized with +[trace-viewer](https://github.com/google/trace-viewer) or chrome devtools to grok one's programs. + +# Install + + npm install chrome-trace-event + +# Usage + +```javascript +const Trace = require("chrome-trace-event").Tracer; +const trace = new Trace({ + noStream: true +}); +trace.pipe(fs.createWriteStream(outPath)); +trace.flush(); +``` + +# Links + +* https://github.com/google/trace-viewer/wiki +* https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU + +# License + +MIT. See LICENSE.txt. diff --git a/node_modules/chrome-trace-event/dist/trace-event.d.ts b/node_modules/chrome-trace-event/dist/trace-event.d.ts new file mode 100644 index 00000000..f68cd376 --- /dev/null +++ b/node_modules/chrome-trace-event/dist/trace-event.d.ts @@ -0,0 +1,52 @@ +/** + * trace-event - A library to create a trace of your node app per + * Google's Trace Event format: + * // JSSTYLED + * https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU + */ +/// <reference types="node" /> +import { Readable as ReadableStream } from "stream"; +export interface Event { + ts: number; + pid: number; + tid: number; + /** event phase */ + ph?: string; + [otherData: string]: any; +} +export interface Fields { + cat?: any; + args?: any; + [filedName: string]: any; +} +export interface TracerOptions { + parent?: Tracer | null; + fields?: Fields | null; + objectMode?: boolean | null; + noStream?: boolean; +} +export declare class Tracer extends ReadableStream { + private _objectMode; + /** Node Stream internal APIs */ + private _push; + private firstPush?; + private noStream; + private events; + private parent; + private fields; + constructor(opts?: TracerOptions); + /** + * If in no streamMode in order to flush out the trace + * you need to call flush. + */ + flush(): void; + _read(_: number): void; + private _pushString; + private _flush; + child(fields: Fields): Tracer; + begin(fields: Fields): void; + end(fields: Fields): void; + completeEvent(fields: Fields): void; + instantEvent(fields: Fields): void; + mkEventFunc(ph: string): (fields: Fields) => void; +} diff --git a/node_modules/chrome-trace-event/dist/trace-event.js b/node_modules/chrome-trace-event/dist/trace-event.js new file mode 100644 index 00000000..d8cfc673 --- /dev/null +++ b/node_modules/chrome-trace-event/dist/trace-event.js @@ -0,0 +1,170 @@ +"use strict"; +/** + * trace-event - A library to create a trace of your node app per + * Google's Trace Event format: + * // JSSTYLED + * https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Tracer = void 0; +const stream_1 = require("stream"); +function evCommon() { + var hrtime = process.hrtime(); // [seconds, nanoseconds] + var ts = hrtime[0] * 1000000 + Math.round(hrtime[1] / 1000); // microseconds + return { + ts, + pid: process.pid, + tid: process.pid // no meaningful tid for node.js + }; +} +class Tracer extends stream_1.Readable { + constructor(opts = {}) { + super(); + this.noStream = false; + this.events = []; + if (typeof opts !== "object") { + throw new Error("Invalid options passed (must be an object)"); + } + if (opts.parent != null && typeof opts.parent !== "object") { + throw new Error("Invalid option (parent) passed (must be an object)"); + } + if (opts.fields != null && typeof opts.fields !== "object") { + throw new Error("Invalid option (fields) passed (must be an object)"); + } + if (opts.objectMode != null && + (opts.objectMode !== true && opts.objectMode !== false)) { + throw new Error("Invalid option (objectsMode) passed (must be a boolean)"); + } + this.noStream = opts.noStream || false; + this.parent = opts.parent; + if (this.parent) { + this.fields = Object.assign({}, opts.parent && opts.parent.fields); + } + else { + this.fields = {}; + } + if (opts.fields) { + Object.assign(this.fields, opts.fields); + } + if (!this.fields.cat) { + // trace-viewer *requires* `cat`, so let's have a fallback. + this.fields.cat = "default"; + } + else if (Array.isArray(this.fields.cat)) { + this.fields.cat = this.fields.cat.join(","); + } + if (!this.fields.args) { + // trace-viewer *requires* `args`, so let's have a fallback. + this.fields.args = {}; + } + if (this.parent) { + // TODO: Not calling Readable ctor here. Does that cause probs? + // Probably if trying to pipe from the child. + // Might want a serpate TracerChild class for these guys. + this._push = this.parent._push.bind(this.parent); + } + else { + this._objectMode = Boolean(opts.objectMode); + var streamOpts = { objectMode: this._objectMode }; + if (this._objectMode) { + this._push = this.push; + } + else { + this._push = this._pushString; + streamOpts.encoding = "utf8"; + } + stream_1.Readable.call(this, streamOpts); + } + } + /** + * If in no streamMode in order to flush out the trace + * you need to call flush. + */ + flush() { + if (this.noStream === true) { + for (const evt of this.events) { + this._push(evt); + } + this._flush(); + } + } + _read(_) { } + _pushString(ev) { + var separator = ""; + if (!this.firstPush) { + this.push("["); + this.firstPush = true; + } + else { + separator = ",\n"; + } + this.push(separator + JSON.stringify(ev), "utf8"); + } + _flush() { + if (!this._objectMode) { + this.push("]"); + } + } + child(fields) { + return new Tracer({ + parent: this, + fields: fields + }); + } + begin(fields) { + return this.mkEventFunc("B")(fields); + } + end(fields) { + return this.mkEventFunc("E")(fields); + } + completeEvent(fields) { + return this.mkEventFunc("X")(fields); + } + instantEvent(fields) { + return this.mkEventFunc("I")(fields); + } + mkEventFunc(ph) { + return (fields) => { + var ev = evCommon(); + // Assign the event phase. + ev.ph = ph; + if (fields) { + if (typeof fields === "string") { + ev.name = fields; + } + else { + for (const k of Object.keys(fields)) { + if (k === "cat") { + ev.cat = fields.cat.join(","); + } + else { + ev[k] = fields[k]; + } + } + } + } + if (!this.noStream) { + this._push(ev); + } + else { + this.events.push(ev); + } + }; + } +} +exports.Tracer = Tracer; +/* + * These correspond to the "Async events" in the Trace Events doc. + * + * Required fields: + * - name + * - id + * + * Optional fields: + * - cat (array) + * - args (object) + * - TODO: stack fields, other optional fields? + * + * Dev Note: We don't explicitly assert that correct fields are + * used for speed (premature optimization alert!). + */ diff --git a/node_modules/chrome-trace-event/package.json b/node_modules/chrome-trace-event/package.json new file mode 100644 index 00000000..1540952d --- /dev/null +++ b/node_modules/chrome-trace-event/package.json @@ -0,0 +1,38 @@ +{ + "name": "chrome-trace-event", + "description": "A library to create a trace of your node app per Google's Trace Event format.", + "license": "MIT", + "version": "1.0.4", + "author": "Trent Mick, Sam Saccone", + "keywords": [ + "trace-event", + "trace", + "event", + "trace-viewer", + "google" + ], + "repository": { + "url": "github:samccone/chrome-trace-event" + }, + "main": "./dist/trace-event.js", + "typings": "./dist/trace-event.d.ts", + "dependencies": {}, + "devDependencies": { + "@types/node": "*", + "prettier": "^1.12.1", + "tape": "4.8.0", + "typescript": "^4.2.4" + }, + "engines": { + "node": ">=6.0" + }, + "files": [ + "dist", + "CHANGES.md" + ], + "scripts": { + "build": "tsc", + "check_format": "prettier -l lib/** test/** examples/**", + "test": "tape test/*.test.js" + } +} |
