Name: ah-processor.utils
Owner: NodeSource
Description: Utilities used by the ah-*.processor modules.
Created: 2017-03-13 10:42:02.0
Updated: 2017-03-13 10:51:49.0
Pushed: 2017-03-20 11:00:59.0
Homepage: null
Size: 1204
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Utilities used by the ah-*.processor modules.
npm install ah-processor.utils
Table of Contents generated with DocToc
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-fsid
number the id of the root activity we whose triggered children we are trying to findstop
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.
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 activitiesids
Set<Number> the ids to consider when finding the oldestReturns Number the id of the oldest activity or null
if no activity for any id was found
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 activitiesids
Set<Number> the ids to consider when finding most immediatethe
Number id of the activity for which we will find the activity that initialized immediately beforeReturns Number the id that initialized immediately before the activity with id
or null
if no activity for any
id was found
Prettifies the provided timestamp which is expected to be in nanoseconds.
Parameters
ns
number timestamp in nanosecondsReturns 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.
Safely extracts the val
property from the object x
.
Parameters
x
Object the object which has the val
propertyReturns any the val
property if x
was defined, otherwise null
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
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
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
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 resourcesMerges 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 propertyPath
s of all functions
that matched the location
.
Parameters
info
Object the object that references the userFunctions
propertyObtains 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 assessReturns Object the life cycle information
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:
Parameters
$0
Object options
Returns Array<Object> a collection of operations that were identified from the given activities
MIT