import { ServiceObject } from '@google-cloud/common'; import { ProfilerConfig } from './config'; /** * Interface for deployment field of RequestProfile. Profiles with matching * deployments will be grouped together. * Used as body of request when creating profile using the profiler API. * * Public for testing. */ export interface Deployment { projectId?: string; target?: string; labels?: { zone?: string; version?: string; language: string; }; } /** * Interface for body of response from profiler API when creating * profile and used as body of request to profiler API when * uploading a profile. * * Public for testing. */ export interface RequestProfile { name: string; profileType?: string; duration?: string; profileBytes?: string; deployment?: Deployment; labels?: { instance?: string; }; } /** * Error constructed from HTTP server response which indicates backoff. */ export declare class BackoffResponseError extends Error { readonly backoffMillis: number; constructor(message: string | undefined, backoffMillis: number); } /** * Class which tracks how long to wait before the next retry and can be * used to get this backoff. */ export declare class Retryer { readonly initialBackoffMillis: number; readonly backoffCapMillis: number; readonly backoffMultiplier: number; private nextBackoffMillis; private random; constructor(initialBackoffMillis: number, backoffCapMillis: number, backoffMultiplier: number, random?: () => number); getBackoff(): number; reset(): void; } /** * Polls profiler server for instructions on behalf of a task and * collects and uploads profiles as requested. * * If heap profiling is enabled, the heap profiler must be enabled before heap * profiles can be collected. */ export declare class Profiler extends ServiceObject { private logger; private profileLabels; private deployment; private profileTypes; private retryer; private sourceMapper; private baseApiUrl; config: ProfilerConfig; constructor(config: ProfilerConfig); /** * Starts an endless loop to poll profiler server for instructions, and * collects and uploads profiles as requested. * If there is a problem when collecting a profile or uploading a profile to * profiler server, this problem will be logged at the error level and * otherwise ignored. * If there is a problem polling profiler server for instructions * on the type of profile to be collected, this problem will be logged at the * error level and getting profile type will be retried. */ start(): Promise; /** * Endlessly polls the profiler server for instructions, and collects and * uploads profiles as requested. */ runLoop(): Promise; /** * Waits for profiler server to tell it to collect a profile, then collects * a profile and uploads it. * * @return time, in ms, to wait before asking profiler server again about * collecting another profile. */ collectProfile(): Promise; /** * Talks to profiler server, which hangs until server indicates * job should be profiled and then indicates what type of profile should * be collected. * * If any problem is encountered, an error will be thrown. * * @return a RequestProfile specifying which type of profile should be * collected and other information needed to collect and upload a profile of * the specified type. * * TODO (issue #28): right now, this call could hang for up to an hour when * this method is the only thing on the event loop, keeping the program open * even when all work is done. Should expose the ability to cancel the http * request made here, and then determine when to cancel this request. * * Public to allow for testing. */ createProfile(): Promise; /** * Collects a profile of the type specified by the profileType field of prof. * If any problem is encountered, like a problem collecting or uploading the * profile, a message will be logged, and the error will otherwise be ignored. * * Public to allow for testing. */ profileAndUpload(prof: RequestProfile): Promise; /** * Collects a profile of the type specified by profileType field of prof. * If any problem is encountered, for example the profileType is not * recognized or profiling is disabled for the specified profileType, an * error will be thrown. * * Public to allow for testing. */ profile(prof: RequestProfile): Promise; /** * Collects a time profile, converts profile to compressed, base64 encoded * string, and puts this string in profileBytes field of prof. * * Public to allow for testing. */ writeTimeProfile(prof: RequestProfile): Promise; /** * Collects a heap profile, converts profile to compressed, base64 encoded * string, and adds profileBytes field to prof with this string. * * Public to allow for testing. */ writeHeapProfile(prof: RequestProfile): Promise; }