Loading adb/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -213,6 +213,7 @@ cc_test_host { cc_benchmark { name: "adb_benchmark", defaults: ["adb_defaults"], host_supported: true, srcs: ["transport_benchmark.cpp"], target: { Loading @@ -226,6 +227,9 @@ cc_benchmark { "libadb_host", ], }, darwin: { enabled: false, } }, static_libs: [ Loading adb/transport_benchmark.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -183,8 +183,10 @@ ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::SameThread); ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::MainThread); int main(int argc, char** argv) { #if defined(__BIONIC__) // Set M_DECAY_TIME so that our allocations aren't immediately purged on free. mallopt(M_DECAY_TIME, 1); #endif android::base::SetMinimumLogSeverity(android::base::WARNING); adb_trace_init(argv); Loading adb/transport_fd.cpp +15 −17 Original line number Diff line number Diff line Loading @@ -85,18 +85,9 @@ struct NonblockingFdConnection : public Connection { if (pfds[0].revents) { if ((pfds[0].revents & POLLOUT)) { std::lock_guard<std::mutex> lock(this->write_mutex_); WriteResult result = DispatchWrites(); switch (result) { case WriteResult::Error: if (DispatchWrites() == WriteResult::Error) { *error = "write failed"; return; case WriteResult::Completed: writable_ = true; break; case WriteResult::TryAgain: break; } } Loading Loading @@ -179,13 +170,14 @@ struct NonblockingFdConnection : public Connection { WriteResult DispatchWrites() REQUIRES(write_mutex_) { CHECK(!write_buffer_.empty()); if (!writable_) { return WriteResult::TryAgain; } auto iovs = write_buffer_.iovecs(); ssize_t rc = adb_writev(fd_.get(), iovs.data(), iovs.size()); if (rc == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { writable_ = false; return WriteResult::TryAgain; } return WriteResult::Error; } else if (rc == 0) { errno = 0; Loading @@ -194,6 +186,7 @@ struct NonblockingFdConnection : public Connection { // TODO: Implement a more efficient drop_front? write_buffer_.take_front(rc); writable_ = write_buffer_.empty(); if (write_buffer_.empty()) { return WriteResult::Completed; } Loading @@ -211,7 +204,12 @@ struct NonblockingFdConnection : public Connection { if (!packet->payload.empty()) { write_buffer_.append(std::make_unique<IOVector::block_type>(std::move(packet->payload))); } return DispatchWrites() != WriteResult::Error; WriteResult result = DispatchWrites(); if (result == WriteResult::TryAgain) { WakeThread(); } return result != WriteResult::Error; } std::thread thread_; Loading adb/types.h +4 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,10 @@ struct Block { CHECK_EQ(0ULL, capacity_); CHECK_EQ(0ULL, size_); if (size != 0) { data_ = std::make_unique<char[]>(size); // This isn't std::make_unique because that's equivalent to `new char[size]()`, which // value-initializes the array instead of leaving it uninitialized. As an optimization, // call new without parentheses to avoid this costly initialization. data_.reset(new char[size]); capacity_ = size; size_ = size; } Loading Loading
adb/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -213,6 +213,7 @@ cc_test_host { cc_benchmark { name: "adb_benchmark", defaults: ["adb_defaults"], host_supported: true, srcs: ["transport_benchmark.cpp"], target: { Loading @@ -226,6 +227,9 @@ cc_benchmark { "libadb_host", ], }, darwin: { enabled: false, } }, static_libs: [ Loading
adb/transport_benchmark.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -183,8 +183,10 @@ ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::SameThread); ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::MainThread); int main(int argc, char** argv) { #if defined(__BIONIC__) // Set M_DECAY_TIME so that our allocations aren't immediately purged on free. mallopt(M_DECAY_TIME, 1); #endif android::base::SetMinimumLogSeverity(android::base::WARNING); adb_trace_init(argv); Loading
adb/transport_fd.cpp +15 −17 Original line number Diff line number Diff line Loading @@ -85,18 +85,9 @@ struct NonblockingFdConnection : public Connection { if (pfds[0].revents) { if ((pfds[0].revents & POLLOUT)) { std::lock_guard<std::mutex> lock(this->write_mutex_); WriteResult result = DispatchWrites(); switch (result) { case WriteResult::Error: if (DispatchWrites() == WriteResult::Error) { *error = "write failed"; return; case WriteResult::Completed: writable_ = true; break; case WriteResult::TryAgain: break; } } Loading Loading @@ -179,13 +170,14 @@ struct NonblockingFdConnection : public Connection { WriteResult DispatchWrites() REQUIRES(write_mutex_) { CHECK(!write_buffer_.empty()); if (!writable_) { return WriteResult::TryAgain; } auto iovs = write_buffer_.iovecs(); ssize_t rc = adb_writev(fd_.get(), iovs.data(), iovs.size()); if (rc == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { writable_ = false; return WriteResult::TryAgain; } return WriteResult::Error; } else if (rc == 0) { errno = 0; Loading @@ -194,6 +186,7 @@ struct NonblockingFdConnection : public Connection { // TODO: Implement a more efficient drop_front? write_buffer_.take_front(rc); writable_ = write_buffer_.empty(); if (write_buffer_.empty()) { return WriteResult::Completed; } Loading @@ -211,7 +204,12 @@ struct NonblockingFdConnection : public Connection { if (!packet->payload.empty()) { write_buffer_.append(std::make_unique<IOVector::block_type>(std::move(packet->payload))); } return DispatchWrites() != WriteResult::Error; WriteResult result = DispatchWrites(); if (result == WriteResult::TryAgain) { WakeThread(); } return result != WriteResult::Error; } std::thread thread_; Loading
adb/types.h +4 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,10 @@ struct Block { CHECK_EQ(0ULL, capacity_); CHECK_EQ(0ULL, size_); if (size != 0) { data_ = std::make_unique<char[]>(size); // This isn't std::make_unique because that's equivalent to `new char[size]()`, which // value-initializes the array instead of leaving it uninitialized. As an optimization, // call new without parentheses to avoid this costly initialization. data_.reset(new char[size]); capacity_ = size; size_ = size; } Loading