add clsi metrics for png2pdf (#35239)

* add clsi metrics for png2pdf

* update metrics to use png2pdf boolean

GitOrigin-RevId: 0d96020b659b31cdf16f5d26c128928dae45f8f9
This commit is contained in:
Brian Gough
2026-09-17 11:20:34 +00:00
committed by Copybot
parent 18b3bb7503
commit 0dd69cb143
4 changed files with 120 additions and 2 deletions
+1
View File
@@ -829,6 +829,7 @@ function _emitMetrics(request, status, stats, timings) {
stop_on_first_error: request.stopOnFirstError ? 'true' : 'false',
passes,
type: request.syncType,
png2pdf: request.png2pdf ? 'true' : 'false',
})
if (timings.sync != null) {
+6 -1
View File
@@ -1,3 +1,5 @@
import Path from 'node:path'
/**
* Converts a time string in seconds to an integer number of milliseconds.
*
@@ -128,8 +130,11 @@ const LATEX_MK_METRICS_STDERR = [
let type = match[1]
const timeMs = parseInt(match[2], 10)
const filename = match[3]
const extension = Path.extname(filename).toLowerCase()
if (type === 'PNG') {
if (type === 'PDF' && extension === '.png') {
type = `PNG-png2pdf`
} else if (type === 'PNG') {
const pngCategory = pngCategoriesByFile.get(filename)
if (pngCategory != null) {
type = `PNG-${pngCategory}`
+1
View File
@@ -18,6 +18,7 @@ const compilesTotal = new prom.Counter({
'stop_on_first_error',
'passes',
'type',
'png2pdf',
],
})
+112 -1
View File
@@ -3,7 +3,7 @@ import path from 'node:path'
import { expect, describe, beforeEach, it } from 'vitest'
import LatexMetrics from '../../../app/js/LatexMetrics.js'
const { addLatexFdbMetrics } = LatexMetrics
const { addLatexFdbMetrics, addLatexMkMetrics } = LatexMetrics
describe('LatexMetrics', function () {
describe('addLatexFdbMetrics', function () {
@@ -111,4 +111,115 @@ describe('LatexMetrics', function () {
})
})
})
describe('addLatexMkMetrics', function () {
beforeEach(function (ctx) {
ctx.stats = {}
Object.defineProperty(ctx.stats, 'latexmk', {
value: {},
enumerable: false,
})
})
describe('latexmk-img-times', function () {
it('should parse image timing information from stderr', function (ctx) {
const output = {
stderr:
'Image written (PNG, 100 ms): output/image1.png\n' +
'Image written (JPG, 50 ms): output/image2.jpg\n',
}
addLatexMkMetrics(output, ctx.stats)
expect(ctx.stats.latexmk['latexmk-img-times']).to.deep.equal([
{ type: 'PNG', time_ms: 100 },
{ type: 'JPG', time_ms: 50 },
])
})
it('should convert PDF type with .png extension to PNG-png2pdf', function (ctx) {
const output = {
stderr: 'Image written (PDF, 150 ms): image.png\n',
}
addLatexMkMetrics(output, ctx.stats)
expect(ctx.stats.latexmk['latexmk-img-times']).to.deep.equal([
{ type: 'PNG-png2pdf', time_ms: 150 },
])
})
it('should handle uppercase .PNG extension', function (ctx) {
const output = {
stderr: 'Image written (PDF, 200 ms): image.PNG\n',
}
addLatexMkMetrics(output, ctx.stats)
expect(ctx.stats.latexmk['latexmk-img-times']).to.deep.equal([
{ type: 'PNG-png2pdf', time_ms: 200 },
])
})
it('should keep PDF type for non-png extensions', function (ctx) {
const output = {
stderr:
'Image written (PDF, 100 ms): document.pdf\n' +
'Image written (PDF, 80 ms): image.jpg\n',
}
addLatexMkMetrics(output, ctx.stats)
expect(ctx.stats.latexmk['latexmk-img-times']).to.deep.equal([
{ type: 'PDF', time_ms: 180 },
])
})
it('should accumulate timing for the same type', function (ctx) {
const output = {
stderr:
'Image written (PDF, 100 ms): image1.png\n' +
'Image written (PDF, 150 ms): image2.png\n' +
'Image written (PNG, 50 ms): image3.png\n',
}
addLatexMkMetrics(output, ctx.stats)
const result = ctx.stats.latexmk['latexmk-img-times'].sort((a, b) =>
a.type.localeCompare(b.type)
)
expect(result).to.deep.equal([
{ type: 'PNG', time_ms: 50 },
{ type: 'PNG-png2pdf', time_ms: 250 },
])
})
it('should handle PNG with category from PNG copy skipped', function (ctx) {
const output = {
stderr:
'PNG copy skipped (alpha): image1.png\n' +
'Image written (PNG, 75 ms): image1.png\n',
}
addLatexMkMetrics(output, ctx.stats)
expect(ctx.stats.latexmk['latexmk-img-times']).to.deep.equal([
{ type: 'PNG-alpha', time_ms: 75 },
])
})
it('should mix PDF-to-png2pdf and PNG types', function (ctx) {
const output = {
stderr:
'Image written (PDF, 100 ms): converted.png\n' +
'Image written (PNG, 50 ms): native.png\n' +
'Image written (JPG, 30 ms): photo.jpg\n',
}
addLatexMkMetrics(output, ctx.stats)
const result = ctx.stats.latexmk['latexmk-img-times'].sort((a, b) =>
a.type.localeCompare(b.type)
)
expect(result).to.deep.equal([
{ type: 'JPG', time_ms: 30 },
{ type: 'PNG', time_ms: 50 },
{ type: 'PNG-png2pdf', time_ms: 100 },
])
})
})
})
})