diff options
author | David Malcolm <dmalcolm@redhat.com> | 2023-07-31 11:13:02 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-07-31 11:13:02 -0400 |
commit | 75d623946d4b6ea80a777b789b116d4b4a2298dc (patch) | |
tree | 09fd7297586bd0c2b71502e834430b9441d4e2ae /gcc/diagnostic-client-data-hooks.h | |
parent | a104e9ac0ae9a7e78ec2edd0b81074946646a87d (diff) | |
download | gcc-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/diagnostic-client-data-hooks.h')
-rw-r--r-- | gcc/diagnostic-client-data-hooks.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/diagnostic-client-data-hooks.h b/gcc/diagnostic-client-data-hooks.h index 5f8b9a2..e3f2d05 100644 --- a/gcc/diagnostic-client-data-hooks.h +++ b/gcc/diagnostic-client-data-hooks.h @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H #define GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H +class sarif_object; class client_version_info; /* A bundle of additional metadata, owned by the diagnostic_context, @@ -41,6 +42,11 @@ class diagnostic_client_data_hooks See SARIF v2.1.0 Appendix J for suggested values. */ virtual const char * maybe_get_sarif_source_language (const char *filename) const = 0; + + /* Hook to allow client to populate a SARIF "invocation" object with + a custom property bag (see SARIF v2.1.0 section 3.8). */ + virtual void + add_sarif_invocation_properties (sarif_object &invocation_obj) const = 0; }; /* Factory function for making an instance of diagnostic_client_data_hooks |