larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

View File

@@ -0,0 +1,38 @@
/// <reference types="node" />
import type { Session } from "inspector";
export type Profile = {
nodes: Array<ProfileNode>;
startTime: number;
endTime: number;
samples?: Array<number>;
timeDeltas?: Array<number>;
};
type ProfileNode = {
id: number;
callFrame: CallFrame;
hitCount?: number;
children?: Array<number>;
deoptReason?: string;
positionTicks?: PositionTickInfo;
};
type CallFrame = {
functionName: string;
scriptId: string;
url: string;
lineNumber: string;
columnNumber: string;
};
type PositionTickInfo = {
line: number;
ticks: number;
};
export default class SamplingProfiler {
session: Session;
startProfiling(): Promise<unknown>;
sendCommand(method: string, params?: unknown): Promise<{
profile: Profile;
}>;
destroy(): void;
stopProfiling(): Promise<Profile>;
}
export {};

View File

@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _assert() {
const data = _interopRequireDefault(require("assert"));
_assert = function () {
return data;
};
return data;
}
function _diagnostic() {
const data = _interopRequireDefault(require("@parcel/diagnostic"));
_diagnostic = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
class SamplingProfiler {
startProfiling() {
let inspector;
try {
inspector = require('inspector');
} catch (err) {
throw new (_diagnostic().default)({
diagnostic: {
message: `The inspector module isn't available`,
origin: '@parcel/workers',
hints: ['Disable build profiling']
}
});
}
this.session = new inspector.Session();
this.session.connect();
return Promise.all([this.sendCommand('Profiler.setSamplingInterval', {
interval: 100
}), this.sendCommand('Profiler.enable'), this.sendCommand('Profiler.start')]);
}
sendCommand(method, params) {
(0, _assert().default)(this.session != null);
return new Promise((resolve, reject) => {
this.session.post(method, params, (err, p) => {
if (err == null) {
resolve(p);
} else {
reject(err);
}
});
});
}
destroy() {
if (this.session != null) {
this.session.disconnect();
}
}
async stopProfiling() {
let res = await this.sendCommand('Profiler.stop');
this.destroy();
return res.profile;
}
}
exports.default = SamplingProfiler;

View File

@@ -0,0 +1,15 @@
/// <reference types="node" />
import type { Profile } from "./SamplingProfiler";
import type { Writable } from "stream";
import { Tracer } from "chrome-trace-event";
export default class Trace {
tracer: Tracer;
tid: number;
eventId: number;
constructor();
getEventId(): number;
init(ts: number): void;
addCPUProfile(name: string, profile: Profile): void;
pipe(writable: Writable): Writable;
flush(): void;
}

View File

@@ -0,0 +1,119 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _chromeTraceEvent() {
const data = require("chrome-trace-event");
_chromeTraceEvent = function () {
return data;
};
return data;
}
class Trace {
constructor() {
this.tracer = new (_chromeTraceEvent().Tracer)();
this.tid = 0;
this.eventId = 0;
}
getEventId() {
return this.eventId++;
}
init(ts) {
this.tracer.instantEvent({
name: 'TracingStartedInPage',
id: this.getEventId(),
ts,
cat: ['disabled-by-default-devtools.timeline'],
args: {
data: {
sessionId: '-1',
page: '0xfff',
frames: [{
frame: '0xfff',
url: 'parcel',
name: ''
}]
}
}
});
this.tracer.instantEvent({
name: 'TracingStartedInBrowser',
id: this.getEventId(),
ts,
cat: ['disabled-by-default-devtools.timeline'],
args: {
data: {
sessionId: '-1'
}
}
});
}
addCPUProfile(name, profile) {
if (this.eventId === 0) {
this.init(profile.startTime);
}
const trace = this.tracer;
const tid = this.tid;
this.tid++;
const cpuStartTime = profile.startTime;
const cpuEndTime = profile.endTime;
trace.instantEvent({
tid,
id: this.getEventId(),
cat: ['toplevel'],
name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
args: {
src_file: '../../ipc/ipc_moji_bootstrap.cc',
src_func: 'Accept'
},
ts: cpuStartTime
});
trace.completeEvent({
tid,
name: 'EvaluateScript',
id: this.getEventId(),
cat: ['devtools.timeline'],
ts: cpuStartTime,
dur: cpuEndTime - cpuStartTime,
args: {
data: {
url: 'parcel',
lineNumber: 1,
columnNumber: 1,
frame: '0xFFF'
}
}
});
trace.instantEvent({
tid,
ts: 0,
ph: 'M',
cat: ['__metadata'],
name: 'thread_name',
args: {
name
}
});
trace.instantEvent({
tid,
name: 'CpuProfile',
id: this.getEventId(),
cat: ['disabled-by-default-devtools.timeline'],
ts: cpuEndTime,
args: {
data: {
cpuProfile: profile
}
}
});
}
pipe(writable) {
return this.tracer.pipe(writable);
}
flush() {
this.tracer.push(null);
}
}
exports.default = Trace;

View File

@@ -0,0 +1,28 @@
import type { TraceEvent, IDisposable, PluginTracer as IPluginTracer } from "@parcel/types";
import type { TraceMeasurement as ITraceMeasurement } from "./types";
export default class Tracer {
onTrace(cb: (event: TraceEvent) => unknown): IDisposable;
wrap(name: string, fn: () => unknown): Promise<void>;
createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?: Record<string, unknown>): ITraceMeasurement | null;
get enabled(): boolean;
enable(): void;
disable(): void;
trace(event: TraceEvent): void;
}
export declare const tracer: Tracer;
type TracerOpts = {
origin: string;
category: string;
};
export declare class PluginTracer implements IPluginTracer {
/** @private */
origin: string;
/** @private */
category: string;
/** @private */
constructor(opts: TracerOpts);
get enabled(): boolean;
createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?: Record<string, unknown>): ITraceMeasurement | null;
}
export {};

View File

@@ -0,0 +1,131 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.tracer = exports.default = exports.PluginTracer = void 0;
function _events() {
const data = require("@parcel/events");
_events = function () {
return data;
};
return data;
}
function _perf_hooks() {
const data = require("perf_hooks");
_perf_hooks = function () {
return data;
};
return data;
}
// @ts-ignore
let tid;
try {
tid = require('worker_threads').threadId;
} catch {
tid = 0;
}
const pid = process.pid;
class TraceMeasurement {
#active = true;
#name;
#pid;
#tid;
#start;
// $FlowFixMe
#data;
constructor(tracer, name, pid, tid, data) {
this.#name = name;
this.#pid = pid;
this.#tid = tid;
this.#start = _perf_hooks().performance.now();
this.#data = data;
}
end() {
if (!this.#active) return;
const duration = _perf_hooks().performance.now() - this.#start;
tracer.trace({
type: 'trace',
name: this.#name,
pid: this.#pid,
tid: this.#tid,
duration,
ts: this.#start,
...this.#data
});
this.#active = false;
}
}
class Tracer {
#traceEmitter = new (_events().ValueEmitter)();
#enabled = false;
onTrace(cb) {
return this.#traceEmitter.addListener(cb);
}
async wrap(name, fn) {
let measurement = this.createMeasurement(name);
try {
await fn();
} finally {
measurement && measurement.end();
}
}
createMeasurement(name, category = 'Core', argumentName, otherArgs) {
if (!this.enabled) return null;
// We create `args` in a fairly verbose way to avoid object
// allocation where not required.
let args;
if (typeof argumentName === 'string') {
args = {
name: argumentName
};
}
if (typeof otherArgs === 'object') {
if (typeof args == 'undefined') {
args = {};
}
for (const [k, v] of Object.entries(otherArgs)) {
args[k] = v;
}
}
const data = {
categories: [category],
args
};
return new TraceMeasurement(this, name, pid, tid, data);
}
get enabled() {
return this.#enabled;
}
enable() {
this.#enabled = true;
}
disable() {
this.#enabled = false;
}
trace(event) {
if (!this.#enabled) return;
this.#traceEmitter.emit(event);
}
}
exports.default = Tracer;
const tracer = exports.tracer = new Tracer();
class PluginTracer {
/** @private */
/** @private */
/** @private */
constructor(opts) {
this.origin = opts.origin;
this.category = opts.category;
}
get enabled() {
return tracer.enabled;
}
createMeasurement(name, category, argumentName, otherArgs) {
return tracer.createMeasurement(name, `${this.category}:${this.origin}${typeof category === 'string' ? `:${category}` : ''}`, argumentName, otherArgs);
}
}
exports.PluginTracer = PluginTracer;

View File

@@ -0,0 +1,4 @@
export { default as SamplingProfiler } from "./SamplingProfiler";
export { default as Trace } from "./Trace";
export { tracer, PluginTracer } from "./Tracer";
export type { TraceMeasurement, TraceMeasurementData } from "./types";

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "PluginTracer", {
enumerable: true,
get: function () {
return _Tracer.PluginTracer;
}
});
Object.defineProperty(exports, "SamplingProfiler", {
enumerable: true,
get: function () {
return _SamplingProfiler.default;
}
});
Object.defineProperty(exports, "Trace", {
enumerable: true,
get: function () {
return _Trace.default;
}
});
Object.defineProperty(exports, "tracer", {
enumerable: true,
get: function () {
return _Tracer.tracer;
}
});
var _SamplingProfiler = _interopRequireDefault(require("./SamplingProfiler"));
var _Trace = _interopRequireDefault(require("./Trace"));
var _Tracer = require("./Tracer");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

View File

@@ -0,0 +1,7 @@
export interface TraceMeasurement {
end(): void;
}
export type TraceMeasurementData = {
readonly categories: string[];
readonly args?: Record<string, unknown>;
};

View File

@@ -0,0 +1 @@
"use strict";