<!--
Copyright 2024 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<!--
This file is used to generate a comprehensive list of WebNN histograms
along with a detailed description for each histogram.

For best practices on writing histogram descriptions, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/README.md

Please follow the instructions in the OWNERS file in this directory to find a
reviewer. If no OWNERS file exists, please consider signing up at
go/reviewing-metrics (Googlers only), as all subdirectories are expected to
have an OWNERS file. As a last resort you can send the CL to
chromium-metrics-reviews@google.com.
-->

<histogram-configuration>

<histograms>

<variants name="WebNNCoreMLActions">
  <variant name="CompiledModelLoad"
      summary="time to load the compiled .mlmodelc file."/>
  <variant name="MLModelCompile"
      summary="time to compile the generated .mlmodel file."/>
  <variant name="MLModelTranslate"
      summary="time to translate from webnn graph to CoreML representation
               and serializes to disk."/>
  <variant name="MLModelWrite"
      summary="time to write the temporary .mlmodel file."/>
  <variant name="MLWeightsWrite"
      summary="time to write the temporary weights.bin file."/>
  <variant name="ModelPredictWithDispatch"
      summary="time predictionFromFeatures took when calling dispatch()."/>
</variants>

<variants name="WebNNDMLActions">
  <variant name="Compilation" summary="time to compile the DirectML graph."/>
  <variant name="RecordGraphExecutionOnBackgroundThread"
      summary="time to record graph execution on background thread."/>
  <variant name="RecordGraphExecutionOnMainThread"
      summary="time to record graph execution on the main thread."/>
</variants>

<variants name="WebNNOrtActions">
  <variant name="Compilation" summary="time to compile the graph."/>
  <variant name="CreateEnvironment"
      summary="time to create the ORT environment."/>
  <variant name="Inference" summary="time to inference."/>
</variants>

<variants name="WebNNOrtExecutionProvider">
  <variant name="MIGraphXExecutionProvider"/>
  <variant name="NvTensorRTRTXExecutionProvider"/>
  <variant name="OpenVINOExecutionProvider"/>
  <variant name="QNNExecutionProvider"/>
  <variant name="VitisAIExecutionProvider"/>
  <variant name="WebGpuExecutionProvider"/>
</variants>

<histogram
    name="WebNN.CompilerProcess.CrashCount.{WebNNOrtExecutionProvider}.{DeviceType}"
    units="count" expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    Records the cumulative number of unexpected WebNN Compiler process
    disconnections (crashes) for {WebNNOrtExecutionProvider} on {DeviceType}
    within a single browser session. Each EP device has its own compiler process
    and crash count. Logged each time the Compiler process disconnects
    unexpectedly. Values range from 1 to 3, after which the Compiler process is
    no longer relaunched.
  </summary>
  <token key="WebNNOrtExecutionProvider" variants="WebNNOrtExecutionProvider"/>
  <token key="DeviceType">
    <variant name="CPU" summary="CPU device"/>
    <variant name="GPU" summary="GPU device"/>
    <variant name="NPU" summary="NPU device"/>
  </token>
</histogram>

<histogram name="WebNN.ConstantDataSizeInKB" units="KB"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>Records the constant data sizes in KB.</summary>
</histogram>

<histogram name="WebNN.Context.Backend" enum="ContextBackendUma"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>Records what backend WebNN is running on.</summary>
</histogram>

<histogram name="WebNN.CoreML.TimingMs.{WebNNCoreMLActions}" units="ms"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    The time taken to perform a WebNN CoreML action. This includes
    {WebNNCoreMLActions}
  </summary>
  <token key="WebNNCoreMLActions" variants="WebNNCoreMLActions"/>
</histogram>

<histogram name="WebNN.DeviceType" enum="DeviceTypeUma"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>Records what device type WebNN is running on.</summary>
</histogram>

<histogram name="WebNN.DML.TimingMs.{WebNNDMLActions}" units="ms"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    The time taken to perform a WebNN DML action. This includes
    {WebNNDMLActions}
  </summary>
  <token key="WebNNDMLActions" variants="WebNNDMLActions"/>
</histogram>

<histogram name="WebNN.DMLCreateDevice.Error" enum="Hresult"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    The HRESULT returned when an attempt to create a dml device fails.
  </summary>
</histogram>

<histogram name="WebNN.MLTensor.TimingMs.Read" units="ms"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>The time taken to read the ml tensor.</summary>
</histogram>

<histogram name="WebNN.Operator" enum="MLGraphOperatorUma"
    expires_after="2027-01-03">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    When an MLGraph is built using WebNN, this histogram records whether a given
    operator has been used. The enum value GraphBuilt is always logged once per
    MLGraph, so to see the prevalence of a given operator, you need to divide
    its count by GraphBuilt count.
  </summary>
</histogram>

<histogram name="WebNN.ORT.FirstSelectedDevice" enum="WebNNOrtDeviceUma"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    Records the first hardware device selected for the ORT backend.
  </summary>
</histogram>

<histogram name="WebNN.ORT.FirstSelectedEP" enum="WebNNOrtEPUma"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    Records the first execution provider selected for the ORT backend.
  </summary>
</histogram>

<histogram name="WebNN.ORT.ImportMemorySuccess" enum="Boolean"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    Records whether importing a D3D12 heap into the ORT backend succeeded.
  </summary>
</histogram>

<histogram name="WebNN.ORT.TimingMs.{WebNNOrtActions}" units="ms"
    expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    The time taken to perform a WebNN ORT action. This includes
    {WebNNOrtActions}
  </summary>
  <token key="WebNNOrtActions" variants="WebNNOrtActions"/>
</histogram>

<histogram name="WebNN.ORT.WinAppRuntimeInstallState"
    enum="WinAppRuntimeInstallStateUma" expires_after="2027-01-03">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    This histogram records the installation state during installation of the
    Windows App Runtime package at browser startup. The state reflects whether
    the installation completed, failed, or encountered other relevant
    conditions.
  </summary>
</histogram>

<histogram name="WebNN.ORT.{PackageDependencyAction}.ErrorResult"
    enum="Hresult" expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    This histogram records the HRESULT of {PackageDependencyAction}. This action
    occurs during installation of the Windows App Runtime package at browser
    startup, or when initializing the WebNN ORT backend.
  </summary>
  <token key="PackageDependencyAction">
    <variant name="AddPackageDependency"/>
    <variant name="DeletePackageDependency"/>
    <variant name="TryCreatePackageDependency"/>
  </token>
</histogram>

<histogram name="WebNN.ORT.{WebNNOrtExecutionProvider}.Status"
    enum="ExecutionProviderStatusUma" expires_after="2027-06-27">
  <owner>reillyg@chromium.org</owner>
  <owner>src/services/webnn/OWNERS</owner>
  <summary>
    WebNN ORT backend can run on different execution providers (EPs). This
    histogram records the status of {WebNNOrtExecutionProvider} during the EP
    initialization, queried by EP Catalog API.
  </summary>
  <token key="WebNNOrtExecutionProvider" variants="WebNNOrtExecutionProvider"/>
</histogram>

</histograms>

</histogram-configuration>
