files/en-us/web/api/gpucommandencoder/writetimestamp/index.md
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{deprecated_header}}{{non-standard_header}}{{AvailableInWorkers}}
The writeTimestamp() method of the
{{domxref("GPUCommandEncoder")}} interface encodes a command that writes a timestamp into a {{domxref("GPUQuerySet")}} once the previous commands recorded into the same queued {{domxref("GPUCommandBuffer")}} have been executed by the GPU.
[!NOTE] To use timestamp queries, the
timestamp-query{{domxref("GPUSupportedFeatures", "feature", "", "nocode")}} must be enabled in the {{domxref("GPUDevice")}}.
writeTimestamp(querySet, queryIndex)
querySet
queryIndex
None ({{jsxref("Undefined")}}).
The following criteria must be met when calling writeTimestamp(), otherwise a {{domxref("GPUValidationError")}} is generated and the {{domxref("GPUCommandEncoder")}} becomes invalid:
timestamp-query {{domxref("GPUSupportedFeatures", "feature", "", "nocode")}} is enabled in the {{domxref("GPUDevice")}}.querySet {{domxref("GPUQuerySet.type")}} is "timestamp"queryIndex value is less than the {{domxref("GPUQuerySet.count")}}.// …
const querySet = device.createQuerySet({
type: "timestamp",
count: 32,
});
// …
commandEncoder.writeTimestamp(querySet, 0);
// …
{{Specifications}}
{{Compat}}