Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adb: Use current date/time instead of last logcat line for timestamp #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions xbuild/src/devices/adb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,21 @@ impl Adb {
Ok(())
}

fn logcat_last_timestamp(&self, device: &str) -> Result<String> {
/// Returns the current device date and time in logcat timestamp format
fn current_date_time(&self, device: &str) -> Result<String> {
let output = self
.shell(device, None)
.arg("logcat")
.arg("-v")
.arg("time")
.arg("-t")
.arg("1")
.arg("date")
// Escape string so that `adb` passes it as-is to `date`
.arg("'+%m-%d %T.000'")
.output()?;
anyhow::ensure!(
output.status.success(),
"adb logcat exited with code {:?}: {}",
"`adb shell date` exited with code {:?}: {}",
output.status.code(),
std::str::from_utf8(&output.stderr)?.trim()
);
let line = std::str::from_utf8(&output.stdout)?.lines().nth(1).unwrap();
Ok(line[..18].to_string())
Ok(std::str::from_utf8(&output.stdout)?.trim().to_owned())
}

fn uidof(&self, device: &str, id: &str) -> Result<u32> {
Expand Down Expand Up @@ -233,12 +231,12 @@ impl Adb {
Ok(uid.parse()?)
}

fn logcat(&self, device: &str, uid: u32, last_timestamp: &str) -> Result<Logcat> {
fn logcat(&self, device: &str, uid: u32, since: &str) -> Result<Logcat> {
let child = self
.shell(device, None)
.adb(device)
.arg("logcat")
.arg("-T")
.arg(format!("'{}'", last_timestamp))
.arg(since)
.arg(format!("--uid={}", uid))
.stdin(Stdio::null())
.stdout(Stdio::piped())
Expand Down Expand Up @@ -354,10 +352,10 @@ impl Adb {
}
self.install(device, path)?;
self.forward_reverse(device, debug_config)?;
let last_timestamp = self.logcat_last_timestamp(device)?;
let since = self.current_date_time(device)?;
self.start(device, package, activity)?;
let uid = self.uidof(device, package)?;
let logcat = self.logcat(device, uid, &last_timestamp)?;
let logcat = self.logcat(device, uid, &since)?;
for line in logcat {
println!("{}", line);
}
Expand Down
Loading