<div dir="ltr">Hi all,<br><br>I'd liked to get your thoughts on possibly adding a generic key-value store to the profile data formats for 'metadata'. Some potential uses cases:<br><b><br>I. Profile Features</b><br><br>The most basic use could be as a central repository for internal bits of housekeeping information about the profile data. For example, to differentiate between FE and IR instrumentation:<br><br><span style="font-family:monospace,monospace">  llvm.instrumentation_source: "IR"</span><br><br>A key-value store would make it simple to add new bits of information and help keep everything human-readable for the text-based test formats. This could potentially also help with error checking at the llvm-profdata level if the Reader classes exposed it.<br><br><b>II. Profile Context</b><br><br>Basic (lightweight) information about the profile could be automatically gathered at profile time. The idea would be to automatically label profiles with contextual information so that the age/origin of a profile could be inspected using the llvm-profdata tool.<br><br><span style="font-family:monospace,monospace">  $ llvm-profdata show -metadata foo.profdata<br>  llvm.profile_start_time: "2016-01-08T23:41:56.755Z"<br>  llvm.profile_duration: 5.102s<br>  llvm.exe_time: "2016-01-08T23:35:56.745Z"<br>  Total functions: 4<br>  Maximum function count: 866988873<br>  Maximum internal block count: 267914296</span><br><br>Other possibilities: executable path, command line arguments, system info (uname)<br><b><br>III. Custom Content</b><br>  <br>The key-value store itself could be exposed to developers via the llvm-profdata tool. This would allow for users to associate arbitrary custom data with a profile, as well as inspect it:<br>  <br><span style="font-family:monospace,monospace">  $ llvm-profdata merge -metadata=customkey,value1 foo.profraw -o foo.profdata<br>  $ llvm-profdata show -metadata foo.profdata<br>  customkey: "value1"<br>  Total functions: 4<br>  Maximum function count: 866988873<br>  Maximum internal block count: 267914296</span><br><br>Developers could add as much custom context as they find valuable:<br>  <br><span style="font-family:monospace,monospace">  $ llvm-profdata merge -metadata="mysoft.version,${SOFTWARE_VERSION} (${BUILD_NUMBER})" -metadata="mysoft.exe_md5,`md5 -q foo.exe` foo.profraw -o foo.profdata<br>  $ llvm-profdata show -metadata foo.profdata<br>  mysoft.version: "0.1.0"<br>  mysoft.exe_md5: "337b5c5bc29cbdca090a1921a58465d6"<br>  Total functions: 4<br>  Maximum function count: 866988873<br>  Maximum internal block count: 267914296</span><br><br>Other information that might be interesting: git/svn revision, workload description, system info (uname -a)<br><br>This would be a way to embed almost any platform-specific or heavy-weight data without requiring the addition of platform-specific code in compiler-rt and without impacting other developers. <br><br><br>When profiles are merged it might be simplest to keep all input metadata (machine-readable things such as feature bits might need to be handled differently):<br><br><span style="font-family:monospace,monospace">  $ llvm-profdata merge -weighted-input=3,foo.profdata bar.profdata -o foobar.profdata<br>  $ llvm-profdata show -metadata foobar.profdata<br>  foo.profdata<br>    llvm.profile_weight: 3<br>    llvm.profile_start_time: "2016-01-08T23:41:56.755Z"<br>    llvm.profile_duration: 5.102s<br>    llvm.exe_time: "2016-01-08T23:35:56.745Z"<br>    customkey: "value1"<br>  bar.profdata<br>    llvm.profile_weight: 1<br>    llvm.profile_start_time: "2016-01-15T00:08:41.168Z"<br>    llvm.profile_duration: "1.001s"<br>    llvm.exe_time: "2016-01-15T00:08:13.000Z"<br>    customkey: "value2"<br>  Total functions: 4<br>  Maximum function count: 866988873<br>  Maximum internal block count: 267914296</span><br><br>In terms of implementation, the metadata could live as a separate contiguous section in the binary profile formats. It might make sense to encode it in something like YAML so that it could also be directly embedded in the various text formats.<br><br>----<br><br>What do you think? How useful would any of the above be to you or other PGO users?<br>Can you think of any other use cases?<br><br>-Nathan<br></div>