android.util.StringBuilderPrinter Java Examples

The following examples show how to use android.util.StringBuilderPrinter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 6 votes vote down vote up
private void getHttpResult(StringBuilderPrinter printer, HashMap<String, String> values) {
  HttpDesc desc = (HttpDesc) parameters;
  printer.println("[HTTP]");
  printer.println("URL: " + desc.url);
  printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
  printIPTestResult(printer);

  if (taskProgress == TaskProgress.COMPLETED) {
    int headerLen = Integer.parseInt(values.get("headers_len"));
    int bodyLen = Integer.parseInt(values.get("body_len"));
    int time = Integer.parseInt(values.get("time_ms"));
    printer.println("");
    printer.println("Downloaded " + (headerLen + bodyLen) + " bytes in " + time + " ms");
    printer.println("Bandwidth: " + (headerLen + bodyLen) * 8 / time + " Kbps");
  } else if (taskProgress == TaskProgress.PAUSED) {
    printer.println("Http paused!");
  } else {
    printer.println("Http download failed, status code " + values.get("code"));
    printer.println("Error: " + values.get("error"));
  }
}
 
Example #2
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 6 votes vote down vote up
private void getDnsResult(StringBuilderPrinter printer, HashMap<String, String> values) {
  DnsLookupDesc desc = (DnsLookupDesc) parameters;
  printer.println("[DNS Lookup]");
  printer.println("Target: " + desc.target);
  printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
  printIPTestResult(printer);

  if (taskProgress == TaskProgress.COMPLETED) {
    String ipAddress = removeQuotes(values.get("address"));
    if (ipAddress == null) {
      ipAddress = "Unknown";
    }
    printer.println("\nAddress: " + ipAddress);
    int time = Integer.parseInt(values.get("time_ms"));
    printer.println("Lookup time: " + time + " ms");
  } else if (taskProgress == TaskProgress.PAUSED) {
    printer.println("DNS look up paused!");
  } else {
    printer.println("Error: " + values.get("error"));
  }
}
 
Example #3
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 6 votes vote down vote up
private void getVideoQoEResult(StringBuilderPrinter printer, HashMap<String, String> values) {
	    VideoQoEDesc desc = (VideoQoEDesc) parameters;
	    printer.println("[Video QoE Measurement]");
	    printer.println("Content ID: " + desc.contentId);
	    printer.println("Streaming Algorithm: " + desc.contentType);
	    printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
	    printIPTestResult(printer);

	    if (taskProgress == TaskProgress.COMPLETED) {
	      printer.println("");
//	      printer.println(UpdateIntent.VIDEO_TASK_PAYLOAD_IS_SUCCEED + ": " + values.get(UpdateIntent.VIDEO_TASK_PAYLOAD_IS_SUCCEED));
	      printer.println("Num of frame dropped" + ": " + values.get("video_num_frame_dropped"));
	      printer.println("Initial loading time" + ": " + values.get("video_initial_loading_time"));
//	      printer.println(UpdateIntent.VIDEO_TASK_PAYLOAD_REBUFFER_TIME + ": " + values.get(UpdateIntent.VIDEO_TASK_PAYLOAD_REBUFFER_TIME));
//	      printer.println(UpdateIntent.VIDEO_TASK_PAYLOAD_GOODPUT_TIMESTAMP + ": " + values.get(UpdateIntent.VIDEO_TASK_PAYLOAD_GOODPUT_TIMESTAMP));
//	      printer.println(UpdateIntent.VIDEO_TASK_PAYLOAD_GOODPUT_VALUE + ": " + values.get(UpdateIntent.VIDEO_TASK_PAYLOAD_GOODPUT_VALUE));
//	      printer.println(UpdateIntent.VIDEO_TASK_PAYLOAD_BITRATE_TIMESTAMP + ": " + values.get(UpdateIntent.VIDEO_TASK_PAYLOAD_BITRATE_TIMESTAMP));
//	      printer.println(UpdateIntent.VIDEO_TASK_PAYLOAD_BITRATE_VALUE + ": " + values.get(UpdateIntent.VIDEO_TASK_PAYLOAD_BITRATE_VALUE));
	    } else if (taskProgress == TaskProgress.PAUSED) {
	      printer.println("Video QoE task paused!");
	    } else {
	      printer.println("Error: " + values.get("error"));
	    }
	  }
 
Example #4
Source File: ImeUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param editorInfo The EditorInfo
 * @return Debug string for the given {@EditorInfo}.
 */
static String getEditorInfoDebugString(EditorInfo editorInfo) {
    StringBuilder builder = new StringBuilder();
    StringBuilderPrinter printer = new StringBuilderPrinter(builder);
    editorInfo.dump(printer, "");
    return builder.toString();
}
 
Example #5
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
private void getPingResult(StringBuilderPrinter printer, HashMap<String, String> values) {
  PingDesc desc = (PingDesc) parameters;
  printer.println("[Ping]");
  printer.println("Target: " + desc.target);
  String ipAddress = removeQuotes(values.get("target_ip"));
  // TODO: internationalize 'Unknown'.
  if (ipAddress == null) {
    ipAddress = "Unknown";
  }
  printer.println("IP address: " + ipAddress);
  printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
  printIPTestResult(printer);

  if (taskProgress == TaskProgress.COMPLETED) {
    float packetLoss = Float.parseFloat(values.get("packet_loss"));
    int count = Integer.parseInt(values.get("packets_sent"));
    printer.println("\n" + count + " packets transmitted, " + (int) (count * (1 - packetLoss))
      + " received, " + (packetLoss * 100) + "% packet loss");

    float value = Float.parseFloat(values.get("mean_rtt_ms"));
    printer.println("Mean RTT: " + String.format("%.1f", value) + " ms");

    value = Float.parseFloat(values.get("min_rtt_ms"));
    printer.println("Min RTT:  " + String.format("%.1f", value) + " ms");

    value = Float.parseFloat(values.get("max_rtt_ms"));
    printer.println("Max RTT:  " + String.format("%.1f", value) + " ms");

    value = Float.parseFloat(values.get("stddev_rtt_ms"));
    printer.println("Std dev:  " + String.format("%.1f", value) + " ms");
  } else if (taskProgress == TaskProgress.PAUSED) {
    printer.println("Ping paused!");
  } else {
    printer.println("Error: " + values.get("error"));
  }
}
 
Example #6
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
private void getUDPBurstResult(StringBuilderPrinter printer, HashMap<String, String> values) {
    UDPBurstDesc desc = (UDPBurstDesc) parameters;
    if (desc.dirUp) {
      printer.println("[UDPBurstUp]");
    } else {
      printer.println("[UDPBurstDown]");
    }
    printer.println("Target: " + desc.target);
    printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
    printIPTestResult(printer);

    if (taskProgress == TaskProgress.COMPLETED) {
      printer.println("IP addr: " + values.get("target_ip"));
      printIPTestResult(printer);
//      printer.println("Packet size: " + desc.packetSizeByte + "B");
//      printer.println("Number of packets to be sent: " + desc.udpBurstCount);
//      printer.println("Interval between packets: " + desc.udpInterval + "ms");

      String lossRatio = String.format("%.2f", Double.parseDouble(values.get("loss_ratio")) * 100);
      String outOfOrderRatio =
          String.format("%.2f", Double.parseDouble(values.get("out_of_order_ratio")) * 100);
      printer.println("\nLoss ratio: " + lossRatio + "%");
      printer.println("Out of order ratio: " + outOfOrderRatio + "%");
      printer.println("Jitter: " + values.get("jitter") + "ms");
    } else if (taskProgress == TaskProgress.PAUSED) {
      printer.println("UDP Burst paused!");
    } else {
      printer.println("Error: " + values.get("error"));
    }
  }
 
Example #7
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
private void getRRCResult(StringBuilderPrinter printer, HashMap<String, String> values) {
  printer.println("[RRC Inference]");
  if (taskProgress == TaskProgress.COMPLETED) {
    printer.println("Succeed!");
  }
  else {
    printer.println("Failed!");
  }
  printer.println("Results uploaded to server");
}
 
Example #8
Source File: HumanReadables.java    From android-test with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms an arbitrary view into a string with (hopefully) enough debug info.
 *
 * @param v nullable view
 * @return a string for human consumption.
 */
public static String describe(View v) {
  if (null == v) {
    return "null";
  }
  ToStringHelper helper = MoreObjects.toStringHelper(v).add("id", v.getId());
  if (v.getId() != -1 && v.getResources() != null && !isViewIdGenerated(v.getId())) {
    try {
      helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
    } catch (Resources.NotFoundException ignore) {
      // Do nothing.
    }
  }
  if (null != v.getContentDescription()) {
    helper.add("desc", v.getContentDescription());
  }

  switch (v.getVisibility()) {
    case View.GONE:
      helper.add("visibility", "GONE");
      break;
    case View.INVISIBLE:
      helper.add("visibility", "INVISIBLE");
      break;
    case View.VISIBLE:
      helper.add("visibility", "VISIBLE");
      break;
    default:
      helper.add("visibility", v.getVisibility());
  }

  helper
      .add("width", v.getWidth())
      .add("height", v.getHeight())
      .add("has-focus", v.hasFocus())
      .add("has-focusable", v.hasFocusable())
      .add("has-window-focus", v.hasWindowFocus())
      .add("is-clickable", v.isClickable())
      .add("is-enabled", v.isEnabled())
      .add("is-focused", v.isFocused())
      .add("is-focusable", v.isFocusable())
      .add("is-layout-requested", v.isLayoutRequested())
      .add("is-selected", v.isSelected())
      .add("layout-params", v.getLayoutParams())
      .add("tag", v.getTag());

  if (null != v.getRootView()) {
    // pretty much only true in unit-tests.
    helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
  }

  EditorInfo ei = new EditorInfo();
  InputConnection ic = v.onCreateInputConnection(ei);
  boolean hasInputConnection = ic != null;
  helper.add("has-input-connection", hasInputConnection);
  if (hasInputConnection) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    Printer p = new StringBuilderPrinter(sb);
    ei.dump(p, "");
    sb.append("]");
    helper.add("editor-info", sb.toString().replace("\n", " "));
  }

  if (Build.VERSION.SDK_INT > 10) {
    helper.add("x", v.getX()).add("y", v.getY());
  }

  if (v instanceof TextView) {
    innerDescribe((TextView) v, helper);
  }
  if (v instanceof Checkable) {
    innerDescribe((Checkable) v, helper);
  }
  if (v instanceof ViewGroup) {
    innerDescribe((ViewGroup) v, helper);
  }
  return helper.toString();
}
 
Example #9
Source File: RRCTask.java    From Mobilyzer with Apache License 2.0 4 votes vote down vote up
public void displayResults(StringBuilderPrinter printer) {
  String DEL = "\t", toprint = DEL + DEL;
  for (int i = 1; i <= times.length; i++) {
    toprint += DEL + " | state" + i;
  }
  toprint += " |";
  int oneLineLen = toprint.length();
  toprint += "\n";
  // seperator
  for (int i = 0; i < oneLineLen; i++) {
    toprint += "-";
  }
  toprint += "\n";
  if (HTTP) {
    toprint += "HTTP (ms)" + DEL;
    for (int i = 0; i < httpTest.length; i++) {
      toprint += DEL + " | " + Integer.toString(httpTest[i]);
    }
    toprint += " |\n";
    for (int i = 0; i < oneLineLen; i++) {
      toprint += "-";
    }
    toprint += "\n";
  }

  if (DNS) {
    toprint += "DNS (ms)" + DEL;
    for (int i = 0; i < dnsTest.length; i++) {
      toprint += DEL + " | " + Integer.toString(dnsTest[i]);
    }
    toprint += " |\n";
    for (int i = 0; i < oneLineLen; i++) {
      toprint += "-";
    }
    toprint += "\n";
  }

  if (TCP) {
    toprint += "TCP (ms)" + DEL;
    for (int i = 0; i < tcpTest.length; i++) {
      toprint += DEL + " | " + Integer.toString(tcpTest[i]);
    }
    toprint += " |\n";
    for (int i = 0; i < oneLineLen; i++) {
      toprint += "-";
    }
    toprint += "\n";
  }

  toprint += "Timers (s)";
  for (int i = 0; i < times.length; i++) {
    double curTime = (double) times[i] * (double) GRANULARITY / 1000.0;
    toprint += DEL + " | " + String.format("%.2f", curTime);
  }
  toprint += " |\n";
  printer.println(toprint);
}
 
Example #10
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 4 votes vote down vote up
private void getTracerouteResult(StringBuilderPrinter printer, HashMap<String, String> values) {
  TracerouteDesc desc = (TracerouteDesc) parameters;
  printer.println("[Traceroute]");
  printer.println("Target: " + desc.target);
  printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
  printIPTestResult(printer);

  if (taskProgress == TaskProgress.COMPLETED) {
    // Manually inject a new line
    printer.println(" ");

    int hops = Integer.parseInt(values.get("num_hops"));
    int hop_str_len = String.valueOf(hops + 1).length();
    for (int i = 1; i <= hops; i++) {
      String key = "hop_" + i + "_addr_1";
      String ipAddress = removeQuotes(values.get(key));
      if (ipAddress == null) {
        ipAddress = "Unknown";
      }
      String hop_str = String.valueOf(i);
      String hopInfo = hop_str;
      for (int j = 0; j < hop_str_len + 1 - hop_str.length(); ++j) {
        hopInfo += " ";
      }
      hopInfo += ipAddress;
      // Maximum IP address length is 15.
      for (int j = 0; j < 16 - ipAddress.length(); ++j) {
        hopInfo += " ";
      }

      key = "hop_" + i + "_rtt_ms";
      // The first and last character of this string are double
      // quotes.
      String timeStr = removeQuotes(values.get(key));
      if (timeStr == null) {
        timeStr = "Unknown";
        printer.println(hopInfo + "-1 ms");
      }else{
        float time = Float.parseFloat(timeStr);
        printer.println(hopInfo + String.format("%6.2f", time) + " ms");  
      }

      
    }
  } else if (taskProgress == TaskProgress.PAUSED) {
    printer.println("Traceroute paused!");
  } else {
    printer.println("Error: " + values.get("error"));
  }
}
 
Example #11
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 4 votes vote down vote up
private void getTCPThroughputResult(StringBuilderPrinter printer, HashMap<String, String> values) {
  TCPThroughputDesc desc = (TCPThroughputDesc) parameters;
  if (desc.dir_up) {
    printer.println("[TCP Uplink]");
  } else {
    printer.println("[TCP Downlink]");
  }
  printer.println("Target: " + desc.target);
  printer.println("Timestamp: " + Util.getTimeStringFromMicrosecond(properties.timestamp));
  printIPTestResult(printer);

  if (taskProgress == TaskProgress.COMPLETED) {
    printer.println("");
    // Display result with precision up to 2 digit
    String speedInJSON = values.get("tcp_speed_results");
    String dataLimitExceedInJSON = values.get("data_limit_exceeded");
    String displayResult = "";

    double tp = desc.calMedianSpeedFromTCPThroughputOutput(speedInJSON);
    double KB = Math.pow(2, 10);
    if (tp < 0) {
      displayResult = "No results available.";
    } else if (tp > KB * KB) {
      displayResult = "Speed: " + String.format("%.2f", tp / (KB * KB)) + " Gbps";
    } else if (tp > KB) {
      displayResult = "Speed: " + String.format("%.2f", tp / KB) + " Mbps";
    } else {
      displayResult = "Speed: " + String.format("%.2f", tp) + " Kbps";
    }

    // Append notice for exceeding data limit
    if (dataLimitExceedInJSON.equals("true")) {
      displayResult +=
          "\n* Task finishes earlier due to exceeding " + "maximum number of "
              + ((desc.dir_up) ? "transmitted" : "received") + " bytes";
    }
    printer.println(displayResult);
  } else if (taskProgress == TaskProgress.PAUSED) {
    printer.println("TCP Throughput paused!");
  } else {
    printer.println("Error: " + values.get("error"));
  }
}
 
Example #12
Source File: MeasurementResult.java    From Mobilyzer with Apache License 2.0 4 votes vote down vote up
/**
   * Print ip connectivity and hostname resolvability result
   */
  private void printIPTestResult(StringBuilderPrinter printer) {
//    printer.println("IPv4/IPv6 Connectivity: " + properties.ipConnectivity);
//    printer.println("IPv4/IPv6 Domain Name Resolvability: " + properties.dnResolvability);
  }