Slow executions
igormaozao opened this issue · 4 comments
Hello.
I'm testing this lib, but I'm having some issues with high delay to execute some actions, for example, doing a simple:
AdbClient.Instance.ExecuteRemoteCommand("adb shell input tab 100 500", device, receiver);
It takes like 3~4 seconds to be executed, is that correct or am I missing something?
I think there may be an issue with your command. This line:
AdbClient.Instance.ExecuteRemoteCommand("adb shell input tab 100 500", device, receiver);
will cause the following command to be executed on your Android device:
adb shell input tab 100 500
That is, you will start an adb
client on the device, have it connect to itself and then run the input tab 100 500
command. It's the equivalent of running
adb shell adb shell input tab 100 500
on your computer.
Can you try running
AdbClient.Instance.ExecuteRemoteCommand("input tab 100 500", device, receiver);
and see if that's better?
Thanks!
True that, my bad, btw, it still taking like 300~400 ms to execute the "input tap 100 500", is that normal? I'm new with ADB so I'm not sure if it's really the time it took usually.
Also there is a faster way to capture the device screen than GetFrameBufferAsync() ?
Thank you!
AdbClient.Instance.ExecuteRemoteCommand
creates a new TCP connection to the adb server running on your PC every time. Opening and closing connections takes time, and this may be the overhead you're seeing.
You could measure the difference between running adb shell
on your PC and typing the command in the interactive shell, versus running the command using SharpAdbClient, to get an idea of the overhead we incur.
If you want to be able to send shell input
commands at a high rate, you probably want to create your own code that can execute multiple commands on the same connection.
If you're up to it, you can try something like this:
var device = null; // Your code here to get the device
using (IAdbSocket socket = Factories.AdbSocketFactory(AdbClient.Instance.EndPoint))
{
AdbClient.Instance.SetDevice(socket, device);
var command = "input tab 100 500";
while (true)
{
socket.SendAdbRequest($"shell:{command}");
var response = socket.ReadAdbResponse();
// Read the output from adb, most likely empty in your case
using (StreamReader reader = new StreamReader(socket.GetShellStream(), Encoding))
{
while (true)
{
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line == null)
{
break;
}
}
}
}
I didn't try the code and it may be that adb will close the connection after the command has executed successfully, in which case this won't work.
If it works, and proves to improve performance for you, it may make some sens to add a ShellSession
or similar class to SharpAdbClient, which allows you to execute multiple commands on a single connection. We accept pull requests ;)
Regarding the performance of GetFrameBufferAsync
: it is very slow (although we improved it a bit in #40), and good alternatives are
See #39 and #55 for some of the work we (eventually) plan to do there.
Hope it helps!
@igormaozao , since you indicated the original problem is resolved, and you haven't replied back to this thread, I'm going to close this issue for now. If you still have questions, let me know!