{"action":"created","issue":{"url":"https://api.github.com/repos/google/benchmark/issues/262","repository_url":"https://api.github.com/repos/google/benchmark","labels_url":"https://api.github.com/repos/google/benchmark/issues/262/labels{/name}","comments_url":"https://api.github.com/repos/google/benchmark/issues/262/comments","events_url":"https://api.github.com/repos/google/benchmark/issues/262/events","html_url":"https://github.com/google/benchmark/pull/262","id":167156317,"number":262,"title":"Add user-defined counters.","user":{"login":"biojppm","id":325344,"avatar_url":"https://avatars.githubusercontent.com/u/325344?v=3","gravatar_id":"","url":"https://api.github.com/users/biojppm","html_url":"https://github.com/biojppm","followers_url":"https://api.github.com/users/biojppm/followers","following_url":"https://api.github.com/users/biojppm/following{/other_user}","gists_url":"https://api.github.com/users/biojppm/gists{/gist_id}","starred_url":"https://api.github.com/users/biojppm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biojppm/subscriptions","organizations_url":"https://api.github.com/users/biojppm/orgs","repos_url":"https://api.github.com/users/biojppm/repos","events_url":"https://api.github.com/users/biojppm/events{/privacy}","received_events_url":"https://api.github.com/users/biojppm/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/benchmark/labels/cla:%20yes","name":"cla: yes","color":"009800"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2016-07-23T00:27:30Z","updated_at":"2016-08-03T23:38:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/google/benchmark/pulls/262","html_url":"https://github.com/google/benchmark/pull/262","diff_url":"https://github.com/google/benchmark/pull/262.diff","patch_url":"https://github.com/google/benchmark/pull/262.patch"},"body":"This PR adds user-defined counters, as discussed in issue #240 . I've added usage notes to the README.md file.\r\n\r\nThis was implemented mainly by adding two classes: `BenchmarkCounters` which is responsible for managing the collection of counters and `Counter` which contains logic for each individual counter. `BenchmarkCounters` objects can be summed up to aggregate multithread benchmark results. Then I added a `BenchmarkCounters` member to `State` and `Run`, which are accessible as needed.\r\n\r\nThough the changes in this PR generally adhere to the gist of the discussion in issue #240 , I've opted to leave the bytes_processed and items_processed as they previously were. In an early commit I did move these quantities to the `BenchmarkCounters` class, but otherwise noted that these changes were maybe a bit too far-reaching for what I wanted to do here. As an illustration of the resulting approach, I left some of this code commented out (eg, see src/benchmark.cc:470).\r\n\r\nI added two methods to the `Fixture` class: `InitState()` and `TerminateState()`. These were needed to change the state before and after the benchmark. They receive a non-const reference to benchmark::State so that they start and stop hardware counters as needed. I did this instead of changing the State constness in `Setup()` and `TearDown()` to retain compatibility. See src/benchmark.cc:758.\r\n\r\nThe JSON reporter was the easiest to adapt. The Console and CSV reporters had the part printing the header moved out of `Reporter::PrintContext()`. In the console reporter, I store the previously-printed header, and check on each Run whether the header is different; if it is then a new header is printed. The printing of header inside the table was not immediately clear, so I added another separator line filled with '-' before the names; this makes the in-table headers more visible by separating them more clearly from the results above. In the CSV reporter, I gather first all the fields in a set, and then print counters (or nothing) based on this set. This set is local so that part is done outside of the `PrintRunData()` method which I promptly recognize as awkward. See src/csv_reporter.cc:80 below.\r\n\r\nNote that I needed to add `#includes of <utility>,<vector>,<string> and <initializer_list>` (this last only when compiling in C++11) to the benchmark_api.h file. If you do not want this, let me know, or just feel free to suggest alternative approaches that would obviate these includes.\r\n\r\nAll the existing unit tests are passed successfully. I added also another test showing use with the PAPI library, but will do a separate PR for that, after this one is closed. Also, I did not add new specific tests for the user counters. If this PR is approved, then we'll discuss what to test for.\r\n\r\nPlease let me know if something in the code of this PR should be changed. For example, maybe `BenchmarkCounters` could be called `UserCounters`. Also, I tried to be faithful to the style of this project, but if for any reason something was overlooked feel free to point it out; I'll gladly correct it. \r\n"},"comment":{"url":"https://api.github.com/repos/google/benchmark/issues/comments/237408193","html_url":"https://github.com/google/benchmark/pull/262#issuecomment-237408193","issue_url":"https://api.github.com/repos/google/benchmark/issues/262","id":237408193,"user":{"login":"AppVeyorBot","id":17834419,"avatar_url":"https://avatars.githubusercontent.com/u/17834419?v=3","gravatar_id":"","url":"https://api.github.com/users/AppVeyorBot","html_url":"https://github.com/AppVeyorBot","followers_url":"https://api.github.com/users/AppVeyorBot/followers","following_url":"https://api.github.com/users/AppVeyorBot/following{/other_user}","gists_url":"https://api.github.com/users/AppVeyorBot/gists{/gist_id}","starred_url":"https://api.github.com/users/AppVeyorBot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AppVeyorBot/subscriptions","organizations_url":"https://api.github.com/users/AppVeyorBot/orgs","repos_url":"https://api.github.com/users/AppVeyorBot/repos","events_url":"https://api.github.com/users/AppVeyorBot/events{/privacy}","received_events_url":"https://api.github.com/users/AppVeyorBot/received_events","type":"User","site_admin":false},"created_at":"2016-08-03T23:38:00Z","updated_at":"2016-08-03T23:38:00Z","body":":x: [Build benchmark 291 failed](https://ci.appveyor.com/project/google/benchmark/build/291) (commit https://github.com/google/benchmark/commit/c5b32e5591 by @jppm)"}}
{"actor":{"display_login":"AppVeyorBot"}}