未命名
android客户端应用(native
app)适配测试自动化
东海陈光剑
2014年5月5日 0:39:04
http://10.125.1.58:88/report.html?run_stamp=20140428054354&min=3&sec=214
<!doctype
html>
<html>
<head>
<meta charset="UTF-8">
<title>适配测试报告</title>
<script src="http://g.tbcdn.cn/kissy/k/1.4.0/seed-min.js"></script>
<style type="text/css">
body {
background-color: #EEFFFF;
}
p.serif{font-family:"Times
New Roman",Georgia,Serif}
p.sansserif{font-family:Arial,Verdana,Sans-serif}
</style>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
var run_stamp0 = 20140428052333;
var href =
location.href;
var m, run_stamp;
m =
href.match(/stamp=(\d+)/);
if(!m) run_stamp =
run_stamp0;
else run_stamp =
m[1] ;
$.ajax({
url :
‘http://10.125.1.58:8888/ReportServlet/cpu?run_stamp=‘+run_stamp, //请求地址
type : ‘GET‘, //POST或GET请求
data : {
siteName : "http://10.125.1.58:8888" //参数
JSON格式 如果是GET请求可以直接在URL里写
},
dataType : ‘jsonp‘,//json 或者 jsonp 默认是html
timeout : 10000,
error :
function() {
alert(‘Time out loading
:http://10.125.1.58:8888/ReportServlet/cpu?run_stamp=‘+run_stamp);
},
success :
function(JSON) {
var
SIZE = JSON.result.length
var y
= new
Array(SIZE);
var device = new Array(SIZE);
for(i=0; i < SIZE;i++){
y[i] =
JSON.result[i].cpu_perctg;//alert(y[i]);
device[i] =
JSON.result[i].device_id[0];
}
for(i=0; i < SIZE;i++){
for(j=0;
j < y[i].length; j++){
y[i][j] =
parseInt(y[i][j]);
}
}
/*var
ss1 = new Array(SIZE); 创建一个长度为size的数组
new Array(size)->ss1=[undefined, undefined, undefined,
undefined, undefined];
然后再push进去
ss1=[undefined, undefined, undefined, undefined, undefined,
{name: "xxx", data: "xxx"}]; @zwj
*/
var ss1 =
[];
for(j=0; j<SIZE;j++){
var
item={};
item.name =
‘device:‘ +
device[j];
item.data =
y[j];
ss1.push(item);
}
/*
var ss2=[
{
name: ‘device:‘+device[0],
data: y[0]
},
{
name:
‘device:‘+device[1],
data: y[1]
},
{
name: ‘device:‘+device[2],
data: y[2]
},
{
name:
‘device:‘+device[3],
data: y[3]
},
{
name: ‘device:‘+device[4],
data: y[4]
}
];
*/
///////////////////////////////////////////////////////////////////////////////////////
$(‘#container_cpu_perctg‘).highcharts({
title: {
text: ‘CPU%‘,
},
xAxis:
{
labels: {
enabled:
false
}
},
yAxis: {
min: 0,
title: {
text:
‘CPU%‘
},
plotLines: [{
value: 0,
width: 1,
color: ‘#808080‘
}]
},
tooltip:
{
valueSuffix: ‘%‘
},
legend: {
layout: ‘vertical‘,
align: ‘right‘,
verticalAlign: ‘middle‘,
borderWidth: 0
},
series: ss1
});
//////////////////////////////////////////////////////////////////////////////////////////////
for(i=0; i < SIZE;i++){
y[i] =
JSON.result[i].cpu_vss;//alert(y[i]);
//device[i] =
JSON.result[i].device_id[0];
}
for(i=0; i < SIZE;i++){
for(j=0;
j < y[i].length; j++){
y[i][j] =
parseInt(y[i][j]);
}
}
/*var
ss1 = new Array(SIZE); 创建一个长度为size的数组
new Array(size)->ss1=[undefined, undefined, undefined,
undefined, undefined];
然后再push进去
ss1=[undefined, undefined, undefined, undefined, undefined,
{name: "xxx", data: "xxx"}]; @zwj
*/
var ss_vss =
[];
for(j=0; j<SIZE;j++){
var
item={};
item.name =
‘device:‘ +
device[j];
item.data =
y[j];
ss_vss.push(item);
}
$(‘#container_cpu_vss‘).highcharts({
title: {
text: ‘VSS(KB)虚拟内存‘,
},
xAxis:
{
labels: {
enabled:
false
}
},
yAxis: {
min: 0,
title: {
text:
‘VSS(KB)‘
},
plotLines: [{
value:
0,
width: 1,
color:
‘#808080‘
}]
},
tooltip: {
valueSuffix: ‘KB‘
},
legend: {
layout: ‘vertical‘,
align: ‘right‘,
verticalAlign: ‘middle‘,
borderWidth: 0
},
series: ss_vss
});
//////////////////////////////////////////////////////////////////////////////////////////////
for(i=0; i < SIZE;i++){
y[i] =
JSON.result[i].cpu_rss;//alert(y[i]);
//device[i] =
JSON.result[i].device_id[0];
}
for(i=0; i < SIZE;i++){
for(j=0;
j < y[i].length; j++){
y[i][j] =
parseInt(y[i][j]);
}
}
/*var
ss1 = new Array(SIZE); 创建一个长度为size的数组
new Array(size)->ss1=[undefined, undefined, undefined,
undefined, undefined];
然后再push进去
ss1=[undefined, undefined, undefined, undefined, undefined,
{name: "xxx", data: "xxx"}]; @zwj
*/
var ss_rss =
[];
for(j=0; j<SIZE;j++){
var
item={};
item.name =
‘device:‘ +
device[j];
item.data =
y[j];
ss_rss.push(item);
}
$(‘#container_cpu_rss‘).highcharts({
title: {
text: ‘RSS(KB)常驻内存‘,
},
xAxis:
{
labels: {
enabled:
false
}
},
yAxis: {
min: 0,
title: {
text:
‘RSS(KB)‘
},
plotLines: [{
value:
0,
width: 1,
color:
‘#808080‘
}]
},
tooltip: {
valueSuffix: ‘KB‘
},
legend: {
layout: ‘vertical‘,
align: ‘right‘,
verticalAlign: ‘middle‘,
borderWidth: 0
},
series: ss_rss
});
//////////////////////////////////////////////////////////////////////////////////////////////
for(i=0; i < SIZE;i++){
y[i] =
JSON.result[i].cpu_thr;//alert(y[i]);
//device[i] =
JSON.result[i].device_id[0];
}
for(i=0; i < SIZE;i++){
for(j=0;
j < y[i].length; j++){
y[i][j] =
parseInt(y[i][j]);
}
}
/*var
ss1 = new Array(SIZE); 创建一个长度为size的数组
new Array(size)->ss1=[undefined, undefined, undefined,
undefined, undefined];
然后再push进去
ss1=[undefined, undefined, undefined, undefined, undefined,
{name: "xxx", data: "xxx"}]; @zwj
*/
var ss_thr =
[];
for(j=0; j<SIZE;j++){
var
item={};
item.name =
‘device:‘ +
device[j];
item.data =
y[j];
ss_thr.push(item);
}
$(‘#container_cpu_thr‘).highcharts({
title: {
text: ‘THR(线程数)‘,
},
xAxis:
{
labels: {
enabled:
false
}
},
yAxis: {
min: 0,
title: {
text:
‘THR‘
},
plotLines: [{
value: 0,
width: 1,
color: ‘#808080‘
}]
},
tooltip:
{
valueSuffix: ‘‘
},
legend: {
layout: ‘vertical‘,
align: ‘right‘,
verticalAlign: ‘middle‘,
borderWidth: 0
},
series: ss_thr
});
}});
</script>
<script src="js/highcharts.js"></script>
<script src="js/modules/data.js"></script>
<script src="js/modules/exporting.js"></script>
</head>
<body class="serif">
<br><br><br><br>
<h1 align="center"style=font-family:微软雅黑>一淘android客户端适配测试报告</h1>
<p
align="right">
<label for="issue_issue_author_id">联系人:陈光剑</label>
<a href="http://www.taobao.com/webww/ww.php?ver=3&touid=universsky1&siteid=cntaobao&status=2&charset=utf-8"
class="inline-item" target="_blank" title="universsky1"><img alt="universsky1" border="0" src="http://amos.alicdn.com/realonline.aw?v=2&uid=universsky1&site=cntaobao&s=2&charset=utf-8"
/></a><a href="http://amos.alicdn.com/msg.aw?v=2&uid=universsky1&site=cnalichn&s=11&charset=UTF-8"
class="inline-item" target="_blank" title="universsky1"></a>
</p>
<div id=time
align="right"
style=font-family:Verdana></div>
<script>setInterval("time.innerHTML=‘今天是‘+new Date().toLocaleString()+‘
星期‘+‘日一二三四五六‘.charAt(new Date().getDay())+‘ ‘;",1000);</script>
<div id="container_cpu_perctg"
style="min-width: 100px;
height: 200px; margin: 0 auto"></div>
<br>
<div id="container_cpu_vss"
style="min-width: 100px;
height: 200px; margin: 0 auto"></div>
<br>
<div id="container_cpu_rss"
style="min-width: 100px;
height: 200px; margin: 0 auto"></div>
<br>
<div id="container_cpu_thr"
style="min-width: 100px;
height: 200px; margin: 0 auto"></div>
<br>
<script>
KISSY.ready(function(S){
var
path="http://10.125.1.58:88/img/";
var href =
location.href;
/**
*
调用系统默认浏览器打开链接 Apache httpd
*
http://127.0.0.1:88/report.html?run_stamp=20140302023811
* &sec=250&min=4
*/
var m,
run_stamp;
m = href.match(/stamp=(\d+)/);
if(!m) run_stamp
= "20140421122151";
else run_stamp =
m[1] ;
var sec
;
sec = href.match(/sec=(\d+)/);
if(!sec) se = 0;
else se=sec[1];
var min;
min =
href.match(/min=(\d+)/);
if(!min) mi=0;
else mi = min[1];
/*
请求报告资源接口,tomcat在8888端口监听 */
S.use("node,io", function(S, Node, IO){
IO({
//url: "http://10.125.1.58:8888/Report/go?run_stamp=" +
run_stamp,
url: "http://10.125.1.58:8888/ReportServlet/pic?run_stamp="
+ run_stamp,
dataType: "jsonp",
jsonpCallback: "report",
success: function(data) {
var report=data;
var
runtime_log = path +
run_stamp + "$runtime.log";
//var cpu_log
= ‘http://10.125.1.58:88/cpu.html?run_stamp=‘ +
run_stamp;
var cpu_log
= path +
run_stamp + "$cpu_usage.log";
var bodyContent="<p align=right ><font
face=\"verdana\">开始时间:" + run_stamp +"</font></p>";
bodyContent = bodyContent + "<p
align=right ><font face=\"verdana\">运行时间: " +
se + "s ( " + mi + " min ) </font></p>";
bodyContent = bodyContent +
"<p align=left ><font face=\"verdana\"><a
href=\""+runtime_log+"\">运行结果(点击查看)</a></font></p>";
bodyContent = bodyContent +
"<p align=left ><font face=\"verdana\"><a
href=\""+cpu_log +"\">CPU使用情况(点击查看)</a></font></p>";
bodyContent = bodyContent + "<hr noshade size=5 align=center width=100%
/>";
bodyContent = bodyContent +
"<table style=\"table-layout:fixed\"
border=\"0\">";
/*表格总开始*/
// 遍历DeviceID
for (var i
= 0; i <
report.result.length; i++) {
bodyContent=bodyContent+"<tr><td width=\"80\"
scope=\"col\"><font face=\"verdana\"
>DeviceId(日志)</font></td>";
for (var j
= 0; j <
report.result[i].img_timestamp.length; j++)
{
bodyContent =
bodyContent+"<td
style=\"word-break : break-all\"; \"overflow:hidden\"; width=\"100\"
scope=\"col\"><font face=\"verdana\" >"+report.result[i].url[j]+"</font></td>";
}
bodyContent = bodyContent+"</tr>";
/*以上是urls行*/
/*这里是log记录*/
var log_url = path
+ run_stamp + "$" +
report.result[i].device_id + "$runtime.log";
bodyContent =
bodyContent+ "<tr><td scope=\"row\"><font face=\"verdana\"
>"+report.result[i].device_id + "</font></td>";
//bodyContent = bodyContent+ "<tr><td
scope=\"row\"><font face=\"verdana\" ><a
href=\""+log_url+"\">"+report.result[i].device_id +
"</a></font></td>";
/*下面是imgsrc行*/
for (var j
= 0; j <
report.result[i].img_timestamp.length; j++)
{
var imgsrc_url = path
+ report.run_stamp+"$"+
report.result[i].device_id+"$"+
report.result[i].img_timestamp[j]+"$"+
report.result[i].img_name[j];
bodyContent = bodyContent+
"<td><a href=\""+ imgsrc_url +"\"><img src=\"" +imgsrc_url+
"\" width=\"200\"
height=\"300\"></td>";
}
bodyContent = bodyContent+"</tr>";
};
/********************************************************************************************************************/
/*总表格结束*/
bodyContent=bodyContent+"</table>";
/*输出总的报告*/
//
document.write("<html><head><title>适配测试报告 " + report.run_stamp
+ "</title></head><body>" + bodyContent);
//document.write("</body></html>");
S.one("body").append(bodyContent);
}
})
});
});
</script>
</body>
</html>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ReportServlet</groupId>
<artifactId>ReportServlet</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ReportServlet</name>
<description>ReportServlet</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- 依赖的jar包们 -->
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<dependency>
<groupId>com.google.gson</groupId>
<artifactId>gson-fixed</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.google.gson</groupId>
<artifactId>gson-fixed</artifactId>
<version>1.0.0</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>ReportServlet</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>CTPics</description>
<display-name>CTPics</display-name>
<servlet-name>CTPics</servlet-name>
<servlet-class>universsky.ct.report.CTPics</servlet-class>
</servlet>
<servlet>
<description>CTCpuUsage</description>
<display-name>CTCpuUsage</display-name>
<servlet-name>CTCpuUsage</servlet-name>
<servlet-class>universsky.ct.report.CTCpuUsage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CTPics</servlet-name>
<url-pattern>/pic</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CTCpuUsage</servlet-name>
<url-pattern>/cpu</url-pattern>
</servlet-mapping>
</web-app>
/**
* QueryResult.java ct.dao Report 下午10:14:57 2014年2月28日 2014
*/
package universsky.ct.result;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 东海陈光剑 2014年2月28日 下午10:14:57
*/
public class QueryPics {
/**
* @param args
* void main
*/
public static void main(String[] args) {
String run_stamp = "20140426114928";
QueryPics qr = new QueryPics();
// Map<String, ArrayList<String>> result = qr.query(run_stamp,
// device_id);
List<HashMap<String, ArrayList<String>>> result = qr.query(run_stamp);
System.out.println(result);
}
public List<HashMap<String, ArrayList<String>>> query(String run_stamp) {
ArrayList<String> deviceList = getDeviceList(run_stamp);
List<HashMap<String, ArrayList<String>>> result = new ArrayList<HashMap<String, ArrayList<String>>>();
// Map<String, ArrayList<String>> imgName = new HashMap<String,
// ArrayList<String>>();
// Map<String, ArrayList<String>> imgTimeStamp = new HashMap<String,
// ArrayList<String>>();
try {
Class.forName("com.mysql.jdbc.Driver"); // 加载MYSQL JDBC驱动程序
System.out.println("Success loading mysql driver!");
} catch (Exception e) {
System.out.print("Error loading mysql driver!");
e.printStackTrace();
}
try {
Connection connect = DriverManager.getConnection(
"jdbc:mysql://10.125.1.58:3306/test", "root", "isword");
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码
System.out.println("Success connect mysql server!");
Statement stmt = connect.createStatement();
for (String device_id : deviceList) {
String queryCmd = "SELECT * FROM ct_pic where run_stamp=‘"
+ run_stamp + "‘ and device_id=‘" + device_id
+ "‘ ORDER BY img_timestamp";
System.out.println(queryCmd);
ResultSet rs = stmt.executeQuery(queryCmd);
ArrayList<String> urlList = new ArrayList<String>();
ArrayList<String> imgNameList = new ArrayList<String>();
ArrayList<String> imgTimeStampList = new ArrayList<String>();
HashMap<String, ArrayList<String>> deviceMap = new HashMap<String, ArrayList<String>>();
while (rs.next()) {
System.out.println(rs.getString("url"));
urlList.add(rs.getString("url"));
System.out.println(rs.getString("img_name"));
imgNameList.add(rs.getString("img_name"));
System.out.println(rs.getString("img_timestamp"));
imgTimeStampList.add(rs.getString("img_timestamp"));
}
ArrayList<String> d = new ArrayList<String>(1);
d.add(device_id);
deviceMap.put("device_id", d);
deviceMap.put("url", urlList);
deviceMap.put("img_name", imgNameList);
deviceMap.put("img_timestamp", imgTimeStampList);
result.add(deviceMap);
}// end for
} catch (Exception e) {
e.printStackTrace();
}
// Map<String, ArrayList<String>> result = new HashMap<String,
// ArrayList<String>>();
// result.put("device_list", deviceList);
// result.put("url", urlList);
// result.put("img_name", imgNameList);
// result.put("img_timestamp", imgTimeStampList);
return result;
}
Map<String, ArrayList<String>> query(String run_stamp, String device_id) {
ArrayList<String> deviceList = getDeviceList(run_stamp);
ArrayList<String> urlList = new ArrayList<String>();
ArrayList<String> imgNameList = new ArrayList<String>();
ArrayList<String> imgTimeStampList = new ArrayList<String>();
try {
Class.forName("com.mysql.jdbc.Driver"); // 加载MYSQL JDBC驱动程序
System.out.println("Success loading mysql driver!");
} catch (Exception e) {
System.out.print("Error loading mysql driver!");
e.printStackTrace();
}
try {
Connection connect = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/test", "root", "isword");
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码
System.out.println("Success connect mysql server!");
Statement stmt = connect.createStatement();
String queryCmd = "SELECT * FROM ct_pic where run_stamp=‘"
+ run_stamp + "‘ and device_id=‘" + device_id
+ "‘ ORDER BY img_timestamp";
System.out.println(queryCmd);
ResultSet rs = stmt.executeQuery(queryCmd);
while (rs.next()) {
System.out.println(rs.getString("img_name"));
imgNameList.add(rs.getString("img_name"));
System.out.println(rs.getString("url"));
urlList.add(rs.getString("url"));
System.out.println(rs.getString("img_timestamp"));
imgTimeStampList.add(rs.getString("img_timestamp"));
}
} catch (Exception e) {
e.printStackTrace();
}
Map<String, ArrayList<String>> result = new HashMap<String, ArrayList<String>>();
result.put("device_list", deviceList);
result.put("url", urlList);
result.put("img_name", imgNameList);
result.put("img_timestamp", imgTimeStampList);
return result;
}
public ArrayList<String> getDeviceList(String run_stamp) {
ArrayList<String> deviceList = new ArrayList<String>();
try {
Connection connect = DriverManager.getConnection(
"jdbc:mysql://10.125.1.58:3306/test", "root", "isword");
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码
System.out.println("Success connect mysql server!");
Statement stmt = connect.createStatement();
String queryCmd = "SELECT device_id FROM ct_pic"
+ " where run_stamp=‘" + run_stamp
+ "‘ GROUP BY device_id;";
System.out.println(queryCmd);
ResultSet rs = stmt.executeQuery(queryCmd);
while (rs.next()) {
System.out.println(rs.getString("device_id"));
deviceList.add(rs.getString("device_id"));
}
} catch (Exception e) {
e.printStackTrace();
}
return deviceList;
}
}
/**
* QueryResult.java ct.dao Report 下午10:14:57 2014年2月28日 2014
*/
package universsky.ct.result;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.gson.Gson;
import com.mysql.fabric.xmlrpc.base.Array;
/**
* @author 东海陈光剑 2014年2月28日 下午10:14:57
*/
public class QueryCpuUsage {
/**
* @param args
* void main
*/
public static void main(String[] args) {
String run_stamp = "20140428052333";
QueryCpuUsage qr = new QueryCpuUsage();
List<HashMap<String, ArrayList<String>>> result = qr.query(run_stamp);
Gson gson = new Gson();
System.out.println(gson.toJson(result));// String json =
// gson.toJson(obj)
}
/**
*
* @param run_stamp
* @return
*/
public List<HashMap<String, ArrayList<String>>> query(String run_stamp) {
List<HashMap<String, ArrayList<String>>> result = new ArrayList<HashMap<String, ArrayList<String>>>();
ArrayList<String> msgList = new ArrayList<String>();
ArrayList<String> deviceList = new ArrayList<String>();
ArrayList<String> cpuUsageList = new ArrayList<String>();
HashMap<String, ArrayList<String>> cpuUsageMap = new HashMap<String, ArrayList<String>>();
try {
Class.forName("com.mysql.jdbc.Driver"); // 加载MYSQL JDBC驱动程序
System.out.println("Success loading mysql driver!");
} catch (Exception e) {
System.out.print("Error loading mysql driver!");
e.printStackTrace();
}
try {
Connection connect = DriverManager.getConnection(
"jdbc:mysql://10.125.1.58:3306/test", "root", "isword");
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码
System.out.println("Success connect mysql server!");
Statement stmt = connect.createStatement();
String queryCmd = "SELECT * FROM ct_perf where message like \"%"
+ run_stamp + "%\" ORDER BY pro_time";
System.out.println(queryCmd);
ResultSet rs = stmt.executeQuery(queryCmd);
while (rs.next()) {
String msg = rs.getString("message");
// System.out.println(msg);
if (msg.startsWith("cpu_usage")
&& msg.endsWith("com.taobao.etao")) {
msgList.add(msg);
String[] msgSplit = msg.split("[$]");
/**
* 0 | cpu_usage 1 | 20140428073427 2 | 096b3760 3 | 25252 0
* 24% S 36 895448K 65300K bg u0_a128 com.taobao.etao
*/
deviceList.add(msgSplit[2]);
cpuUsageList.add(msgSplit[3]);
String cpuUsage = msgSplit[3];
String[] cpuUsageSplit = cpuUsage
.split("[ \\s\\t\n\\x0B\\f\\r]");
int ii = 0;
for (String cs : cpuUsageSplit) {
if (!cs.isEmpty()) {
/**
* 0 | 25252 1 | 0 2 | 56% 3 | S 4 | 37 5 | 896488K
* 6 | 65320K 7 | bg 8 | u0_a128 9 | com.taobao.etao
*/
// System.out.println((ii++) + " | " + cs);
}
}
// System.out.println(msgSplit[3]);
// int col_index = 0;
// for (String col : msgSplit) {
// System.out.println((col_index++) + " | " + col);
// }
}
}
cpuUsageMap.put(run_stamp, msgList);
} catch (Exception e) {
e.printStackTrace();
}
// //////////////////////////////////////////////////////////////
for (String deviceId : deviceList) {
// System.out.println(deviceId);
}
for (String msg : msgList) {
// System.out.println(msg);
}
for (String e : cpuUsageList) {
// System.out.println(e);
}
List<String> deviceIdCpuList = new ArrayList<String>();
for (int i = 0; i < deviceList.size(); i++) {
deviceIdCpuList.add(i + " " + deviceList.get(i) + " "
+ cpuUsageList.get(i));
}
Map<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
for (int i = 0; i < deviceIdCpuList.size(); i++) {
// System.out.println(deviceIdCpuList.get(i));
String element = "";
String[] item = deviceIdCpuList.get(i).split("[\\s]");
int c = 0;
for (String e : item) {
if (!e.isEmpty()) {
// System.out.println((c++) + " | " + e);
element += e + "$";
}
}
// 规范化后的deviceIdCpuList
deviceIdCpuList.set(i, element);
}
// /////////////////////////
// for (int i = 0; i < deviceIdCpuList.size(); i++) {
// // System.out.println(deviceIdCpuList.get(i));
// }
Set<String> deviceSet = new HashSet<String>();
for (String e : deviceList) {
deviceSet.add(e);
}
for (String e : deviceSet) {
System.out.println(e);
}
List<String[]> dollorList = new ArrayList<String[]>();
for (String e : deviceIdCpuList) {
String[] ss = e.split("[$]");
// printStringArray(ss);
dollorList.add(ss);
}
// ////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////
for (String deviceId : deviceSet) {
ArrayList<String> cpu_perctgList = new ArrayList<String>();
ArrayList<String> cpu_vssList = new ArrayList<String>();
ArrayList<String> cpu_rssList = new ArrayList<String>();
ArrayList<String> cpu_thrList = new ArrayList<String>();
for (String[] sa : dollorList) {
// for (String e : sa)
// System.out.println(e);
for (int i = 0; i < sa.length; i++) {
System.out.print(sa[i] + " ");
if (deviceId.equals(sa[1])) {
String cpu_thr = sa[3];
cpu_thrList.add(cpu_thr);
String cpu_per = sa[4].replace("%", "");
cpu_perctgList.add(cpu_per);
String vss = sa[7].replace("K", "");
cpu_vssList.add(vss);
String rss = sa[8].replace("K", "");
cpu_rssList.add(rss);
}
}
System.out.println();
}
//
// for (String e : cpu_perctgList) {
// System.out.println(deviceId + " | " + e);
// }
ArrayList<String> d = new ArrayList<String>(1);
d.add(deviceId);
HashMap<String, ArrayList<String>> DCMap = new HashMap<String, ArrayList<String>>();
DCMap.put("device_id", d);
DCMap.put("cpu_perctg", cpu_perctgList);
DCMap.put("cpu_vss", cpu_vssList);
DCMap.put("cpu_rss", cpu_rssList);
DCMap.put("cpu_thr", cpu_thrList);
result.add(DCMap);
System.out.println(DCMap.get("device_id"));
System.out.println(DCMap.get("cpu_perctg"));
System.out.println(DCMap.get("cpu_vss"));
System.out.println(DCMap.get("cpu_rss"));
System.out.println(DCMap.get("cpu_thr"));
}
return result;
}
}
/**
* Report.java ct.report Report 下午7:38:18 2014年2月28日 2014
*/
package universsky.ct.report;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import universsky.ct.dao.ReportDao;
import com.google.gson.Gson;
/**
* @author 东海陈光剑 2014年2月28日 下午7:38:18
*/
public class CTPics extends HttpServlet {
/**
* serialVersionUID long
*/
private static final long serialVersionUID = -7282812094112943289L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
run_stamp = req.getParameter("run_stamp");
callback = req.getParameter("callback");
ReportDao dao = new ReportDao();
Gson gson = new Gson();
String json = gson.toJson(dao);
// 在console上打印记录
System.out.println(callback + "(" + json + ")");
PrintWriter out = resp.getWriter();
out.print(callback + "(" + json + ")");
out.flush();
}
public String getRun_stamp() {
return run_stamp;
}
public void setRun_stamp(String run_stamp) {
CTPics.run_stamp = run_stamp;
}
static String run_stamp;
static String callback;
}
/**
* Report.java ct.report Report 下午7:38:18 2014年2月28日 2014
*/
package universsky.ct.report;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import universsky.ct.dao.CpuUsageDao;
import universsky.ct.dao.ReportDao;
import com.google.gson.Gson;
/**
* @author 东海陈光剑 2014年2月28日 下午7:38:18
*/
public class CTCpuUsage extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -8142830838963500670L;
/**
* serialVersionUID long
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
run_stamp = req.getParameter("run_stamp");
callback = req.getParameter("callback");
CpuUsageDao dao = new CpuUsageDao();
Gson gson = new Gson();
String json = gson.toJson(dao);
// 在console上打印记录
System.out.println(callback + "(" + json + ")");
PrintWriter out = resp.getWriter();
out.print(callback + "(" + json + ")");
out.flush();
}
public String getRun_stamp() {
return run_stamp;
}
public void setRun_stamp(String run_stamp) {
CTCpuUsage.run_stamp = run_stamp;
}
static String run_stamp;
static String callback;
}
/**
* ReportDao.java ct.dao Report 下午9:32:16 2014年2月28日 2014
*/
package universsky.ct.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.google.gson.Gson;
import universsky.ct.report.CTPics;
import universsky.ct.report.CTCpuUsage;
import universsky.ct.result.QueryCpuUsage;
import universsky.ct.result.QueryPics;
/**
* @author 东海陈光剑 2014年2月28日 下午9:32:16
*/
public class CpuUsageDao {
private String run_stamp = (new CTCpuUsage()).getRun_stamp();
List<HashMap<String, ArrayList<String>>> result = (new QueryCpuUsage())
.query(run_stamp);
// public static void main(String[] args) {
// String run_stamp = "20140428052333";
// QueryCpuUsage qr = new QueryCpuUsage();
// List<HashMap<String, ArrayList<String>>> result = qr.query(run_stamp);
// Gson gson = new Gson();
// System.out.println(gson.toJson(result));// String json =
// // gson.toJson(obj)
// }
}
/**
* ReportDao.java ct.dao Report 下午9:32:16 2014年2月28日 2014
*/
package universsky.ct.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import universsky.ct.report.CTPics;
import universsky.ct.result.QueryPics;
/**
* @author 东海陈光剑 2014年2月28日 下午9:32:16
*/
public class ReportDao {
// Report report = new Report();
private String run_stamp = (new CTPics()).getRun_stamp();
// private ArrayList<String> deviceList = (new Report()).getDeviceList();
// private String device_id = (new Report()).getDevice_id();
// QueryResult qr = new QueryResult();
// Map<String, ArrayList<String>> result = (new QueryResult()).query(
// run_stamp, device_id);
List<HashMap<String, ArrayList<String>>> result = (new QueryPics())
.query(run_stamp);
}
log4j.rootLogger=DEBUG,console,FILE,database
#Config the full path of logger class Name: universsky.solo.util.Util
log4j.logger.universsky.solo.util.Util=DEBUG,XFILE,databaseRuntime
log4j.logger.universsky.solo.perf.PerfUtil=DEBUG,PERF,databasePerf
#log4j.logger.universsky.solo.util.LogcatUtil=DEBUG,LOGCAT,databaseLogcat
# Output to Console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.threshold=DEBUG
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyyMMddHHmmss} [%5p] - %c -%F(%L) -%m%n
# Output to FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.Append=true
log4j.appender.FILE.File=./logs/logs.log
log4j.appender.FILE.Threshold=DEBUG
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyyMMddHHmmss} [%5p] - %c -%F(%L) -%m%n
log4j.appender.FILE.MaxFileSize=10MB
# The self defined XFILE Appender
log4j.appender.XFILE=org.apache.log4j.RollingFileAppender
log4j.appender.XFILE.file=./runtime/runtime.log
log4j.appender.XFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.XFILE.layout.ConversionPattern= %d{yyyyMMddHHmmss} [%5p] - %c -%F(%L) -%m%n
# The self defined PERF Appender
log4j.appender.PERF=org.apache.log4j.RollingFileAppender
log4j.appender.PERF.file=./perfs/cpu_usage.log
log4j.appender.PERF.layout=org.apache.log4j.PatternLayout
log4j.appender.PERF.layout.ConversionPattern= %d{yyyyMMddHHmmss} [%5p] - %c -%F(%L) -%m%n
# The self defined LOGCAT Appender
#log4j.appender.LOGCAT=org.apache.log4j.RollingFileAppender
#log4j.appender.LOGCAT.file=./logcat/logcat.log
#log4j.appender.LOGCAT.layout=org.apache.log4j.PatternLayout
#log4j.appender.LOGCAT.layout.ConversionPattern= %d{yyyyMMddHHmmss} [%5p] - %c -%F(%L) -%m%n
########################
# SMTP Appender
#######################
#log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
#log4j.appender.MAIL.Threshold=DEBUG
#log4j.appender.MAIL.BufferSize=0
#log4j.appender.MAIL.SMTPHost=smtp.alibaba-inc.com
# username
#log4j.appender.MAIL.SMTPUsername=wb-[email protected]-inc.com
# password
#log4j.appender.MAIL.SMTPPassword=Ali123456789
#log4j.appender.MAIL.Subject=Log4J Message
#log4j.appender.MAIL.From=wb-[email protected]-inc.com
#log4j.appender.MAIL.To=wb-[email protected]-inc.com
#log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
#log4j.appender.MAIL.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
# database
#log4j.rootLogger=INFO,database
log4j.appender.database=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.database.URL=jdbc:mysql://10.125.1.58:3306/test
log4j.appender.database.driver=com.mysql.jdbc.Driver
log4j.appender.database.user=root
log4j.appender.database.password=isword
log4j.appender.database.sql=insert into ct_log4j(level,location,message,pro_time) values(‘%p‘,‘%c‘,‘%m‘,‘%d{yyyyMMddHHmmss}‘)
log4j.appender.database.layout=org.apache.log4j.PatternLayout
log4j.appender.databaseRuntime=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.databaseRuntime.URL=jdbc:mysql://10.125.1.58:3306/test
log4j.appender.databaseRuntime.driver=com.mysql.jdbc.Driver
log4j.appender.databaseRuntime.user=root
log4j.appender.databaseRuntime.password=isword
log4j.appender.databaseRuntime.sql=insert into ct_runtime(level,location,message,pro_time) values(‘%p‘,‘%c‘,‘%m‘,‘%d{yyyyMMddHHmmss}‘)
log4j.appender.databaseRuntime.layout=org.apache.log4j.PatternLayout
log4j.appender.databasePerf=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.databasePerf.URL=jdbc:mysql://10.125.1.58:3306/test
log4j.appender.databasePerf.driver=com.mysql.jdbc.Driver
log4j.appender.databasePerf.user=root
log4j.appender.databasePerf.password=isword
log4j.appender.databasePerf.sql=insert into ct_perf(level,location,message,pro_time) values(‘%p‘,‘%c‘,‘%m‘,‘%d{yyyyMMddHHmmss}‘)
log4j.appender.databasePerf.layout=org.apache.log4j.PatternLayout
#log4j.appender.databaseLogcat=org.apache.log4j.jdbc.JDBCAppender
#log4j.appender.databaseLogcat.URL=jdbc:mysql://10.125.1.58:3306/test
#log4j.appender.databaseLogcat.driver=com.mysql.jdbc.Driver
#log4j.appender.databaseLogcat.user=root
#log4j.appender.databaseLogcat.password=isword
#log4j.appender.databaseLogcat.sql=insert into ct_logcat(level,location,message,pro_time) values(‘%p‘,‘%c‘,‘%m‘,‘%d{yyyyMMddHHmmss}‘)
#log4j.appender.databaseLogcat.layout=org.apache.log4j.PatternLayout
/**
* universsky.solo MailSendSSL.java 2014年4月23日
*/
package universsky.solo.sendmail;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import universsky.solo.util.Const;
/**
* @author 东海陈光剑 2014年4月23日 下午4:18:39
*/
public class MailSendSSL {
private String userName = "[email protected]";
private String passWord = "Ali123456789";
private String smtp = "smtp.alibaba-inc.com";
private String sendEmail = "[email protected]";
private Message msg;
public static void main(String[] args) {
String run_stamp = "20140421122151";
String min = "1";
String sec = "70";
sendMailSSL(run_stamp, min, sec, Const.toNames);
}
public static void sendMailSSL(String run_stamp, String min, String sec,
String[] toNames) {
MailSendSSL m = new MailSendSSL();
String subject = "[一淘适配测试]报告";
String fromEmail = "[email protected]";
String emailBody = "[一淘适配测试]报告:"
+ "<a href= \"http://10.125.1.58:88/report.html?run_stamp="
+ run_stamp + "&min=" + min + "&sec=" + sec
+ "\">http://10.125.1.58:88/report.html?run_stamp= "
+ run_stamp + "&min=" + min + "&sec=" + sec + "</a>";
StringBuffer sb = new StringBuffer(emailBody);
for (String toName : toNames) {
m.sendHtmlEmail(subject, fromEmail, toName, toName, emailBody);
}
}
/**
*
* @param subject
* 邮件主题
* @param fromEmail
* 发件人姓名
* @param toEmail
* 收件人email
* @param toName
* 收件人姓名
* @param emailBody
* 邮件内容
* @return
*/
public String sendHtmlEmail(String subject, String fromEmail,
String toEmail, String toName, String emailBody) {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", smtp);
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
// MailSSLSocketFactory sf = new MailSSLSocketFactory();
// sf.setTrustAllHosts(true);
// // sf.setTrustedHosts(new String[] { "my-server" });
// props.put("mail.smtp.ssl.enable", "true");
// // also use following for additional safety
// //props.put("mail.smtp.ssl.checkserveridentity", "true");
// props.put("mail.smtp.ssl.socketFactory", sf);
//
// 设置用户名密码
Session session = Session.getDefaultInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, passWord);
}
});
// -- Create a new message --
msg = new MimeMessage(session);
try {
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(sendEmail, fromEmail));// 设置发件人
// 发件人姓名
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(toEmail, false));// 设置收件人
msg.setSubject(subject);// 设置主题
// 以普通方法发送
// 以HTML方式发送
msg.setContent(emailBody, "text/html;charset=utf-8");// 邮件主体
msg.setSentDate(new Date());
Transport.send(msg);// 发送邮件
System.out.println("Message sent: " + toEmail);
} catch (Exception e) {
e.printStackTrace();
}
return "Y";
}
}
android客户端应用(native app)适配测试自动化 东海陈光剑 2014年5月5日
0:39:04,布布扣,bubuko.com
android客户端应用(native app)适配测试自动化 东海陈光剑 2014年5月5日
0:39:04