Socket
Socket
Sign inDemoInstall

@searchspring/snap-profiler

Package Overview
Dependencies
0
Maintainers
3
Versions
84
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @searchspring/snap-profiler

Snap Profiler


Version published
Weekly downloads
2.4K
decreased by-10.25%
Maintainers
3
Install size
12.8 kB
Created
Weekly downloads
 

Changelog

Source

0.53.4 (2024-04-22)

Bug Fixes

  • preact-components-carousel: bugfix for backwards compatible classnames on carousel re-renders (0fbbf29)

Readme

Source

Snap Profiler

NPM Status

A utility for recording how long something takes to complete. Profiler is used in finding API response, component rendering and Middleware execution times.

Dependency

Snap Profiler is a dependency of @searchspring/snap-controller NPM Status

Installation

npm install --save @searchspring/snap-profiler

Import

import { Profiler } from '@searchspring/snap-profiler';

Profiler

An optional `namespace` can be passed to the Profiler constructor for profile organization.
import { Profiler } from '@searchspring/snap-profiler';

const profiler = new Profiler('namespace');

setNamespace method

Programatically set the namespace after construction.

import { Profiler } from '@searchspring/snap-profiler';

const profiler = new Profiler();

profiler.setNamespace('namespace');

create method

Create a new profile.

import { Profiler } from '@searchspring/snap-profiler';

const profiler = new Profiler();

const searchProfile = profiler.create({ 
	type: 'event', 
	name: 'search', 
	context: params
}: ProfileDetails);
type ProfileDetails<T> = { 
	type: string; 
	name: string; 
	context: T;
}

Returns an instance of Profile.

Profile

Profile is not an exported member of the Snap Profiler package. It is only returned in the Profiler create method.

start method

This will start the profiler timer.

searchProfile.start();

stop method

This will stop the profiler timer.

searchProfile.stop();

namespace property

Profile namespace that was set using the Profiler constructor or the setNamespace method.

console.log(`namespace: ${searchProfile.namespace}`);

type property

Profile type that was set in the create method ProfileDetails parameters.

console.log(`type: ${searchProfile.type}`);

name property

Profile name that was set in the create method ProfileDetails parameters.

console.log(`name: ${searchProfile.name}`);

context property

Profile context that was set in the create method ProfileDetails parameters. The context is used to provide additional details regarding the profile. A search profile would likely contain the request parameters amoung other things.

console.log(`context: ${searchProfile.context}`);

status property

Profile status. The default value is pending.

The value will change to started when the start method is invoked and to finished when the stop method is invoked.

console.log(`context: ${searchProfile.status}`);

time property

Profile time object is of type ProfileTime:

type ProfileTime = {
	date: number;
	begin: number;
	end: number;
	run: number;
};

ProfileTime.date - set to Date.now() when start method is invoked.

ProfileTime.begin - set to window.performance.now() when start method is invoked.

ProfileTime.end - set to window.performance.now() when stop method is invoked.

ProfileTime.run - set to the total running time in milliseconds between when the start and stop methods have been invoked.

Logging profiles

It is recommended to using the Snap Logger's profile method to log Snap Profiles as it provides a clean output for easy parsing.

FAQs

Last updated on 22 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc