1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.parser; 17 18 import com.android.loganalysis.item.QtaguidItem; 19 20 import java.util.List; 21 22 /** 23 * An {@link IParser} to handle the output of {@code xt_qtaguid}. 24 */ 25 public class QtaguidParser implements IParser { 26 27 /** 28 * Parses the output of "cat /proc/net/xt_qtaguid/stats". 29 * This method only parses total received bytes and total sent bytes per user. 30 * 31 * xt_qtaguid contains network usage per uid in simple space separated format. 32 * The first row of the output is description, and actual data follow. Example: 33 * IDX IFACE ACCT_TAG_HEX UID_TAG_INT CNT_SET RX_BYTES RX_PACKETS TX_BYTES ... (omitted) 34 * 2 wlan0 0x0 0 0 669013 7534 272120 ... 35 * 3 wlan0 0x0 0 1 0 0 0 ... 36 * 4 wlan0 0x0 1000 0 104010 860 135166 ... 37 * ... 38 */ 39 @Override 40 public QtaguidItem parse(List<String> lines) { 41 QtaguidItem item = new QtaguidItem(); 42 for (String line : lines) { 43 String[] columns = line.split(" ", -1); 44 if (columns.length < 8 || columns[0].equals("IDX")) { 45 continue; 46 } 47 48 try { 49 int uid = Integer.parseInt(columns[3]); 50 int rxBytes = Integer.parseInt(columns[5]); 51 int txBytes = Integer.parseInt(columns[7]); 52 53 if (item.contains(uid)) { 54 item.updateRow(uid, rxBytes, txBytes); 55 } else { 56 item.addRow(uid, rxBytes, txBytes); 57 } 58 } catch (NumberFormatException e) { 59 // ignore 60 } 61 } 62 63 return item; 64 } 65 } 66