Search in sources :

Example 6 with PkgInfo

use of com.tencent.wstt.apt.data.PkgInfo in project GT by Tencent.

the class GetPMAPInfoAction method run.

@Override
public void run() {
    /**
		 * 获取进程名称和PID,并获取当前时间
		 */
    TableItem[] selectData = tableViewer.getTable().getSelection();
    if (selectData == null || selectData.length == 0) {
        return;
    }
    PkgInfo itemData = (PkgInfo) selectData[0].getData();
    final String pkgName = itemData.contents[PkgInfo.NAME_INDEX];
    final String pid = GetPkgInfosByPsUtil.getPid(pkgName);
    if (pid == null) {
        APTConsoleFactory.getInstance().APTPrint("对应进程不存在");
        return;
    }
    /**
		 * 执行pmap -x pid命令,并将输出写文件
		 */
    Thread thread = new Thread(new Runnable() {

        @Override
        public synchronized void run() {
            Date curDate = new Date(System.currentTimeMillis());
            String curDateStr = Constant.SIMPLE_DATE_FORMAT_SECOND.format(curDate);
            String fileName = pkgName.replace(":", "-") + "_" + pid + "_pmap_" + curDateStr + ".txt";
            String filePath = Constant.LOG_FOLDER_ON_PC + File.separator + fileName;
            FileWriter fw = null;
            try {
                File file = new File(filePath);
                fw = new FileWriter(file);
            } catch (IOException e) {
                e.printStackTrace();
                APTConsoleFactory.getInstance().APTPrint("文件创建失败:" + filePath);
                return;
            }
            String cmdOutputStr = CMDExecute.runCMD(PCInfo.adbShell + " pmap -x " + pid);
            try {
                fw.write(cmdOutputStr);
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
                MessageDialog.openInformation(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "提示", "写文件失败_" + filePath);
                APTConsoleFactory.getInstance().APTPrint("pmap失败");
            }
            APTConsoleFactory.getInstance().APTPrint("pmap获取完成:" + filePath);
        }
    });
    thread.start();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) FileWriter(java.io.FileWriter) IOException(java.io.IOException) PkgInfo(com.tencent.wstt.apt.data.PkgInfo) File(java.io.File) Date(java.util.Date)

Example 7 with PkgInfo

use of com.tencent.wstt.apt.data.PkgInfo in project GT by Tencent.

the class GetSMAPInfoAction method run.

@Override
public void run() {
    /**
		 * TODO 检查当前是否root
		 */
    /**
		 * 获取进程名称和PID,并获取当前时间
		 */
    TableItem[] selectData = tableViewer.getTable().getSelection();
    if (selectData == null || selectData.length == 0) {
        return;
    }
    PkgInfo itemData = (PkgInfo) selectData[0].getData();
    final String pkgName = itemData.contents[PkgInfo.NAME_INDEX];
    //这样就确保了pid是最新的,不用刷新进程列表
    final String pid = GetPkgInfosByPsUtil.getPid(pkgName);
    if (pid == null) {
        APTConsoleFactory.getInstance().APTPrint(Constant.APTCONSOLE_LOG_TAGS[Constant.APTCONSOLE_LOG_TAG_ERR] + "对应进程不存在");
        return;
    }
    /**
		 * 执行cat /proc/pid/smap命令,并将输出写文件
		 */
    Thread thread = new Thread(new Runnable() {

        @Override
        public synchronized void run() {
            Date curDate = new Date(System.currentTimeMillis());
            String curDateStr = Constant.SIMPLE_DATE_FORMAT_SECOND.format(curDate);
            String fileName = pkgName.replace(":", "-") + "_" + pid + "_smap_" + curDateStr + ".txt";
            String filePath = Constant.SMAPS_LOG_PATH_ON_PC + File.separator + fileName;
            FileWriter fw = null;
            try {
                //首先检查目录是否存在
                File dirFile = new File(Constant.SMAPS_LOG_PATH_ON_PC);
                if (!dirFile.exists()) {
                    //mkdir 不会自动创建不存在的父目录
                    if (!dirFile.mkdirs()) {
                        APTConsoleFactory.getInstance().APTPrint(Constant.APTCONSOLE_LOG_TAGS[Constant.APTCONSOLE_LOG_TAG_ERR] + "创建目录失败" + Constant.SMAPS_LOG_PATH_ON_PC);
                        return;
                    }
                }
                File file = new File(filePath);
                if (!file.exists()) {
                    if (!file.createNewFile()) {
                        APTConsoleFactory.getInstance().APTPrint(Constant.APTCONSOLE_LOG_TAGS[Constant.APTCONSOLE_LOG_TAG_ERR] + "创建文件失败" + filePath);
                        return;
                    }
                }
                fw = new FileWriter(file);
            } catch (IOException e) {
                e.printStackTrace();
                APTConsoleFactory.getInstance().APTPrint(Constant.APTCONSOLE_LOG_TAGS[Constant.APTCONSOLE_LOG_TAG_CRASH] + "文件创建异常:" + filePath);
                return;
            }
            String cmdOutputStr = CMDExecute.runCMD(PCInfo.adbShell + " su -c cat /proc/" + pid + "/smaps");
            try {
                fw.write(cmdOutputStr);
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
                MessageDialog.openInformation(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "提示", "写文件失败_" + filePath);
                APTConsoleFactory.getInstance().APTPrint(Constant.APTCONSOLE_LOG_TAGS[Constant.APTCONSOLE_LOG_TAG_CRASH] + "获取smap文件异常");
            }
            APTConsoleFactory.getInstance().APTPrint(Constant.APTCONSOLE_LOG_TAGS[Constant.APTCONSOLE_LOG_TAG_INFO] + "获取smap文件完成:" + filePath);
        }
    });
    thread.start();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) FileWriter(java.io.FileWriter) IOException(java.io.IOException) PkgInfo(com.tencent.wstt.apt.data.PkgInfo) File(java.io.File) Date(java.util.Date)

Example 8 with PkgInfo

use of com.tencent.wstt.apt.data.PkgInfo in project GT by Tencent.

the class DevicesView method getIndexByPkgName.

private int getIndexByPkgName(String pkgName, TableViewer viewer) {
    if (pkgName == null || viewer == null) {
        return -1;
    }
    TableItem[] tableItems = viewer.getTable().getItems();
    if (tableItems == null) {
        return -1;
    }
    int len = tableItems.length;
    for (int i = 0; i < len; i++) {
        PkgInfo element = (PkgInfo) tableItems[i].getData();
        if (pkgName.equals(element.contents[PkgInfo.NAME_INDEX])) {
            return i;
        }
    }
    return -1;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) PkgInfo(com.tencent.wstt.apt.data.PkgInfo)

Example 9 with PkgInfo

use of com.tencent.wstt.apt.data.PkgInfo in project GT by Tencent.

the class DevicesView method makeActions.

/**
	 * 初始化action
	 */
private void makeActions() {
    /**
		 * 测试按钮
		 */
    testAction = new StartTestAction();
    testAction.setText("Start");
    testAction.setToolTipText("开始检测");
    testAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/start.png"));
    /**
		 * 刷新按钮
		 */
    refreshAction = new Action() {

        public void run() {
            refreshGetPkgInfo();
        }
    };
    refreshAction.setText("获取手机上的进程列表");
    refreshAction.setToolTipText("获取手机上的进程列表");
    refreshAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/refresh.png"));
    /**
		 * 打开log目录
		 */
    openResultDirAction = new Action() {

        public void run() {
            try {
                if (PCInfo.OSName.toLowerCase().indexOf("window") != -1) {
                    Runtime.getRuntime().exec("explorer.exe " + Constant.LOG_FOLDER_ON_PC + File.separator + TestSence.getInstance().curDir);
                } else {
                    Runtime.getRuntime().exec("open " + Constant.LOG_FOLDER_ON_PC + File.separator + TestSence.getInstance().curDir);
                }
            } catch (IOException e) {
                e.printStackTrace();
                APTConsoleFactory.getInstance().APTPrint("打开测试结果文件夹失败");
            }
        }
    };
    openResultDirAction.setText("打开测试结果保存目录");
    openResultDirAction.setToolTipText("打开测试结果保存目录");
    openResultDirAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/open_pc.png"));
    /**
		 * 打开log
		 */
    openLogWithChartAction = new Action() {

        public void run() {
            FileDialog dialog = new FileDialog(sourcePkgTableViewer.getControl().getShell(), SWT.OPEN);
            //设置初始路径
            dialog.setFilterPath(Constant.LOG_FOLDER_ON_PC);
            //返回的全路径(路径+文件名)
            final String fileName = dialog.open();
            if (fileName == null) {
                return;
            }
            final APTLogFileHeader afh = APTLogFileParse.pareseAPTLogFileHeader(fileName);
            if (afh == null) {
                APTConsoleFactory.getInstance().APTPrint("文件头格式不兼容");
                return;
            }
            //在数据量比较大时,解析会比较大
            APTState.getInstance().DealWithEventBefore(APTEventEnum.OPENLOG_OPER);
            APTConsoleFactory.getInstance().APTPrint("正解析log数据,请稍候......");
            final CPUView cpuViewPart = (CPUView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(CPUView.ID);
            final MemoryView memViewPart = (MemoryView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(MemoryView.ID);
            cpuViewPart.setCpuTableViewerFilter(null);
            cpuViewPart.setJiffiesTableViewerFilter(null);
            memViewPart.setTableViewerFilter(null);
            Thread parseLogThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    final JfreeChartDatas datas = APTLogFileParse.getData(fileName, afh);
                    if (datas == null) {
                        APTConsoleFactory.getInstance().APTPrint("文件格式不兼容");
                        return;
                    }
                    if (datas.monitorItem.equals(Constant.TEXT_ITEM_TITLES[Constant.CPU_INDEX])) {
                        cpuViewPart.cpuRealTimeChart.fillData(datas);
                    } else {
                        memViewPart.memRealTimeChart.fillData(datas);
                    }
                }
            });
            parseLogThread.start();
            try {
                //TODO 这里使用会不会存在很卡的情况,打开比较大的文件的时候
                parseLogThread.join();
                for (int i = 0; i < afh.pkgNames.length; i++) {
                    PkgInfo item = new PkgInfo();
                    item.contents[PkgInfo.NAME_INDEX] = afh.pkgNames[i];
                    item.contents[PkgInfo.PID_INDEX] = "-1";
                    addDataItem(targetPkgTableViewer, item);
                }
                APTState.getInstance().DealWithEventAfter(APTEventEnum.OPENLOG_OPER);
                //APTConsoleFactory.getInstance().APTPrint("打开log更新");
                GetCurCheckedStateUtil.update();
                APTConsoleFactory.getInstance().APTPrint("log打开完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };
    openLogWithChartAction.setText("用JFreechart打开log");
    openLogWithChartAction.setToolTipText("用JFreechart打开log");
    openLogWithChartAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/generate_chart.png"));
    /**
		 * 复制数据
		 */
    copyAction = new CopyAllFromTableViewAction(sourcePkgTableViewer);
    copyAction.setText("复制");
    copyAction.setToolTipText("复制当前显示的表格数据到剪切板");
    ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/save.png");
    copyAction.setImageDescriptor(descriptor);
    /**
		 * 添加菜单
		 */
    addPkgAction = new Action() {

        @Override
        public void run() {
            if (isSupportAddOrDeleteOper) {
                super.run();
                APTState.getInstance().DealWithEventBefore(APTEventEnum.CONFIGRURE_OPER);
                IStructuredSelection iss = (IStructuredSelection) sourcePkgTableViewer.getSelection();
                if (iss == null) {
                    return;
                }
                PkgInfo itemData = (PkgInfo) iss.getFirstElement();
                addDataItem(targetPkgTableViewer, itemData);
                APTState.getInstance().DealWithEventAfter(APTEventEnum.CONFIGRURE_OPER);
            } else {
                APTConsoleFactory.getInstance().APTPrint("Operation forbid");
            }
        }
    };
    addPkgAction.setText("添加");
    addPkgAction.setToolTipText("添加该进程到被测进程列表");
    addPkgAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/add.png"));
    /**
		 * 删除菜单
		 */
    removePkgAction = new Action() {

        @Override
        public void run() {
            if (isSupportAddOrDeleteOper) {
                super.run();
                APTState.getInstance().DealWithEventBefore(APTEventEnum.CONFIGRURE_OPER);
                TableItem[] selectData = targetPkgTableViewer.getTable().getSelection();
                if (selectData == null || selectData.length == 0) {
                    return;
                }
                PkgInfo itemData = (PkgInfo) selectData[0].getData();
                targetPkgTableViewer.remove(itemData);
                APTState.getInstance().DealWithEventAfter(APTEventEnum.CONFIGRURE_OPER);
            } else {
                APTConsoleFactory.getInstance().APTPrint("Operation forbid");
            }
        }
    };
    removePkgAction.setText("删除");
    removePkgAction.setToolTipText("从被测进程列表中删除该进程");
    removePkgAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/remove.png"));
    pmapAction = new GetPMAPInfoAction(sourcePkgTableViewer);
    pmapAction.setText("PMAP");
    pmapAction.setToolTipText("PMAP");
    pmapAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/pmap.png"));
    smapAction = new GetSMAPInfoAction(sourcePkgTableViewer);
    smapAction.setText("SMAP");
    smapAction.setToolTipText("SMAP");
    smapAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/pmap.png"));
    dumpHprofAction = new DumpHprofAction();
    dumpHprofAction.setText("DumpHprof");
    dumpHprofAction.setToolTipText("DumpHprof");
    dumpHprofAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/dump.png"));
    gcAction = new GCAction();
    gcAction.setText("GC");
    gcAction.setToolTipText("GC");
    gcAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Constant.PLUGIN_ID, "icons/gc.png"));
}
Also used : GCAction(com.tencent.wstt.apt.action.GCAction) CopyAllFromTableViewAction(com.tencent.wstt.apt.statistics.actions.CopyAllFromTableViewAction) GetSMAPInfoAction(com.tencent.wstt.apt.action.GetSMAPInfoAction) DumpHprofAction(com.tencent.wstt.apt.action.DumpHprofAction) StartTestAction(com.tencent.wstt.apt.action.StartTestAction) GetPMAPInfoAction(com.tencent.wstt.apt.action.GetPMAPInfoAction) Action(org.eclipse.jface.action.Action) DumpHprofAction(com.tencent.wstt.apt.action.DumpHprofAction) StartTestAction(com.tencent.wstt.apt.action.StartTestAction) IOException(java.io.IOException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) APTLogFileHeader(com.tencent.wstt.apt.file.APTLogFileParse.APTLogFileHeader) PkgInfo(com.tencent.wstt.apt.data.PkgInfo) JfreeChartDatas(com.tencent.wstt.apt.file.APTLogFileParse.JfreeChartDatas) GetSMAPInfoAction(com.tencent.wstt.apt.action.GetSMAPInfoAction) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) GCAction(com.tencent.wstt.apt.action.GCAction) CopyAllFromTableViewAction(com.tencent.wstt.apt.statistics.actions.CopyAllFromTableViewAction) FileDialog(org.eclipse.swt.widgets.FileDialog) GetPMAPInfoAction(com.tencent.wstt.apt.action.GetPMAPInfoAction)

Example 10 with PkgInfo

use of com.tencent.wstt.apt.data.PkgInfo in project GT by Tencent.

the class DevicesView method createTableView.

/**
	 * 初始化tableviewer
	 * 仅仅支持单选
	 * @param parent
	 */
private void createTableView(Composite parent) {
    sourcePkgTableViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    // 设置表头内容 
    for (int i = 0; i < SOURCE_COLUMN_NAME.length; i++) {
        new TableColumn(sourcePkgTableViewer.getTable(), SWT.LEFT).setText(SOURCE_COLUMN_NAME[i]);
    }
    sourcePkgTableViewer.getTable().getColumn(0).setWidth(200);
    sourcePkgTableViewer.getTable().getColumn(1).setWidth(50);
    // 设置表头和表格线可见
    sourcePkgTableViewer.getTable().setHeaderVisible(true);
    sourcePkgTableViewer.getTable().setLinesVisible(true);
    sourcePkgTableViewer.setSorter(new APTTableSorter());
    // 分别为表头的每一列注册事件
    for (int i = 0; i < SOURCE_COLUMN_NAME.length; i++) {
        final int j = i;
        TableColumn column = sourcePkgTableViewer.getTable().getColumn(j);
        column.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                //					// 单击时,重新设置排序对象属性
                ((APTTableSorter) sourcePkgTableViewer.getSorter()).doSort(j);
                // 刷新表格数据
                sourcePkgTableViewer.refresh();
            }
        });
    }
    sourcePkgTableViewer.setContentProvider(new ViewContentProvider());
    sourcePkgTableViewer.setLabelProvider(new ViewLabelProvider());
    sourcePkgTableViewer.getTable().addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            if (isSupportAddOrDeleteOper) {
                //APTConsoleFactory.getInstance().APTPrint("start ");
                APTState.getInstance().DealWithEventBefore(APTEventEnum.CONFIGRURE_OPER);
                //APTConsoleFactory.getInstance().APTPrint("1 ");
                // 获取当前选择的进程
                IStructuredSelection iss = (IStructuredSelection) sourcePkgTableViewer.getSelection();
                //APTConsoleFactory.getInstance().APTPrint("2 ");
                if (iss == null) {
                    //APTConsoleFactory.getInstance().APTPrint("iss == null");
                    return;
                }
                PkgInfo itemData = (PkgInfo) iss.getFirstElement();
                //APTConsoleFactory.getInstance().APTPrint("3");
                addDataItem(targetPkgTableViewer, itemData);
                //APTConsoleFactory.getInstance().APTPrint("4");
                APTState.getInstance().DealWithEventAfter(APTEventEnum.CONFIGRURE_OPER);
            //APTConsoleFactory.getInstance().APTPrint("5");
            } else {
                APTConsoleFactory.getInstance().APTPrint("Operation forbid");
            }
        }
    });
    sourcePkgTableViewer.getTable().setToolTipText("双击或者右键菜单可添加指定进程到被测进程列表");
    FormData tableViewFormData = new FormData();
    tableViewFormData.left = new FormAttachment(0, 5);
    tableViewFormData.right = new FormAttachment(100, -5);
    tableViewFormData.top = new FormAttachment(targetPkgTableViewer.getTable(), 10);
    tableViewFormData.bottom = new FormAttachment(100, -5);
    Table table = sourcePkgTableViewer.getTable();
    table.setLayoutData(tableViewFormData);
}
Also used : FormData(org.eclipse.swt.layout.FormData) MouseEvent(org.eclipse.swt.events.MouseEvent) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableColumn(org.eclipse.swt.widgets.TableColumn) PkgInfo(com.tencent.wstt.apt.data.PkgInfo) MouseListener(org.eclipse.swt.events.MouseListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

PkgInfo (com.tencent.wstt.apt.data.PkgInfo)11 TableItem (org.eclipse.swt.widgets.TableItem)5 IOException (java.io.IOException)3 FormAttachment (org.eclipse.swt.layout.FormAttachment)3 FormData (org.eclipse.swt.layout.FormData)3 DevicesView (com.tencent.wstt.apt.ui.views.DevicesView)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Date (java.util.Date)2 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 MouseListener (org.eclipse.swt.events.MouseListener)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Table (org.eclipse.swt.widgets.Table)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 DumpHprofAction (com.tencent.wstt.apt.action.DumpHprofAction)1 GCAction (com.tencent.wstt.apt.action.GCAction)1 GetPMAPInfoAction (com.tencent.wstt.apt.action.GetPMAPInfoAction)1