Home | History | Annotate | Download | only in win
      1 // Copyright (c) 2012 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 
      5 // A log file reader can read log files produced by Event Tracing for Windows
      6 // (by way of the FileLogger class) that contain events generated from a select
      7 // few supported providers; see file_logger_win.h for the list.
      8 
      9 #ifndef CHROME_TEST_LOGGING_WIN_LOG_FILE_READER_H_
     10 #define CHROME_TEST_LOGGING_WIN_LOG_FILE_READER_H_
     11 
     12 #include <stddef.h>
     13 #include <windows.h>
     14 #include <wmistr.h>
     15 #include <evntrace.h>
     16 
     17 #include "base/logging.h"
     18 #include "base/strings/string_piece.h"
     19 
     20 namespace base {
     21 class FilePath;
     22 }
     23 
     24 namespace logging_win {
     25 
     26 // An interface to classes interested in taking action based on events parsed
     27 // out of a log file created by the FileLogger.
     28 class LogFileDelegate {
     29  public:
     30   virtual ~LogFileDelegate();
     31 
     32   // Invoked for event types not currently handled by the parser.
     33   virtual void OnUnknownEvent(const EVENT_TRACE* event) = 0;
     34 
     35   // Invoked for events of known types that cannot be parsed due to unexpected
     36   // data.
     37   virtual void OnUnparsableEvent(const EVENT_TRACE* event) = 0;
     38 
     39   // Invoked for the header at the front of all log files.
     40   virtual void OnFileHeader(const EVENT_TRACE* event,
     41                             const TRACE_LOGFILE_HEADER* header) = 0;
     42 
     43   // Invoked for simple log messages produced by LogEventProvider.
     44   virtual void OnLogMessage(const EVENT_TRACE* event,
     45                             logging::LogSeverity severity,
     46                             const base::StringPiece& message) = 0;
     47 
     48   // Invoked for full log messages produced by LogEventProvider.
     49   virtual void OnLogMessageFull(const EVENT_TRACE* event,
     50                                 logging::LogSeverity severity,
     51                                 DWORD stack_depth,
     52                                 const intptr_t* backtrace,
     53                                 int line,
     54                                 const base::StringPiece& file,
     55                                 const base::StringPiece& message) = 0;
     56 
     57   // Invoked for trace events produced by TraceEventETWProvider.
     58   virtual void OnTraceEvent(const EVENT_TRACE* event,
     59                             const base::StringPiece& name,
     60                             char type,
     61                             intptr_t id,
     62                             const base::StringPiece& extra,
     63                             DWORD stack_depth,
     64                             const intptr_t* backtrace) = 0;
     65 
     66  protected:
     67   LogFileDelegate();
     68 };
     69 
     70 // Reads |log_file|, invoking appropriate methods on |delegate| as events are
     71 // parsed.  Although it is safe to call this from multiple threads, only one
     72 // file may be read at a time; other threads trying to read other log files will
     73 // be blocked waiting.
     74 void ReadLogFile(const base::FilePath& log_file, LogFileDelegate* delegate);
     75 
     76 }  // namespace logging_win
     77 
     78 #endif  // CHROME_TEST_LOGGING_WIN_LOG_FILE_READER_H_
     79