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.
5 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h"
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"
17 using content::BrowserThread
;
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
, base::CommandLine
>> commands
;
27 base::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
));
32 command
= base::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
));
37 command
= base::CommandLine((base::FilePath("/usr/bin/audio_diagnostics")));
38 commands
.push_back(std::make_pair("audio_diagnostics", command
));
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
= base::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
));
55 command
= base::CommandLine((base::FilePath("/usr/bin/printenv")));
56 commands
.push_back(std::make_pair("env", command
));
58 command
= base::CommandLine(base::FilePath("/usr/bin/setxkbmap"));
59 command
.AppendArg("-print");
60 command
.AppendArg("-query");
61 commands
.push_back(std::make_pair("setxkbmap", command
));
63 command
= base::CommandLine(base::FilePath("/usr/bin/xinput"));
64 command
.AppendArg("list");
65 command
.AppendArg("--long");
66 commands
.push_back(std::make_pair("xinput", command
));
69 command
= base::CommandLine(base::FilePath("/usr/bin/xrandr"));
70 command
.AppendArg("--verbose");
71 commands
.push_back(std::make_pair("xrandr", command
));
72 #elif defined(USE_OZONE)
73 command
= base::CommandLine(base::FilePath("/usr/bin/modetest"));
74 commands
.push_back(std::make_pair("modetest", command
));
77 // Get a list of file sizes for the logged in user (excluding the names of
78 // the files in the Downloads directory for privay reasons).
79 command
= base::CommandLine(base::FilePath("/bin/sh"));
80 command
.AppendArg("-c");
81 command
.AppendArg("/usr/bin/du -h /home/chronos/user |"
82 " grep -v -e \\/home\\/chronos\\/user\\/Downloads\\/");
83 commands
.push_back(std::make_pair("user_files", command
));
85 // Get disk space usage information
86 command
= base::CommandLine(base::FilePath("/bin/df"));
87 commands
.push_back(std::make_pair("disk_usage", command
));
89 for (size_t i
= 0; i
< commands
.size(); ++i
) {
90 VLOG(1) << "Executting System Logs Command: " << commands
[i
].first
;
92 base::GetAppOutput(commands
[i
].second
, &output
);
93 (*response
)[commands
[i
].first
] = output
;
99 namespace system_logs
{
101 CommandLineLogSource::CommandLineLogSource() : SystemLogsSource("CommandLine") {
104 CommandLineLogSource::~CommandLineLogSource() {
107 void CommandLineLogSource::Fetch(const SysLogsSourceCallback
& callback
) {
108 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
109 DCHECK(!callback
.is_null());
111 SystemLogsResponse
* response
= new SystemLogsResponse
;
112 BrowserThread::PostBlockingPoolTaskAndReply(
114 base::Bind(&ExecuteCommandLines
, response
),
115 base::Bind(callback
, base::Owned(response
)));
118 } // namespace system_logs