ContentCacheMetrics.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const Metrics = require('./Metrics')
  2. const ONE_MB = 1024 * 1024
  3. function emitPdfStats(stats, timings) {
  4. if (timings['compute-pdf-caching']) {
  5. emitPdfCachingStats(stats, timings)
  6. } else {
  7. // How much bandwidth will the pdf incur when downloaded in full?
  8. Metrics.summary('pdf-bandwidth', stats['pdf-size'])
  9. }
  10. }
  11. function emitPdfCachingStats(stats, timings) {
  12. if (!stats['pdf-size']) return // double check
  13. // How large is the overhead of hashing up-front?
  14. const fraction =
  15. timings.compileE2E - timings['compute-pdf-caching'] !== 0
  16. ? timings.compileE2E /
  17. (timings.compileE2E - timings['compute-pdf-caching'])
  18. : 1
  19. Metrics.summary('overhead-compute-pdf-ranges', fraction * 100 - 100)
  20. // How does the hashing scale to pdf size in MB?
  21. Metrics.timing(
  22. 'compute-pdf-caching-relative-to-pdf-size',
  23. timings['compute-pdf-caching'] / (stats['pdf-size'] / ONE_MB)
  24. )
  25. if (stats['pdf-caching-total-ranges-size']) {
  26. // How does the hashing scale to total ranges size in MB?
  27. Metrics.timing(
  28. 'compute-pdf-caching-relative-to-total-ranges-size',
  29. timings['compute-pdf-caching'] /
  30. (stats['pdf-caching-total-ranges-size'] / ONE_MB)
  31. )
  32. // How fast is the hashing per range on average?
  33. Metrics.timing(
  34. 'compute-pdf-caching-relative-to-ranges-count',
  35. timings['compute-pdf-caching'] / stats['pdf-caching-n-ranges']
  36. )
  37. // How many ranges are new?
  38. Metrics.summary(
  39. 'new-pdf-ranges-relative-to-total-ranges',
  40. (stats['pdf-caching-n-new-ranges'] / stats['pdf-caching-n-ranges']) * 100
  41. )
  42. }
  43. // How much content is cacheable?
  44. Metrics.summary(
  45. 'cacheable-ranges-to-pdf-size',
  46. (stats['pdf-caching-total-ranges-size'] / stats['pdf-size']) * 100
  47. )
  48. const sizeWhenDownloadedInFull =
  49. // All of the pdf
  50. stats['pdf-size'] -
  51. // These ranges are potentially cached.
  52. stats['pdf-caching-total-ranges-size'] +
  53. // These ranges are not cached.
  54. stats['pdf-caching-new-ranges-size']
  55. // How much bandwidth can we save when downloading the pdf in full?
  56. Metrics.summary(
  57. 'pdf-bandwidth-savings',
  58. 100 - (sizeWhenDownloadedInFull / stats['pdf-size']) * 100
  59. )
  60. // How much bandwidth will the pdf incur when downloaded in full?
  61. Metrics.summary('pdf-bandwidth', sizeWhenDownloadedInFull)
  62. // How much space do the ranges use?
  63. // This will accumulate the ranges size over time, skipping already written ranges.
  64. Metrics.summary('pdf-ranges-disk-size', stats['pdf-caching-new-ranges-size'])
  65. }
  66. module.exports = {
  67. emitPdfStats
  68. }