Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lambda/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const extractStatistics = (event) => {
power: stat.value,
cost: stat.averagePrice,
duration: stat.averageDuration,
initDuration: stat.initDuration,
totalCost: stat.totalCost,
}));
};
Expand Down
6 changes: 6 additions & 0 deletions lambda/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ const computeStatistics = (baseCost, results, value, discardTopBottom) => {
const averageDuration = utils.computeAverageDuration(durations, discardTopBottom);
console.log('Average duration: ', averageDuration);

const initDurations = utils.parseLogAndExtractInitDurations(results);

const [initDuration] = initDurations;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption is that there's always only one cold start, right? This will change a bit when #177 is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we could use the same computeAverageDuration to get the average init duration, passing discardTopBottom as zero.

console.log('Init duration: ', initDuration);

// ... and overall statistics
const averagePrice = utils.computePrice(baseCost, minRAM, value, averageDuration);

Expand All @@ -154,6 +159,7 @@ const computeStatistics = (baseCost, results, value, discardTopBottom) => {
const stats = {
averagePrice,
averageDuration,
initDuration,
totalCost,
value,
};
Expand Down
21 changes: 20 additions & 1 deletion lambda/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports.createPowerConfiguration = async(lambdaARN, value, alias) => {
try {
await utils.setLambdaPower(lambdaARN, value);

// wait for functoin update to complete
// wait for function update to complete
await utils.waitForFunctionUpdate(lambdaARN);

const {Version} = await utils.publishLambdaVersion(lambdaARN);
Expand Down Expand Up @@ -432,6 +432,15 @@ module.exports.parseLogAndExtractDurations = (data) => {
});
};

module.exports.parseLogAndExtractInitDurations = (data) => {
return data
.map((log) => {
const logString = utils.base64decode(log.LogResult || '');
return utils.extractInitDuration(logString);
})
// remove logs with no init duration (after cold start)
.filter((duration) => duration > 0);
};
/**
* Compute total cost
*/
Expand Down Expand Up @@ -489,6 +498,16 @@ module.exports.extractDuration = (log) => {
const durationStr = durationSplit[1].split(' ms')[0];
return parseFloat(durationStr);
};
/**
* Extract init duration (in ms) from a given Lambda's CloudWatch log.
*/
module.exports.extractInitDuration = (log) => {
const initDurationMatches = log.match(/\tInit Duration: ([0-9\.]*) ms/);
if (initDurationMatches === null) return 0;

const durationStr = initDurationMatches[1];
return parseFloat(durationStr);
};

/**
* Encode a given string to base64.
Expand Down
Loading