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 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h" 6 7 #include <string> 8 #include <vector> 9 10 #include "base/bind.h" 11 #include "base/command_line.h" 12 #include "base/files/file_path.h" 13 #include "base/logging.h" 14 #include "base/process/launch.h" 15 #include "content/public/browser/browser_thread.h" 16 17 using content::BrowserThread; 18 19 namespace { 20 21 // Gathers log data from various scripts/programs. 22 void ExecuteCommandLines(system_logs::SystemLogsResponse* response) { 23 // TODO(tudalex): Move program calling in a array or something similar to make 24 // it more easier to modify and understand. 25 std::vector<std::pair<std::string, CommandLine> > commands; 26 27 CommandLine command(base::FilePath("/usr/bin/amixer")); 28 command.AppendArg("-c0"); 29 command.AppendArg("contents"); 30 commands.push_back(std::make_pair("alsa controls", command)); 31 32 command = CommandLine((base::FilePath("/usr/bin/cras_test_client"))); 33 command.AppendArg("--dump_server_info"); 34 command.AppendArg("--dump_audio_thread"); 35 commands.push_back(std::make_pair("cras", command)); 36 37 command = CommandLine((base::FilePath("/usr/bin/audio_diagnostics"))); 38 commands.push_back(std::make_pair("audio_diagnostics", command)); 39 40 #if 0 41 // This command hangs as of R39. TODO(alhli): Make cras_test_client more 42 // robust or add a wrapper script that times out, and fix this or remove 43 // this code. crbug.com/419523 44 command = CommandLine((base::FilePath("/usr/bin/cras_test_client"))); 45 command.AppendArg("--loopback_file"); 46 command.AppendArg("/dev/null"); 47 command.AppendArg("--rate"); 48 command.AppendArg("44100"); 49 command.AppendArg("--duration_seconds"); 50 command.AppendArg("0.01"); 51 command.AppendArg("--show_total_rms"); 52 commands.push_back(std::make_pair("cras_rms", command)); 53 #endif 54 55 command = CommandLine((base::FilePath("/usr/bin/printenv"))); 56 commands.push_back(std::make_pair("env", command)); 57 58 command = CommandLine(base::FilePath("/usr/bin/setxkbmap")); 59 command.AppendArg("-print"); 60 command.AppendArg("-query"); 61 commands.push_back(std::make_pair("setxkbmap", command)); 62 63 command = CommandLine(base::FilePath("/usr/bin/xinput")); 64 command.AppendArg("list"); 65 command.AppendArg("--long"); 66 commands.push_back(std::make_pair("xinput", command)); 67 68 command = CommandLine(base::FilePath("/usr/bin/xrandr")); 69 command.AppendArg("--verbose"); 70 commands.push_back(std::make_pair("xrandr", command)); 71 72 // Get a list of file sizes for the logged in user (excluding the names of 73 // the files in the Downloads directory for privay reasons). 74 command = CommandLine(base::FilePath("/bin/sh")); 75 command.AppendArg("-c"); 76 command.AppendArg("/usr/bin/du -h /home/chronos/user |" 77 " grep -v -e \\/home\\/chronos\\/user\\/Downloads\\/"); 78 commands.push_back(std::make_pair("user_files", command)); 79 80 for (size_t i = 0; i < commands.size(); ++i) { 81 std::string output; 82 base::GetAppOutput(commands[i].second, &output); 83 (*response)[commands[i].first] = output; 84 } 85 } 86 87 } // namespace 88 89 namespace system_logs { 90 91 void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) { 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 93 DCHECK(!callback.is_null()); 94 95 SystemLogsResponse* response = new SystemLogsResponse; 96 BrowserThread::PostBlockingPoolTaskAndReply( 97 FROM_HERE, 98 base::Bind(&ExecuteCommandLines, response), 99 base::Bind(callback, base::Owned(response))); 100 } 101 102 } // namespace system_logs 103