마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

android process runtime.exec() 속도 문의입니다.

0 추천
루팅된 폰으로 개발을 진행하고 있는데요,

 

tcpdump를 이용하여 패킷을 분석하고, 그 결과를 출력하는 기능을 만들었습니다.

 

근데 ADB를 통해 명령을 쳤을때와, process = runtime.exec() 명령으로 실행 후 결과를 출력했을 때, 결과가 출력되는 속도가 달라서

 

사용에 문제가 있는데 이 처리 속도를 조금 더 높일수 있는 방법이 있나요 ?
익명사용자 님이 2014년 9월 18일 질문

1개의 답변

0 추천

정확히는 모르겠지만 adb 명령을 통해 콘솔에서 작업을 하는 것과

java 에서 많은 depth를 거쳐 wrapping 된 명령은 같은 명령이라 할지라도 속도 차가 좀 나지 않을까요?

추측성이지만 실제 tcpdump 산출 시간은 같으나 wrapping된 인터페이스에서 발생하는 객체 생성/삭제 메서드 호출 등이 느려지게 하지 않나 싶어요.

콘솔과 비슷하게 하려면 depth를 최대한 줄여서 tcpdump 를 수행하는 c코드를 작성하는 것이 어떨지요..?

 

아래는 실제 exec(...) 메서드 호출 시 ProcessManager 에서 수행하는 부분입니다. (젤리빈)

public Process exec(String[] taintedCommand, String[] taintedEnvironment, File workingDirectory, boolean redirectErrorStream)

    throws IOException
  {
    if (taintedCommand == null) {
      throw new NullPointerException("taintedCommand == null");
    }
    if (taintedCommand.length == 0) {
      throw new IndexOutOfBoundsException("taintedCommand.length == 0");
    }
 
    String[] command = (String[])taintedCommand.clone();
    String[] environment = taintedEnvironment != null ? (String[])taintedEnvironment.clone() : null;
 
    for (int i = 0; i < command.length; i++) {
      if (command[i] == null) {
        throw new NullPointerException("taintedCommand[" + i + "] == null");
      }
    }
 
    if (environment != null) {
      for (int i = 0; i < environment.length; i++) {
        if (environment[i] == null) {
          throw new NullPointerException("taintedEnvironment[" + i + "] == null");
        }
      }
    }
 
    FileDescriptor in = new FileDescriptor();
    FileDescriptor out = new FileDescriptor();
    FileDescriptor err = new FileDescriptor();
 
    String workingPath = workingDirectory == null ? null : workingDirectory.getPath();
 
    synchronized (this.processReferences) {
      int pid;
      try {
        pid = exec(command, environment, workingPath, in, out, err, redirectErrorStream);
      } catch (IOException e) {
        IOException wrapper = new IOException("Error running exec(). Command: " + Arrays.toString(command) + " Working Directory: " + workingDirectory + " Environment: " + Arrays.toString(environment));
 
        wrapper.initCause(e);
        throw wrapper;
      }
      ProcessImpl process = new ProcessImpl(pid, in, out, err);
      ProcessReference processReference = new ProcessReference(process, this.referenceQueue);
      this.processReferences.put(Integer.valueOf(pid), processReference);
 
      this.processReferences.notifyAll();
 
      return process;
    }
  }
Gioskhan (12,060 포인트) 님이 2014년 9월 26일 답변
...