private void runProfile() {
    String profileFile = null;
    boolean start = false;

    String process = nextArg();
    if (process == null) {
      System.err.println("Error: No profile process supplied");
      showUsage();
      return;
    }

    String cmd = nextArg();
    if ("start".equals(cmd)) {
      start = true;
      profileFile = nextArg();
      if (profileFile == null) {
        System.err.println("Error: No profile file path supplied");
        showUsage();
        return;
      }
    } else if (!"stop".equals(cmd)) {
      System.err.println("Error: Profile command " + cmd + " not valid");
      showUsage();
      return;
    }

    try {
      if (!mAm.profileControl(process, start, profileFile)) {
        System.out.println("PROFILE FAILED on process " + process);
        return;
      }
    } catch (IllegalArgumentException e) {
      System.out.println("PROFILE FAILED: " + e.getMessage());
      return;
    } catch (IllegalStateException e) {
      System.out.println("PROFILE FAILED: " + e.getMessage());
      return;
    } catch (RemoteException e) {
      System.out.println("PROFILE FAILED: activity manager gone");
      return;
    }
  }