Coverage for /Syzygy/trace/etw_control/call_trace_control_main.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
0.0%0091.C++source

Line-by-line coverage:

   1    :  // Copyright 2012 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  //
  15    :  // A utility for controlling call-traces from the command-line.
  16    :  #include <iostream>
  17    :  #include "base/at_exit.h"
  18    :  #include "base/command_line.h"
  19    :  #include "base/logging.h"
  20    :  #include "syzygy/trace/etw_control/call_trace_control.h"
  21    :  
  22  m :  static const char kUsage[] =
  23  m :      "Usage: call_trace_control [command] [options]\n"
  24  m :      "Commands:\n"
  25  m :      "  start: start the call-trace, creating the ETW logs.\n"
  26  m :      "  query: query the call-trace status.\n"
  27  m :      "  stop: stop the call-trace, flushing and closing the ETW logs.\n"
  28  m :      "\n"
  29  m :      "Options to 'start':\n"
  30  m :      "  --append: Append to the ETW log files rather than overwriting them.\n"
  31  m :      "  --call-trace-file: Path to call-trace ETW log file.\n"
  32  m :      "      Defaults to 'call_trace.etl' in the current working directory.\n"
  33  m :      "  --chrome-file: Path to Chrome ETW log file.\n"
  34  m :      "      If not specified, does not enable Chrome ETW logging.\n"
  35  m :      "  --min-buffers: The minimum number of buffers to use for call-trace.\n"
  36  m :      "      Augment this from the defaults if seeing lost events.\n"
  37  m :      "  --kernel-file: Path to kernel ETW log file.\n"
  38  m :      "      Defaults to 'kernel.etl' in the current working directory.\n"
  39  m :      "  --kernel-flags: Flags to pass to kernel ETW logger (numeric).\n"
  40  m :      "      Defaults to PROCESS|THREAD|IMAGE_LOAD|DISK_IO|DISK_FILE_IO|\n"
  41  m :      "                  MEMORY_PAGE_FAULTS|MEMORY_HARD_FAULTS|FILE_IO.\n";
  42    :  
  43  m :  int Usage() {
  44  m :    std::cout << kUsage;
  45  m :    return 1;
  46  m :  }
  47    :  
  48  m :  enum Command {
  49  m :    kStart,
  50  m :    kQuery,
  51  m :    kStop,
  52  m :  };
  53    :  
  54  m :  struct Options {
  55  m :    Command command;
  56  m :  };
  57    :  
  58  m :  bool ParseOptions(Options* options) {
  59  m :    DCHECK(options != NULL);
  60    :  
  61  m :    CommandLine* cmd_line = CommandLine::ForCurrentProcess();
  62    :  
  63  m :    if (cmd_line->HasSwitch("help") || cmd_line->HasSwitch("h")) {
  64  m :      Usage();
  65  m :      return false;
  66  m :    }
  67    :  
  68  m :    if (cmd_line->GetArgs().size() == 0) {
  69  m :      LOG(ERROR) << "Must specify a command.";
  70  m :      return false;
  71  m :    }
  72    :  
  73  m :    if (cmd_line->GetArgs().size() > 1) {
  74  m :      LOG(ERROR) << "Can only specify one command.";
  75  m :      return false;
  76  m :    }
  77    :  
  78  m :    if (cmd_line->GetArgs()[0] == L"start") {
  79  m :      options->command = kStart;
  80  m :    } else if (cmd_line->GetArgs()[0] == L"query") {
  81  m :      options->command = kQuery;
  82  m :    } else if (cmd_line->GetArgs()[0] == L"stop") {
  83  m :      options->command = kStop;
  84  m :    } else {
  85  m :      LOG(ERROR) << "Unknown command: " << cmd_line->GetArgs()[0] << ".";
  86  m :      return false;
  87  m :    }
  88    :  
  89  m :    return true;
  90  m :  }
  91    :  
  92  m :  int main(int argc, char** argv) {
  93  m :    base::AtExitManager at_exit;
  94  m :    CommandLine::Init(argc, argv);
  95    :  
  96  m :    logging::LoggingSettings settings;
  97  m :    settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
  98  m :    settings.lock_log = logging::DONT_LOCK_LOG_FILE;
  99  m :    settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
 100  m :    if (!logging::InitLogging(settings))
 101  m :      return 1;
 102    :  
 103  m :    Options options;
 104  m :    if (!ParseOptions(&options))
 105  m :      return 1;
 106    :  
 107    :    // Call the command we care about.
 108  m :    bool success = false;
 109  m :    switch (options.command) {
 110  m :      case kStart: {
 111  m :        success = StartCallTraceImpl();
 112  m :        break;
 113  m :      }
 114    :  
 115  m :      case kQuery: {
 116  m :        success = QueryCallTraceImpl();
 117  m :        break;
 118  m :      }
 119    :  
 120  m :      case kStop: {
 121  m :        success = StopCallTraceImpl();
 122  m :        break;
 123  m :      }
 124    :  
 125  m :      default: {
 126  m :        NOTREACHED() << "Unexpected command.";
 127  m :      }
 128  m :    }
 129    :  
 130  m :    return success ? 0 : 1;
 131  m :  }

Coverage information generated Thu Mar 26 16:15:41 2015.