Merge changes Ic8d22016,I3e15296e,Ie275e22c
* changes: adb: improve benchmark script a bit. adb: extract helper for dumping a packet header. adbd: turn on -Wthread-safety.
This commit is contained in:
commit
321a60f156
|
@ -41,7 +41,10 @@ cc_defaults {
|
|||
|
||||
target: {
|
||||
android: {
|
||||
cflags: ["-DADB_HOST=0"],
|
||||
cflags: [
|
||||
"-DADB_HOST=0",
|
||||
"-Wthread-safety",
|
||||
],
|
||||
},
|
||||
|
||||
host: {
|
||||
|
|
|
@ -186,6 +186,48 @@ std::string dump_hex(const void* data, size_t byte_count) {
|
|||
return line;
|
||||
}
|
||||
|
||||
std::string dump_header(const amessage* msg) {
|
||||
unsigned command = msg->command;
|
||||
int len = msg->data_length;
|
||||
char cmd[9];
|
||||
char arg0[12], arg1[12];
|
||||
int n;
|
||||
|
||||
for (n = 0; n < 4; n++) {
|
||||
int b = (command >> (n * 8)) & 255;
|
||||
if (b < 32 || b >= 127) break;
|
||||
cmd[n] = (char)b;
|
||||
}
|
||||
if (n == 4) {
|
||||
cmd[4] = 0;
|
||||
} else {
|
||||
// There is some non-ASCII name in the command, so dump the hexadecimal value instead
|
||||
snprintf(cmd, sizeof cmd, "%08x", command);
|
||||
}
|
||||
|
||||
if (msg->arg0 < 256U)
|
||||
snprintf(arg0, sizeof arg0, "%d", msg->arg0);
|
||||
else
|
||||
snprintf(arg0, sizeof arg0, "0x%x", msg->arg0);
|
||||
|
||||
if (msg->arg1 < 256U)
|
||||
snprintf(arg1, sizeof arg1, "%d", msg->arg1);
|
||||
else
|
||||
snprintf(arg1, sizeof arg1, "0x%x", msg->arg1);
|
||||
|
||||
return android::base::StringPrintf("[%s] arg0=%s arg1=%s (len=%d) ", cmd, arg0, arg1, len);
|
||||
}
|
||||
|
||||
std::string dump_packet(const char* name, const char* func, const apacket* p) {
|
||||
std::string result = name;
|
||||
result += ": ";
|
||||
result += func;
|
||||
result += ": ";
|
||||
result += dump_header(&p->msg);
|
||||
result += dump_hex(p->payload.data(), p->payload.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string perror_str(const char* msg) {
|
||||
return android::base::StringPrintf("%s: %s", msg, strerror(errno));
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <android-base/macros.h>
|
||||
|
||||
#include "adb.h"
|
||||
|
||||
int syntax_error(const char*, ...) __attribute__((__format__(__printf__, 1, 2)));
|
||||
|
||||
void close_stdin();
|
||||
|
@ -42,6 +44,8 @@ bool mkdirs(const std::string& path);
|
|||
std::string escape_arg(const std::string& s);
|
||||
|
||||
std::string dump_hex(const void* ptr, size_t byte_count);
|
||||
std::string dump_header(const amessage* msg);
|
||||
std::string dump_packet(const char* name, const char* func, const apacket* p);
|
||||
|
||||
std::string perror_str(const char* msg);
|
||||
|
||||
|
|
|
@ -60,8 +60,6 @@ def benchmark_push(device=None, file_size_mb=100):
|
|||
if device == None:
|
||||
device = adb.get_device()
|
||||
|
||||
lock_max(device)
|
||||
|
||||
remote_path = "/dev/null"
|
||||
local_path = "/tmp/adb_benchmark_temp"
|
||||
|
||||
|
@ -69,7 +67,7 @@ def benchmark_push(device=None, file_size_mb=100):
|
|||
f.truncate(file_size_mb * 1024 * 1024)
|
||||
|
||||
speeds = list()
|
||||
for _ in range(0, 5):
|
||||
for _ in range(0, 10):
|
||||
begin = time.time()
|
||||
device.push(local=local_path, remote=remote_path)
|
||||
end = time.time()
|
||||
|
@ -81,15 +79,13 @@ def benchmark_pull(device=None, file_size_mb=100):
|
|||
if device == None:
|
||||
device = adb.get_device()
|
||||
|
||||
lock_max(device)
|
||||
|
||||
remote_path = "/data/local/tmp/adb_benchmark_temp"
|
||||
local_path = "/tmp/adb_benchmark_temp"
|
||||
|
||||
device.shell(["dd", "if=/dev/zero", "of=" + remote_path, "bs=1m",
|
||||
"count=" + str(file_size_mb)])
|
||||
speeds = list()
|
||||
for _ in range(0, 5):
|
||||
for _ in range(0, 10):
|
||||
begin = time.time()
|
||||
device.pull(remote=remote_path, local=local_path)
|
||||
end = time.time()
|
||||
|
@ -101,10 +97,8 @@ def benchmark_shell(device=None, file_size_mb=100):
|
|||
if device == None:
|
||||
device = adb.get_device()
|
||||
|
||||
lock_max(device)
|
||||
|
||||
speeds = list()
|
||||
for _ in range(0, 5):
|
||||
for _ in range(0, 10):
|
||||
begin = time.time()
|
||||
device.shell(["dd", "if=/dev/zero", "bs=1m",
|
||||
"count=" + str(file_size_mb)])
|
||||
|
@ -114,7 +108,10 @@ def benchmark_shell(device=None, file_size_mb=100):
|
|||
analyze("shell %dMiB" % file_size_mb, speeds)
|
||||
|
||||
def main():
|
||||
benchmark_pull()
|
||||
device = adb.get_device()
|
||||
unlock(device)
|
||||
benchmark_push(device)
|
||||
benchmark_pull(device)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -408,42 +408,6 @@ void FdConnection::Close() {
|
|||
fd_.reset();
|
||||
}
|
||||
|
||||
static std::string dump_packet(const char* name, const char* func, apacket* p) {
|
||||
unsigned command = p->msg.command;
|
||||
int len = p->msg.data_length;
|
||||
char cmd[9];
|
||||
char arg0[12], arg1[12];
|
||||
int n;
|
||||
|
||||
for (n = 0; n < 4; n++) {
|
||||
int b = (command >> (n * 8)) & 255;
|
||||
if (b < 32 || b >= 127) break;
|
||||
cmd[n] = (char)b;
|
||||
}
|
||||
if (n == 4) {
|
||||
cmd[4] = 0;
|
||||
} else {
|
||||
/* There is some non-ASCII name in the command, so dump
|
||||
* the hexadecimal value instead */
|
||||
snprintf(cmd, sizeof cmd, "%08x", command);
|
||||
}
|
||||
|
||||
if (p->msg.arg0 < 256U)
|
||||
snprintf(arg0, sizeof arg0, "%d", p->msg.arg0);
|
||||
else
|
||||
snprintf(arg0, sizeof arg0, "0x%x", p->msg.arg0);
|
||||
|
||||
if (p->msg.arg1 < 256U)
|
||||
snprintf(arg1, sizeof arg1, "%d", p->msg.arg1);
|
||||
else
|
||||
snprintf(arg1, sizeof arg1, "0x%x", p->msg.arg1);
|
||||
|
||||
std::string result = android::base::StringPrintf("%s: %s: [%s] arg0=%s arg1=%s (len=%d) ", name,
|
||||
func, cmd, arg0, arg1, len);
|
||||
result += dump_hex(p->payload.data(), p->payload.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
void send_packet(apacket* p, atransport* t) {
|
||||
p->msg.magic = p->msg.command ^ 0xffffffff;
|
||||
// compute a checksum for connection/auth packets for compatibility reasons
|
||||
|
|
Loading…
Reference in New Issue