fetch_system_session_events_main_win.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // A utility for testing locally the retrieval of system session events.
  5. #include <iostream>
  6. #include "base/strings/stringprintf.h"
  7. #include "base/time/time.h"
  8. #include "components/metrics/system_session_analyzer/system_session_analyzer_win.h"
  9. namespace {
  10. using metrics::SystemSessionAnalyzer;
  11. class SystemSessionEventFetcher : public SystemSessionAnalyzer {
  12. public:
  13. explicit SystemSessionEventFetcher() : SystemSessionAnalyzer(0) {}
  14. using SystemSessionAnalyzer::FetchEvents;
  15. };
  16. } // namespace
  17. int main(int argc, char** argv) {
  18. SystemSessionEventFetcher fetcher;
  19. std::vector<SystemSessionEventFetcher::EventInfo> events;
  20. // Retrieve events for the last 5 sessions. We expect our own sessions start
  21. // event, and then 2 events per each preceding session for 11 total.
  22. if (!fetcher.FetchEvents(11U, &events)) {
  23. std::cerr << "Failed to fetch events." << std::endl;
  24. return 1;
  25. }
  26. // Print the event ids and times.
  27. for (const SystemSessionEventFetcher::EventInfo& event : events) {
  28. base::Time::Exploded exploded = {};
  29. event.event_time.LocalExplode(&exploded);
  30. std::string time = base::StringPrintf(
  31. "%d/%d/%d %d:%02d:%02d", exploded.month, exploded.day_of_month,
  32. exploded.year, exploded.hour, exploded.minute, exploded.second);
  33. std::cout << "Event: " << event.event_id << " (" << time << ")"
  34. << std::endl;
  35. }
  36. return 0;
  37. }