0

im running jelly Bean on a physical device and trying to monitor network statistics. For example in DDMS there is a tab called network statistics and when you press start you can monitor network connection data transfers.

enter image description here

I specifically would like to monitor a few webviews i have: so i've done the following in my webclient:

@Override
public void onPageStarted(WebView view, String url, 
   android.graphics.Bitmap favicon) {


    TrafficStats.setThreadStatsTag(0xF00D);


}

public void onPageFinished(WebView view, String url) { 
TrafficStats.clearThreadStatsTag();    
}

I was expecting to see a different color and im not seeing that tag listed (0xF00D) or a different color i only see a red color near the bottom of the screen capture.

What i need is to be able to differentiate different threads by color.

j2emanue
  • 60,549
  • 65
  • 286
  • 456

2 Answers2

1

The color in the DDMS network statistics view is beyond your control. What you can do in your code is just set tag per thread. In the DDMS network statistics view source code, DDMS defines a color set

private static final java.awt.Color TOTAL_COLOR = java.awt.Color.GRAY;
private static final java.awt.Color[] SERIES_COLORS = new java.awt.Color[] {
    java.awt.Color.decode("0x2bc4c1"), // teal
    java.awt.Color.decode("0xD50F25"), // red
    java.awt.Color.decode("0x3369E8"), // blue
    java.awt.Color.decode("0xEEB211"), // orange
    java.awt.Color.decode("0x00bd2e"), // green
    java.awt.Color.decode("0xae26ae"), // purple
};

traffic flow being actively tracked, uniquely defined by UID and tag(defined in your code). DDMS use a TrackedItem represents a traffic flow. And then define a ArrayList to represent all the traffic flows.

private ArrayList<TrackedItem> mTrackedItems = new ArrayList<TrackedItem>();

When DDMS detect a new traffic flow which means a new uid or tag, It set the item color in this way:

final int size = mTrackedItems.size();
item.color = nextSeriesColor(size);

private static java.awt.Color nextSeriesColor(int index) {
return SERIES_COLORS[index % SERIES_COLORS.length];

}

I omit some irrelevant codes to the color setting.

So, you can just set the tag. You can't decide the color by yourself if you don't modify the DDMS source code.

Jansen
  • 133
  • 12
0

UPDATE: AS PER THE DOCUMENTATION setThreadStatsTag() is for watching socket traffic. I was trying to use it for watching Thread traffic. My mistake:

 setThreadStatsTag(int tag)

Set active tag to use when accounting Socket traffic originating from the current thread.

j2emanue
  • 60,549
  • 65
  • 286
  • 456