{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "https://pvs-studio.com/pvs-studio-analyzer-log-schema.json",
  "title": "Structured log produced by the pvs-studio-analyzer utility",
  "type": "object",
  "required": [
    "basicPerformance",
    "configuration",
    "environment",
    "input",
    "output",
    "pvsDiagVersion",
    "runs",
    "toolchains",
    "utility"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "description": "URI of the JSON Schema used to validate this document"
    },
    "basicPerformance": {
      "$ref": "#/definitions/basicPerformance"
    },
    "configuration": {
      "$ref": "#/definitions/configuration"
    },
    "environment": {
      "$ref": "#/definitions/environment"
    },
    "input": {
      "$ref": "#/definitions/input"
    },
    "output": {
      "$ref": "#/definitions/output"
    },
    "pvsDiagVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "Indicates that this is a log produced by PVS-Studio tools and specifies the format version"
    },
    "runs": {
      "$ref": "#/definitions/runs"
    },
    "toolchains": {
      "$ref": "#/definitions/toolchains"
    },
    "utility": {
      "$ref": "#/definitions/utility"
    }
  },
  "additionalProperties": false,
  "definitions": {
    "timepoint": {
      "$comment": "A point in time in extended ISO-8601 UTC+0 format (YYYY-MM-DDThh:mm:ss.sssZ)",
      "type": "string",
      "format": "date-time"
    },
    "durationNS": {
      "$comment": "Duration (in nanoseconds)",
      "type": "integer",
      "minimum": 0
    },
    "durationISO": {
      "$comment": "Duration in ISO-8601 format (hh:mm:ss.sssZ)",
      "type": "string",
      "format": "time"
    },
    "memorySize": {
      "$comment": "Amount of memory",
      "type": "integer",
      "minimum": 0
    },
    "envVars": {
      "$comment": "Map of environment variable names to values",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "artifacts": {
      "type": "object",
      "description": "Map of artifact names to file paths",
      "properties": {
        "cfg": {
          "type": "string",
          "minLength": 1,
          "description": "Path to the PVS-Studio configuration file"
        },
        "rawLog": {
          "type": "string",
          "minLength": 1,
          "description": "Path to the raw log file"
        },
        "stacktraceFile": {
          "type": "string",
          "minLength": 1,
          "description": "Path to the stacktrace file"
        }
      },
      "additionalProperties": {
        "type": "string"
      }
    },
    "toolchains": {
      "type": "array",
      "description": "Information about detected toolchains",
      "items": {
        "type": "object",
        "required": [
          "filePath",
          "info",
          "isUnknown",
          "name",
          "kind"
        ],
        "properties": {
          "cwd": {
            "type": "string",
            "description": "The current working directory from which information about the compiler was requested"
          },
          "filePath": {
            "type": "string",
            "minLength": 1,
            "description": "Path to the compiler executable"
          },
          "info": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Output captured while probing the compiler (for example, version information or diagnostic messages)"
          },
          "isUnknown": {
            "type": "boolean",
            "description": "Indicates that the compiler type could not be determined and a default value was used"
          },
          "name": {
            "type": "string",
            "description": "Compiler name or identifier"
          },
          "kind": {
            "type": "string",
            "description": "Compiler kind or target language family"
          }
        }
      }
    },
    "utility": {
      "type": "object",
      "description": "Information about the utility that produced the log",
      "required": [
        "name",
        "path",
        "version",
        "hash",
        "isStable",
        "logVersion"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "const": "pvs-studio-analyzer",
          "description": "Human-readable platform-independent utility name"
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "description": "Path to the utility executable"
        },
        "version": {
          "type": "string",
          "description": "Utility version"
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-fA-F0-9]{32}$",
          "description": "MD5 checksum of the utility file"
        },
        "isStable": {
          "type": "boolean",
          "description": "Indicates whether this is a stable build"
        },
        "logVersion": {
          "type": "integer",
          "minimum": 2,
          "description": "Log format version for this utility"
        }
      },
      "additionalProperties": false
    },
    "environment": {
      "type": "object",
      "required": [
        "os",
        "osVersion",
        "platform",
        "totalRam",
        "totalRamMiB",
        "physicalRam",
        "physicalRamMiB",
        "availableRam",
        "availableRamMiB",
        "variables"
      ],
      "description": "Information about the environment where the utility was run (host)",
      "properties": {
        "os": {
          "type": "string",
          "description": "Operating system (Windows, Linux, macOS, AstraLinux, ...)"
        },
        "osVersion": {
          "type": "string",
          "description": "Operating system version"
        },
        "platform": {
          "type": "string",
          "description": "Host platform"
        },
        "totalRam": {
          "$ref": "#/definitions/memorySize",
          "description": "Total RAM (bytes)"
        },
        "totalRamMiB": {
          "$ref": "#/definitions/memorySize",
          "description": "Total RAM (MiB)"
        },
        "physicalRam": {
          "$ref": "#/definitions/memorySize",
          "description": "Physical memory (bytes)"
        },
        "physicalRamMiB": {
          "$ref": "#/definitions/memorySize",
          "description": "Physical memory (MiB)"
        },
        "availableRam": {
          "$ref": "#/definitions/memorySize",
          "description": "Available RAM at startup (bytes)"
        },
        "availableRamMiB": {
          "$ref": "#/definitions/memorySize",
          "description": "Available RAM at startup (MiB)"
        },
        "variables": {
          "$ref": "#/definitions/envVars",
          "description": "Environment variables"
        }
      },
      "additionalProperties": false
    },
    "input": {
      "type": "object",
      "description": "Utility input parameters (explicit and implicit)",
      "required": [
        "arguments",
        "cwd",
        "projectFile",
        "timestamp",
        "logging"
      ],
      "properties": {
        "arguments": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Utility command-line arguments"
        },
        "cwd": {
          "type": "string",
          "minLength": 1,
          "description": "Current working directory of the process"
        },
        "projectFile": {
          "type": "string",
          "minLength": 1,
          "description": "Input file for analysis (for example, strace output or compile_commands.json)"
        },
        "timestamp": {
          "$ref": "#/definitions/timepoint",
          "description": "Analyzer start date and time in ISO-8601 UTC+0 format (YYYY-MM-DDThh:mm:ss.sssZ)"
        },
        "logging": {
          "$ref": "#/definitions/logging"
        }
      },
      "additionalProperties": false
    },
    "ruleConfig": {
      "type": "object",
      "required": [
        "filePath",
        "priority"
      ],
      "properties": {
        "filePath": {
          "type": "string",
          "description": "Path to the file"
        },
        "priority": {
          "type": "integer",
          "description": "Config priority"
        }
      },
      "additionalProperties": false
    },
    "pathSettings": {
      "type": "object",
      "description": "Path settings",
      "required": [
        "excluded",
        "included",
        "isolatedDirs",
        "skipSettingsFrom",
        "skipAnalysisFrom"
      ],
      "properties": {
        "excluded": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of paths excluded from analysis"
        },
        "included": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of paths included in analysis"
        },
        "isolatedDirs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of isolated directories"
        },
        "skipSettingsFrom": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Paths whose settings are ignored"
        },
        "skipAnalysisFrom": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Paths whose analyzer warnings are ignored"
        }
      },
      "additionalProperties": false
    },
    "logging": {
      "type": "object",
      "description": "Logging settings",
      "required": [
        "categories",
        "options",
        "sourceLog"
      ],
      "properties": {
        "categories": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "basic",
              "parser",
              "performance"
            ]
          },
          "minItems": 1,
          "uniqueItems": true,
          "description": "Logging categories"
        },
        "options": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "skip-sensitive",
              "dump-intermediate-files",
              "embed-runs"
            ]
          },
          "uniqueItems": true,
          "description": "Logging options"
        },
        "sourceLog": {
          "type": "string",
          "minLength": 1,
          "description": "Path to the raw log file from which the structured log was produced"
        }
      },
      "additionalProperties": false
    },
    "output": {
      "type": "object",
      "description": "Utility results",
      "required": [
        "anomalies",
        "artifacts",
        "isFailed",
        "returnCode",
        "stderr",
        "stdout"
      ],
      "properties": {
        "anomalies": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of anomalies identified based on the log"
        },
        "artifacts": {
          "$ref": "#/definitions/artifacts",
          "description": "Output files produced by the utility"
        },
        "isFailed": {
          "type": "boolean",
          "description": "Whether the utility considers the run failed"
        },
        "returnCode": {
          "$ref": "#/definitions/returnCode",
          "description": "Utility exit code"
        },
        "stderr": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "stderr contents (excluding analyzer warnings)"
        },
        "stdout": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "stdout contents (excluding analyzer warnings)"
        }
      },
      "additionalProperties": false
    },
    "basicPerformance": {
      "type": "object",
      "description": "Basic performance metrics",
      "required": [
        "elapsedTime",
        "elapsedTimeISO",
        "peakMemoryConsumption",
        "peakMemoryConsumptionMiB"
      ],
      "properties": {
        "elapsedTime": {
          "$ref": "#/definitions/durationNS",
          "description": "Elapsed time (nanoseconds)"
        },
        "elapsedTimeISO": {
          "$ref": "#/definitions/durationISO",
          "description": "Elapsed time in ISO-8601 format (hh:mm:ss.sssZ)"
        },
        "peakMemoryConsumption": {
          "$ref": "#/definitions/memorySize",
          "description": "Peak memory usage (bytes)"
        },
        "peakMemoryConsumptionMiB": {
          "$ref": "#/definitions/memorySize",
          "description": "Peak memory usage (MiB)"
        }
      },
      "additionalProperties": false
    },
    "executorStage": {
      "type": "object",
      "description": "Description of an action performed by an executor",
      "required": [
        "artifacts",
        "isFailed",
        "order",
        "returnCode"
      ],
      "additionalProperties": true,
      "properties": {
        "artifacts": {
          "$ref": "#/definitions/artifacts",
          "description": "Files related to this stage"
        },
        "details": {
          "type": "object",
          "description": "Detailed information about the executor step"
        },
        "isFailed": {
          "type": "boolean",
          "description": "Whether this stage failed"
        },
        "order": {
          "type": "integer",
          "minimum": 0,
          "description": "Executor run sequence number"
        },
        "returnCode": {
          "$ref": "#/definitions/returnCode",
          "description": "Executor exit code"
        }
      }
    },
    "executorEntry": {
      "type": "object",
      "required": [
        "id"
      ],
      "description": "Information about an executor run",
      "properties": {
        "dependencies": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of dependent files"
        },
        "id": {
          "type": "string",
          "description": "Executor run identifier (UUID)",
          "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
        },
        "inputArgs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Executor command-line arguments"
        },
        "sourceFilePath": {
          "type": "string",
          "description": "Path to the analyzed file"
        },
        "stages": {
          "type": "object",
          "description": "Executor stages",
          "properties": {
            "preprocessing": {
              "$ref": "#/definitions/preprocessingStage"
            }
          },
          "additionalProperties": {
            "$ref": "#/definitions/executorStage"
          }
        },
        "systemDirs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of directories the analyzer treats as system directories"
        }
      }
    },
    "executorEntryExecuted": {
      "allOf": [
        {
          "$ref": "#/definitions/executorEntry"
        },
        {
          "type": "object",
          "required": [
            "stages"
          ],
          "properties": {
            "stages": {
              "type": "object",
              "required": [
                "analysis"
              ]
            }
          }
        }
      ]
    },
    "runs": {
      "type": "object",
      "required": [
        "auxiliary",
        "executed",
        "failed",
        "skipped"
      ],
      "description": "Information about executor runs",
      "properties": {
        "auxiliary": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/executorEntry"
          },
          "description": "List of auxiliary analyzer runs (not directly related to specific files)"
        },
        "executed": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/executorEntryExecuted"
          },
          "description": "List of successfully analyzed files"
        },
        "failed": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/executorEntry"
          },
          "description": "List of failed analyzer runs"
        },
        "skipped": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/executorEntry"
          },
          "description": "List of files skipped during analysis"
        }
      },
      "additionalProperties": false
    },
    "returnCode": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Exit code. May be null."
    },
    "preprocessingStage": {
      "allOf": [
        {
          "$ref": "#/definitions/executorStage"
        },
        {
          "type": "object",
          "required": [
            "artifacts",
            "environment",
            "launchArgs",
            "output",
            "preprocessor"
          ],
          "properties": {
            "artifacts": {
              "type": "object",
              "required": [
                "outputFile"
              ],
              "properties": {
                "outputFile": {
                  "type": "string",
                  "description": "Path to the preprocessed output file"
                }
              },
              "additionalProperties": {
                "type": "string"
              },
              "description": "Files produced during preprocessing"
            },
            "environment": {
              "$ref": "#/definitions/envVars",
              "description": "Environment variables used to run the preprocessor"
            },
            "launchArgs": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "Preprocessor command-line arguments"
            },
            "output": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "Preprocessor output (stdout + stderr)"
            },
            "preprocessor": {
              "type": "string",
              "minLength": 1,
              "description": "Path to the preprocessor executable"
            }
          }
        }
      ]
    },
    "configuration": {
      "type": "object",
      "required": [
        "annotations",
        "pathSettings",
        "ruleConfigs",
        "suppressFiles",
        "threads"
      ],
      "description": "Actual analyzer configuration",
      "properties": {
        "annotations": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of paths to annotation files"
        },
        "pathSettings": {
          "$ref": "#/definitions/pathSettings"
        },
        "ruleConfigs": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ruleConfig"
          },
          "description": "List of included pvsconfig files (explicit and implicit)"
        },
        "suppressFiles": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of included suppression files (explicit and implicit)"
        },
        "threads": {
          "type": "integer",
          "description": "Actual number of execution threads"
        }
      },
      "additionalProperties": true
    }
  }
}
