<commit_before>package com.mobiperf_library;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import android.net.TrafficStats;

import com.mobiperf_library.util.PhoneUtils;

public class ContextCollector {
	private Thread contextThread;
	public static int isBusy = 0;
	// this thread is used for collecting context information in a time
	// interval.
	private volatile Vector<Map<String, Object>> contextResultVector;
	private Map<String, Object> currentContext;
	public int busyInterval = 1000;
	public int idleInterval = 6000;
	Thread runnable = new Thread() {
		public static final String TYPE = "context";
		public MeasurementResult result;

		public void run() {
			long prevSend = 0;
			long prevRecv = 0;
			long sendBytes = 0;
			long recvBytes = 0;
			long intervalSend = 0;
			long intervalRecv = 0;
			long prevPktSend = 0;
			long prevPktRecv = 0;
			long sendPkt = 0;
			long recvPkt = 0;
			long intervalPktSend = 0;
			long intervalPktRecv = 0;
			int interval = busyInterval;
			while (true) {
				sendBytes = TrafficStats.getMobileTxBytes();
				recvBytes = TrafficStats.getMobileRxBytes();
				sendPkt = TrafficStats.getMobileTxPackets();
				sendPkt = TrafficStats.getMobileRxPackets();
				if (prevSend > 0 || prevRecv > 0) {
					intervalSend = sendBytes - prevSend;
					intervalRecv = recvBytes - prevRecv;
				}
				if (prevPktSend > 0 || prevPktRecv > 0) {
					intervalPktSend = sendPkt - prevPktSend;
					intervalPktRecv = recvPkt - prevPktRecv;
				}
				prevSend = sendBytes;
				prevRecv = recvBytes;
				prevPktSend = sendPkt;
				prevPktRecv = recvPkt;
				PhoneUtils phoneUtils = PhoneUtils.getPhoneUtils();
				Map<String, Object> contextResult = new HashMap<String, Object>();
				contextResult.put("timestamp",
						System.currentTimeMillis() * 1000);
				contextResult.put("rssi", phoneUtils.getCurrentRssi());
				contextResult.put("inc_mobile_bytes_send", intervalSend);
				contextResult.put("inc_mobile_bytes_recv", intervalRecv);
				contextResult.put("inc_mobile_pkt_send", intervalPktSend);
				contextResult.put("inc_mobile_pkt_recv", intervalPktRecv);
				contextResult.put("interval", interval);
				contextResult.put("battery_level",
						phoneUtils.getCurrentBatteryLevel());
				currentContext = contextResult;
				contextResultVector.add(contextResult);
				System.out.println("context result="
						+ currentContext.toString());
				if (isBusy == 0) {
					interval = idleInterval;
				} else {
					interval = busyInterval;
				}<commit_msg>Add the upper limit of the size of contextResultVector.<commit_after>package com.mobiperf_library;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import android.net.TrafficStats;

import com.mobiperf_library.util.PhoneUtils;

public class ContextCollector {
	private Thread contextThread;
	public static int isBusy = 0;
	// this thread is used for collecting context information in a time
	// interval.
	private volatile Vector<Map<String, Object>> contextResultVector;
	private Map<String, Object> currentContext;
	public int busyInterval = 2000;
	public int idleInterval = 60000;
	Thread runnable = new Thread() {
		public static final String TYPE = "context";
		public MeasurementResult result;

		public void run() {
			long prevSend = 0;
			long prevRecv = 0;
			long sendBytes = 0;
			long recvBytes = 0;
			long intervalSend = 0;
			long intervalRecv = 0;
			long prevPktSend = 0;
			long prevPktRecv = 0;
			long sendPkt = 0;
			long recvPkt = 0;
			long intervalPktSend = 0;
			long intervalPktRecv = 0;
			int interval = busyInterval;
			while (true) {
				sendBytes = TrafficStats.getMobileTxBytes();
				recvBytes = TrafficStats.getMobileRxBytes();
				sendPkt = TrafficStats.getMobileTxPackets();
				sendPkt = TrafficStats.getMobileRxPackets();
				if (prevSend > 0 || prevRecv > 0) {
					intervalSend = sendBytes - prevSend;
					intervalRecv = recvBytes - prevRecv;
				}
				if (prevPktSend > 0 || prevPktRecv > 0) {
					intervalPktSend = sendPkt - prevPktSend;
					intervalPktRecv = recvPkt - prevPktRecv;
				}
				prevSend = sendBytes;
				prevRecv = recvBytes;
				prevPktSend = sendPkt;
				prevPktRecv = recvPkt;
				PhoneUtils phoneUtils = PhoneUtils.getPhoneUtils();
				Map<String, Object> contextResult = new HashMap<String, Object>();
				contextResult.put("timestamp",
						System.currentTimeMillis() * 1000);
				contextResult.put("rssi", phoneUtils.getCurrentRssi());
				contextResult.put("inc_mobile_bytes_send", intervalSend);
				contextResult.put("inc_mobile_bytes_recv", intervalRecv);
				contextResult.put("inc_mobile_pkt_send", intervalPktSend);
				contextResult.put("inc_mobile_pkt_recv", intervalPktRecv);
				contextResult.put("interval", interval);
				contextResult.put("battery_level",
						phoneUtils.getCurrentBatteryLevel());
				currentContext = contextResult;
				contextResultVector.add(contextResult);
				if(contextResultVector.size()>2000){
					contextResultVector.clear();
				}
				if (isBusy == 0) {
					interval = idleInterval;
				} else {
					interval = busyInterval;
				}
{'fraction_non_alphanumeric': 0.09911678115799803, 'fraction_numerical': 0.012757605495583905, 'mean_word_length': 3.9332042594385284, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7390787', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1578, 'n_words': 381}