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
, CommandLine
> > commands
;
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
));
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
));
37 command
= 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
= 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
= CommandLine((base::FilePath("/usr/bin/printenv")));
56 commands
.push_back(std::make_pair("env", command
));
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
));
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
));
68 command
= CommandLine(base::FilePath("/usr/bin/xrandr"));
69 command
.AppendArg("--verbose");
70 commands
.push_back(std::make_pair("xrandr", command
));
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
));
80 for (size_t i
= 0; i
< commands
.size(); ++i
) {
82 base::GetAppOutput(commands
[i
].second
, &output
);
83 (*response
)[commands
[i
].first
] = output
;
89 namespace system_logs
{
91 void CommandLineLogSource::Fetch(const SysLogsSourceCallback
& callback
) {
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
93 DCHECK(!callback
.is_null());
95 SystemLogsResponse
* response
= new SystemLogsResponse
;
96 BrowserThread::PostBlockingPoolTaskAndReply(
98 base::Bind(&ExecuteCommandLines
, response
),
99 base::Bind(callback
, base::Owned(response
)));
102 } // namespace system_logs