开发者社区> 镜像站> NPM> ah-processor.utils
ah-processor.utils
Utilities used by the ah-*.processor modules.
Last updated 4 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ah-processor.utils 
SYNC missed versions from official npm registry.

ah-processor.utils

Utilities used by the ah-*.processor modules.

Installation

npm install ah-processor.utils

Table of Contents generated with DocToc

API

idsTriggeredBy

Finds all ids of activities that are triggered by the given id. This function works recursive, i.e. any activity triggered by a child of the root activity is included as well.

For this to work, activities are assumed to be in the order that they were triggered. This can easily be achieved by simply sorting the activities by their init timestamp.

Parameters

  • activities Map<number, Activity> collected via ah-fs
  • id number the id of the root activity we whose triggered children we are trying to find
  • stop function a predicate that will finish the activity walk if it returns true. Function signature: (id, activity).

Returns Set<number> the provided root id and all ids of activities triggered by it or any of it's children, grandchildren, etc.

oldestId

Finds the oldest activity of the ones supplied via the ids. We consider an activity older than another one if it's init timestamp is further in the past.

Any ids we can't find as in the activities are ignored.

Parameters

  • activities Map<Number, Object> the collected async activities
  • ids Set<Number> the ids to consider when finding the oldest

Returns Number the id of the oldest activity or null if no activity for any id was found

immediatelyBeforeId

Finds the activity of the ones supplied via the ids that initialized immediately before the one with the given id initialized.

Parameters

  • activities Map<Number, Object> the collected async activities
  • ids Set<Number> the ids to consider when finding most immediate
  • the Number id of the activity for which we will find the activity that initialized immediately before

Returns Number the id that initialized immediately before the activity with id or null if no activity for any id was found

prettyNs

Prettifies the provided timestamp which is expected to be in nanoseconds.

Parameters

  • ns number timestamp in nanoseconds

Returns Object<string, number> an object with an ms property which is the prettified version of the provided timestamp in milliseconds and ns, the originally passed timestamp.

safeGetVal

Safely extracts the val property from the object x.

Parameters

  • x Object the object which has the val property

Returns any the val property if x was defined, otherwise null

safeFirstStamp

Safely gets the first time stamp of the given timestamps. If no timestamp is found, a time of 0 is returned.

Parameters

Returns Object the prettified first time stamp

firstNonZeroStamp

Finds the first stamp in the array of time stamp arrays that has a valid time stamp. If none is found it will return a zero time stamp.

Parameters

Returns Object prettified time stamp or prettyNs(0) if not found

uniqueUserFunctions

Identifies all user functions within the given functions, adds location and propertyPath strings and returns the result.

The propertyPath is deduced from the path array.

If a user function is found twice it will only be included once.

Parameters

  • fns Array<Object> all functions found attached to a particular async resource
  • $0 Object options
    • $0.pathPrefix string? prefix used for the property paths (optional, default 'root')

Returns Array<Object> all user functions with the above mentioned details added

separateUserFunctions

Pulls user functions from all resources of the provided info and attaches them as the userFunctions property to the info object directly.

As a result, instead of having a userFunctions array on each resource we end up with just one on the info object.

Parameters

  • info Object the info object which references the resources

mergeUserFunctions

Merges the userFunctions found on the info object, such that all functions with the same location property are represented as one.

As the result the propertyPath array is removed from all functions and replaced with the propertyPaths array which combines the propertyPaths of all functions that matched the location.

Parameters

  • info Object the object that references the userFunctions property

lifeCycle

Obtains the life cycle information using the init and destroy time stamps of the given activity.

All time stamps have the format: { ns: <time in naseconds>, ms: <pretty printed time> }

The return value includes the following properties:

  • created: when the resource was created, i.e. it's init time stamp

  • destroyed: when the resource ceased to exist, i.e. it's destroy time stamp

  • timeAlive: the difference between the above two

    If the destroy time stamp isn't avaible it is set to a prettified version of 0. The same is true in that case for the timeAlive.

Parameters

  • activity Object the activity whose life cycle to assess

Returns Object the life cycle information

processActivities

Applies multiple processors to the given activities in order to process them into operations. Each activity that is identified as part of an operation is removed from the activities map, i.e. it is modified in place. Therefore any activities still present in the map after processing completes, couldn't be processed into an operation.

Each processor needs to be instantiable and have a process function that returns { groups, operations}. Additionally each processor needs to have the following static properties:

  • operationSteps: how many steps (resources) are needed to identify an operation
  • operation: the description of the operation the processor identifies

Parameters

  • $0 Object options
    • $0.activities Map<(Number | String), Object> activities to be processed
    • $0.processors Array<Object> collection of processors to be applied
    • $0.includeActivities Boolean if true the activities that were used to identify a step of an operation are attached to the data about that step

Returns Array<Object> a collection of operations that were identified from the given activities

License

MIT

Current Tags

  • 0.4.0                                ...           latest (4 years ago)

5 Versions

  • 0.4.0                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (1)
Dev Dependencies (0)
None