cmake: add command line options to output script profiling data

For users of CMake who want to optimize their scripts if they take a
while to run, this commit adds the ability to output profiling data.

To enable this output, it adds the two command line parameters
to select the output path and format.

This commit adds the first profiling format of type ``google-trace``,
which is the output is a JSON file containing Duration events as per the
Google Trace Format specification:

https://docs.google.com/document/d/1CvAClvFfyA5R-
PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#
This commit is contained in:
Wouter Klouwen
2019-02-02 09:06:36 +00:00
parent 8f122b4557
commit 9aa4640792
20 changed files with 304 additions and 2 deletions
@@ -0,0 +1,18 @@
if (NOT EXISTS ${ProfilingTestOutput})
set(RunCMake_TEST_FAILED "Expected ${ProfilingTestOutput} to exists")
endif()
file(READ "${ProfilingTestOutput}" JSON_HEADER LIMIT 2)
if (NOT JSON_HEADER MATCHES "^\\[{")
set(RunCMake_TEST_FAILED "Expected valid JSON start")
return()
endif()
file(SIZE "${ProfilingTestOutput}" OUTPUT_SIZE)
math(EXPR END_OFFSET "${OUTPUT_SIZE} -2 ")
file(READ "${ProfilingTestOutput}" JSON_TRAILER OFFSET ${END_OFFSET})
if (NOT JSON_TRAILER MATCHES "^}]$")
set(RunCMake_TEST_FAILED "Expected valid JSON end")
return()
endif()
@@ -0,0 +1 @@
# This file is intentionally left blank
@@ -697,3 +697,25 @@ function(run_llvm_rc)
unset(LLVMRC_RESULT)
endfunction()
run_llvm_rc()
set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt --profiling-format=google-trace)
run_cmake(profiling-all-params)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt --profiling-format=invalid-format)
run_cmake(profiling-invalid-format)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_OPTIONS --profiling-output=/no/such/file.txt)
run_cmake(profiling-missing-format)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_OPTIONS --profiling-format=google-trace)
run_cmake(profiling-missing-output)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/profiling-test")
set(ProfilingTestOutput ${RunCMake_TEST_BINARY_DIR}/output.json)
set(RunCMake_TEST_OPTIONS --profiling-format=google-trace --profiling-output=${ProfilingTestOutput})
run_cmake(ProfilingTest)
unset(RunCMake_TEST_OPTIONS)
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
^.*Could not start profiling: Unable to open: /no/such/file.txt$
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
^.*Invalid format specified for --profiling-format$
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
^.*Invalid format specified for --profiling-format$
@@ -0,0 +1 @@
1
@@ -0,0 +1 @@
^.*--profiling-format specified but no --profiling-output!$