Merge pull request #28880 from overleaf/bg-add-time-option-to-clsi

add latexmk `-time` option to clsi and record performance logs

GitOrigin-RevId: 467473859359913da73f83e10b63b45603ea175c
This commit is contained in:
Brian Gough
2025-10-09 08:06:12 +00:00
committed by Copybot
parent 3913008e02
commit d24f37d3a4
12 changed files with 441 additions and 8 deletions
+24
View File
@@ -0,0 +1,24 @@
const crypto = require('node:crypto')
/**
* Consistently sample a keyspace with a given sample percentage.
* The same key will always produce a consistent percentile value that
* can be compared against the sample percentage.
* Example: if key is the userId and the samplePercentage is 10, then
* we see all the activity for the 10% of users who are selected.
*
* @param {string} key - The unique identifier to be hashed and checked.
* @param {number} samplePercentage - The percentage (0-100) of keys that should return true.
* @returns {boolean} - True if the key is within the sample, false otherwise.
*/
function sampleByHash(key, samplePercentage) {
if (samplePercentage <= 0) {
return false
}
const hash = crypto.createHash('md5').update(key).digest()
const hashValue = hash.readUInt32BE(0)
const percentile = Math.floor((hashValue / 0xffffffff) * 100)
return percentile < samplePercentage
}
module.exports = { sampleByHash }