{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "https://pvs-studio.com/pvs-studio-analyzer-log-schema.json",
  "title": "Structured log for the pvs-studio-analyzer utility",
  "type": "object",
  "required": [
    "detectedCompilers",
    "pvsDiagVersion",
    "utility",
    "environment",
    "input",
    "output",
    "basicPerformance",
    "runs"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "description": "Path to the data schema"
    },
    "pvsDiagVersion": {
      "type": "integer",
      "minimum": 1,
      "description": "Marker that this is a log from PVS tools, and the format version"
    },
    "detectedCompilers": {
      "$ref": "#/definitions/detectedCompilers"
    },
    "utility": {
      "$ref": "#/definitions/utility"
    },
    "environment": {
      "$ref": "#/definitions/environment"
    },
    "input": {
      "$ref": "#/definitions/input"
    },
    "output": {
      "$ref": "#/definitions/output"
    },
    "basicPerformance": {
      "$ref": "#/definitions/basicPerformance"
    },
    "runs": {
      "$ref": "#/definitions/runs"
    }
  },
  "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": "List of environment variables",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "detectedCompilers": {
      "type": "array",
      "description": "Information about detected compilers",
      "required": [],
      "properties": {
        "filePath": {
          "type": "string",
          "description": "Path to the compiler executable"
        },
        "isDefault": {
          "type": "boolean",
          "description": "If true, the compiler type could not be determined and the default value is used"
        },
        "type": {
          "type": "string",
          "description": "Compiler type"
        },
        "versionInfo": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Compiler version information (most often the output of '--version')"
        }
      }
    },
    "utility": {
      "type": "object",
      "description": "Information about the utility that produced the log",
      "required": [
        "name",
        "path",
        "version",
        "hash",
        "isStable",
        "logVersion"
      ],
      "properties": {
        "name": {
          "type": "string",
          "const": "pvs-studio-analyzer",
          "description": "Human-readable platform-independent utility name"
        },
        "path": {
          "type": "string",
          "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 a release (stable) version"
        },
        "logVersion": {
          "type": "integer",
          "minimum": 1,
          "description": "Versioning of the log format for this specific 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": [
        "annotations",
        "arguments",
        "cwd",
        "projectFile",
        "ruleConfigs",
        "suppressFiles",
        "threads",
        "timestamp",
        "pathSettings",
        "logging"
      ],
      "properties": {
        "annotations": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of paths to annotation files"
        },
        "arguments": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Utility command-line arguments"
        },
        "cwd": {
          "type": "string",
          "description": "Current working directory of the process"
        },
        "projectFile": {
          "type": "string",
          "description": "Data source file for analysis (strace or compile_commands)"
        },
        "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 suppress files (explicit and implicit)"
        },
        "threads": {
          "type": "integer",
          "description": "Actual number of execution threads"
        },
        "timestamp": {
          "$ref": "#/definitions/timepoint",
          "description": "Analyzer start date and time in ISO-8601 UTC+0 format (YYYY-MM-DDThh:mm:ss.sssZ)"
        },
        "pathSettings": {
          "$ref": "#/definitions/pathSettings"
        },
        "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,
          "description": "Logging categories"
        },
        "options": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "skip-sensitive",
              "dump-intermediate-files",
              "embed-runs"
            ]
          },
          "description": "Logging options"
        },
        "sourceLog": {
          "type": "string",
          "description": "Path to the raw log file the structured log was produced from"
        }
      },
      "additionalProperties": false
    },
    "output": {
      "type": "object",
      "description": "Utility results",
      "required": [
        "returnCode",
        "stdout",
        "stderr",
        "anomalies",
        "isFailed"
      ],
      "properties": {
        "returnCode": {
          "type": "integer",
          "description": "Utility exit code"
        },
        "stdout": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "stdout contents (excluding analyzer warnings)"
        },
        "stderr": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "stderr contents (excluding analyzer warnings)"
        },
        "outputFilePath": {
          "type": "string",
          "description": "Path to the raw-json report with findings"
        },
        "stacktraceFile": {
          "type": "string",
          "description": "Path to the stacktrace file"
        },
        "anomalies": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of anomalies diagnosed based on the log"
        },
        "isFailed": {
          "type": "boolean",
          "description": "Whether the utility considers that it completed successfully"
        }
      },
      "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": [
        "order",
        "returnCode"
      ],
      "additionalProperties": true,
      "properties": {
        "details": {
          "type": "object",
          "description": "Detailed information about the executor step"
        },
        "order": {
          "type": "integer",
          "description": "Executor run sequence number"
        },
        "rawLog": {
          "type": "string",
          "description": "Path to the executor log file"
        },
        "returnCode": {
          "$ref": "#/definitions/returnCode",
          "description": "Executor exit code"
        }
      }
    },
    "executorEntry": {
      "type": "object",
      "required": [
        "id"
      ],
      "description": "Information about executors",
      "properties": {
        "dependencies": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of dependent files"
        },
        "id": {
          "type": "string",
          "description": "Executor run identifier (UUID)"
        },
        "inputArgs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Executor command-line arguments"
        },
        "preprocessor": {
          "$ref": "#/definitions/preprocessor"
        },
        "sourceFilePath": {
          "type": "string",
          "description": "Path to the analyzed file"
        },
        "stages": {
          "type": "object",
          "description": "Executor stages",
          "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",
        "skipped"
      ],
      "description": "Information about executors",
      "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 analyzed files"
        },
        "skipped": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/executorEntry"
          },
          "description": "List of files skipped during analysis"
        }
      },
      "additionalProperties": false
    },
    "returnCode": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Utility exit code. May be null."
    },
    "preprocessor": {
      "type": "object",
      "description": "Preprocessor run results",
      "required": [
        "filePath",
        "returnCode",
        "outputFilePath",
        "launchArgs",
        "environment",
        "output"
      ],
      "properties": {
        "filePath": {
          "type": "string",
          "description": "Path to the preprocessor (compiler)"
        },
        "returnCode": {
          "type": "integer",
          "description": "Preprocessor exit code"
        },
        "outputFilePath": {
          "type": "string",
          "description": "Path to the preprocessed file"
        },
        "launchArgs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Preprocessor command-line arguments"
        },
        "environment": {
          "$ref": "#/definitions/envVars",
          "description": "Environment variables for running the preprocessor"
        },
        "output": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Preprocessor output (stdout + stderr)"
        }
      },
      "additionalProperties": false
    }
  }
}
