aboutsummaryrefslogtreecommitdiff
path: root/gcc/po
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2023-07-31 11:13:02 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2023-07-31 11:13:02 -0400
commit75d623946d4b6ea80a777b789b116d4b4a2298dc (patch)
tree09fd7297586bd0c2b71502e834430b9441d4e2ae /gcc/po
parenta104e9ac0ae9a7e78ec2edd0b81074946646a87d (diff)
downloadgcc-75d623946d4b6ea80a777b789b116d4b4a2298dc.zip
gcc-75d623946d4b6ea80a777b789b116d4b4a2298dc.tar.gz
gcc-75d623946d4b6ea80a777b789b116d4b4a2298dc.tar.bz2
SARIF and -ftime-report's output [PR109361]
This patch adds support for embeddding profiling information about the compiler itself into the SARIF output. Specifically, if SARIF diagnostic output is requested, via -fdiagnostics-format=sarif-file or -fdiagnostics-format=sarif-stderr, then any -ftime-report output is written in JSON form into the SARIF output, rather than to stderr. In earlier versions of this patch I extended -ftime-report so that *as well* as writing to stderr, it would embed the information in any SARIF output. This turned out to be awkward to use, in that I found myself needing to get the data in JSON form without also having it emitted on stderr (which was fouling my build scripts). The timing information is written to the SARIF as a "gcc/timeReport" property within a property bag of the "invocation" object. Here's an example of the output: "invocations": [ { "executionSuccessful": true, "toolExecutionNotifications": [], "properties": { "gcc/timeReport": { "timevars": [ { "name": "phase setup", "elapsed": { "user": 0.04, "sys": 0, "wall": 0.04, "ggc_mem": 1863472 } }, [...snip...] { "name": "analyzer: processing worklist", "elapsed": { "user": 0.06, "sys": 0, "wall": 0.06, "ggc_mem": 48 } }, { "name": "analyzer: emitting diagnostics", "elapsed": { "user": 0.01, "sys": 0, "wall": 0.01, "ggc_mem": 0 } }, { "name": "TOTAL", "elapsed": { "user": 0.21, "sys": 0.03, "wall": 0.24, "ggc_mem": 3368736 } } ], "CHECKING_P": true, "flag_checking": true } } } ] The documentation notes that the precise output format is subject to change. I have successfully used this in my analyzer integration tests to get timing information about which source files get slowed down by the analyzer. I've validated the generated .sarif files against the SARIF schema. gcc/ChangeLog: PR analyzer/109361 * diagnostic-client-data-hooks.h (class sarif_object): New forward decl. (diagnostic_client_data_hooks::add_sarif_invocation_properties): New vfunc. * diagnostic-format-sarif.cc: Include "diagnostic-format-sarif.h". (class sarif_invocation): Inherit from sarif_object rather than json::object. (class sarif_result): Likewise. (class sarif_ice_notification): Likewise. (sarif_object::get_or_create_properties): New. (sarif_invocation::prepare_to_flush): Add "context" param. Use it to call the context's add_sarif_invocation_properties hook. (sarif_builder::flush_to_file): Pass m_context to sarif_invocation::prepare_to_flush. * diagnostic-format-sarif.h: New header. * doc/invoke.texi (Developer Options): Clarify that -ftime-report writes to stderr. Document that if SARIF diagnostic output is requested then any timing information is written in JSON form as part of the SARIF output, rather than to stderr. * timevar.cc: Include "json.h". (timer::named_items::m_hash_map): Split out type into... (timer::named_items::hash_map_t): ...this new typedef. (timer::named_items::make_json): New function. (timevar_diff): New function. (make_json_for_timevar_time_def): New function. (timer::timevar_def::make_json): New function. (timer::make_json): New function. * timevar.h (class json::value): New forward decl. (timer::make_json): New decl. (timer::timevar_def::make_json): New decl. * tree-diagnostic-client-data-hooks.cc: Include "diagnostic-format-sarif.h" and "timevar.h". (compiler_data_hooks::add_sarif_invocation_properties): New vfunc implementation. gcc/testsuite/ChangeLog: PR analyzer/109361 * c-c++-common/diagnostic-format-sarif-file-timevars-1.c: New test. * c-c++-common/diagnostic-format-sarif-file-timevars-2.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/po')
0 files changed, 0 insertions, 0 deletions