| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h" | 5 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // Gathers log data from various scripts/programs. | 25 // Gathers log data from various scripts/programs. |
| 26 void ExecuteCommandLines(system_logs::SystemLogsResponse* response) { | 26 void ExecuteCommandLines(system_logs::SystemLogsResponse* response) { |
| 27 // TODO(tudalex): Move program calling in a array or something similar to make | 27 // TODO(tudalex): Move program calling in a array or something similar to make |
| 28 // it more easier to modify and understand. | 28 // it more easier to modify and understand. |
| 29 std::vector<std::pair<std::string, base::CommandLine>> commands; | 29 std::vector<std::pair<std::string, base::CommandLine>> commands; |
| 30 | 30 |
| 31 base::CommandLine command(base::FilePath("/usr/bin/amixer")); | 31 base::CommandLine command(base::FilePath("/usr/bin/amixer")); |
| 32 command.AppendArg("-c0"); | 32 command.AppendArg("-c0"); |
| 33 command.AppendArg("contents"); | 33 command.AppendArg("contents"); |
| 34 commands.push_back(std::make_pair("alsa controls", command)); | 34 commands.emplace_back("alsa controls", command); |
| 35 | 35 |
| 36 command = base::CommandLine((base::FilePath("/usr/bin/cras_test_client"))); | 36 command = base::CommandLine((base::FilePath("/usr/bin/cras_test_client"))); |
| 37 command.AppendArg("--dump_server_info"); | 37 command.AppendArg("--dump_server_info"); |
| 38 command.AppendArg("--dump_audio_thread"); | 38 command.AppendArg("--dump_audio_thread"); |
| 39 commands.push_back(std::make_pair("cras", command)); | 39 commands.emplace_back("cras", command); |
| 40 | 40 |
| 41 command = base::CommandLine((base::FilePath("/usr/bin/audio_diagnostics"))); | 41 command = base::CommandLine((base::FilePath("/usr/bin/audio_diagnostics"))); |
| 42 commands.push_back(std::make_pair("audio_diagnostics", command)); | 42 commands.emplace_back("audio_diagnostics", command); |
| 43 | 43 |
| 44 #if 0 | 44 #if 0 |
| 45 // This command hangs as of R39. TODO(alhli): Make cras_test_client more | 45 // This command hangs as of R39. TODO(alhli): Make cras_test_client more |
| 46 // robust or add a wrapper script that times out, and fix this or remove | 46 // robust or add a wrapper script that times out, and fix this or remove |
| 47 // this code. crbug.com/419523 | 47 // this code. crbug.com/419523 |
| 48 command = base::CommandLine((base::FilePath("/usr/bin/cras_test_client"))); | 48 command = base::CommandLine((base::FilePath("/usr/bin/cras_test_client"))); |
| 49 command.AppendArg("--loopback_file"); | 49 command.AppendArg("--loopback_file"); |
| 50 command.AppendArg("/dev/null"); | 50 command.AppendArg("/dev/null"); |
| 51 command.AppendArg("--rate"); | 51 command.AppendArg("--rate"); |
| 52 command.AppendArg("44100"); | 52 command.AppendArg("44100"); |
| 53 command.AppendArg("--duration_seconds"); | 53 command.AppendArg("--duration_seconds"); |
| 54 command.AppendArg("0.01"); | 54 command.AppendArg("0.01"); |
| 55 command.AppendArg("--show_total_rms"); | 55 command.AppendArg("--show_total_rms"); |
| 56 commands.push_back(std::make_pair("cras_rms", command)); | 56 commands.emplace_back("cras_rms", command); |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 command = base::CommandLine((base::FilePath("/usr/bin/printenv"))); | 59 command = base::CommandLine((base::FilePath("/usr/bin/printenv"))); |
| 60 commands.push_back(std::make_pair("env", command)); | 60 commands.emplace_back("env", command); |
| 61 | 61 |
| 62 #if defined(USE_X11) | 62 #if defined(USE_X11) |
| 63 command = base::CommandLine(base::FilePath("/usr/bin/xrandr")); | 63 command = base::CommandLine(base::FilePath("/usr/bin/xrandr")); |
| 64 command.AppendArg("--verbose"); | 64 command.AppendArg("--verbose"); |
| 65 commands.push_back(std::make_pair("xrandr", command)); | 65 commands.emplace_back("xrandr", command); |
| 66 #elif defined(USE_OZONE) | 66 #elif defined(USE_OZONE) |
| 67 command = base::CommandLine(base::FilePath("/usr/bin/modetest")); | 67 command = base::CommandLine(base::FilePath("/usr/bin/modetest")); |
| 68 commands.push_back(std::make_pair("modetest", command)); | 68 commands.emplace_back("modetest", command); |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 // Get a list of file sizes for the whole system (excluding the names of the | 71 // Get a list of file sizes for the whole system (excluding the names of the |
| 72 // files in the Downloads directory for privay reasons). | 72 // files in the Downloads directory for privay reasons). |
| 73 if (base::SysInfo::IsRunningOnChromeOS()) { | 73 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 74 // The following command would hang if run in Linux Chrome OS build on a | 74 // The following command would hang if run in Linux Chrome OS build on a |
| 75 // Linux Workstation. | 75 // Linux Workstation. |
| 76 command = base::CommandLine(base::FilePath("/bin/sh")); | 76 command = base::CommandLine(base::FilePath("/bin/sh")); |
| 77 command.AppendArg("-c"); | 77 command.AppendArg("-c"); |
| 78 command.AppendArg( | 78 command.AppendArg( |
| 79 "/usr/bin/du -h / | grep -v -e \\/home\\/.*\\/Downloads\\/"); | 79 "/usr/bin/du -h --max-depth=5 /home/ /mnt/stateful_partition/ | " |
| 80 commands.push_back(std::make_pair("system_files", command)); | 80 "grep -v -e Downloads"); |
| 81 commands.emplace_back("system_files", command); |
| 81 } | 82 } |
| 82 | 83 |
| 83 // Track the list of plugged-in USB devices. | 84 // Track the list of plugged-in USB devices. |
| 84 command = base::CommandLine(base::FilePath("/bin/sh")); | 85 command = base::CommandLine(base::FilePath("/bin/sh")); |
| 85 command.AppendArg("-c"); | 86 command.AppendArg("-c"); |
| 86 command.AppendArg("/usr/bin/lsusb -t"); | 87 command.AppendArg("/usr/bin/lsusb -t"); |
| 87 commands.emplace_back("usb_devices", command); | 88 commands.emplace_back("usb_devices", command); |
| 88 | 89 |
| 89 // Get disk space usage information | 90 // Get disk space usage information |
| 90 command = base::CommandLine(base::FilePath("/bin/df")); | 91 command = base::CommandLine(base::FilePath("/bin/df")); |
| 91 commands.push_back(std::make_pair("disk_usage", command)); | 92 commands.emplace_back("disk_usage", command); |
| 92 | 93 |
| 93 for (size_t i = 0; i < commands.size(); ++i) { | 94 for (const auto& command : commands) { |
| 94 VLOG(1) << "Executting System Logs Command: " << commands[i].first; | 95 VLOG(1) << "Executting System Logs Command: " << command.first; |
| 95 std::string output; | 96 std::string output; |
| 96 base::GetAppOutput(commands[i].second, &output); | 97 base::GetAppOutput(command.second, &output); |
| 97 (*response)[commands[i].first] = output; | 98 response->emplace(command.first, output); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace | 102 } // namespace |
| 102 | 103 |
| 103 namespace system_logs { | 104 namespace system_logs { |
| 104 | 105 |
| 105 CommandLineLogSource::CommandLineLogSource() : SystemLogsSource("CommandLine") { | 106 CommandLineLogSource::CommandLineLogSource() : SystemLogsSource("CommandLine") { |
| 106 } | 107 } |
| 107 | 108 |
| 108 CommandLineLogSource::~CommandLineLogSource() { | 109 CommandLineLogSource::~CommandLineLogSource() { |
| 109 } | 110 } |
| 110 | 111 |
| 111 void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) { | 112 void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 DCHECK(!callback.is_null()); | 114 DCHECK(!callback.is_null()); |
| 114 | 115 |
| 115 SystemLogsResponse* response = new SystemLogsResponse; | 116 SystemLogsResponse* response = new SystemLogsResponse; |
| 116 base::PostTaskWithTraitsAndReply(FROM_HERE, | 117 base::PostTaskWithTraitsAndReply(FROM_HERE, |
| 117 base::TaskTraits().MayBlock().WithPriority( | 118 base::TaskTraits().MayBlock().WithPriority( |
| 118 base::TaskPriority::BACKGROUND), | 119 base::TaskPriority::BACKGROUND), |
| 119 base::Bind(&ExecuteCommandLines, response), | 120 base::Bind(&ExecuteCommandLines, response), |
| 120 base::Bind(callback, base::Owned(response))); | 121 base::Bind(callback, base::Owned(response))); |
| 121 } | 122 } |
| 122 | 123 |
| 123 } // namespace system_logs | 124 } // namespace system_logs |
| OLD | NEW |