4月 10

java 内存泄露问题查找

  之前已经查找过java运行越来越慢的问题,用了visualvm工具,文档详见:http://www.simonzhang.net/?p=950。只是查到了内存泄露,知道由某类问题导致,但是不能具体到类上,不能定位到是什么资源导致内存泄露,所以需要进一步查看。
  通过google学习,找到了JRockit Mission Control 4.1。此工具已经免费,直接到oracle下载相关包。下载位置:
http://www.oracle.com/technetwork/middleware/jrockit/downloads/index.html
  下载Oracle JRockit 6 – R28.2.2其中包含JRockit Mission Control 4.1和JRockit Real Time 4.1。直接下载了linux的64位的bin文件,上传到服务器上安装并替换当前的jdk。命令记录:
# chmod 755 jrockit-jdk1.6.0_29-R28.2.2-4.1.0-linux-x64.bin
# ./jrockit-jdk1.6.0_29-R28.2.2-4.1.0-linux-x64.bin
系统会弹出安装界面,我开启了X11可以远程使用图形化界面。真是有oracle的风格呀。

# mv jrockit-jdk1.6.0_29-R28.2.2 /usr/local/jrockit-jdk1.6.0_29-R28.2.2
  编辑/etc/profile添加
JAVA_HOME=/usr/local/jrockit-jdk1.6.0_29-R28.2.2
CLASSPATH=$JAVA_HOME/jre/lib/ext/jcert.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/jpda.jar:$JAVA_HOME/lib/tools.jar
PATH=.:$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export JAVA_HOME PATH CLASSPATH
  保存过后加载资源,然后启动JRockit Mission Control
# source /etc/profile
# cd /usr/local/jrockit-jdk1.6.0_29-R28.2.2/bin/
# jrmc
  启动后可以看到图形化界面,“启动Memleak”

  找到消耗内存大的部分,列出所有实例看看什么数据占用过多,然后在处理。如果下图

4月 09

开启wp7 热点

  买了部samsung omnia 7 使用联通3G卡。但是机器本身没有开热点功能,非常不方便外出救急。通过网上学习进行了强行开启。
步骤如下:
a)下载 DiagProvXML 和 Samsung Tools安装到手机中,我使用的新峰应用汇。

b)运行 DiagProvXML,切换到 iso store,长按 Internet Sharing,点击execute。提示处理成功。
c)退出 DiagProvXML ,运行 Samsung Tools,点击“启动3G切换”和“运行ADC标志”。保存后手机会重启。

d)手机重启后,进入系统,“设置”会看到“网络共享”,进行开启并设置。

e) 用电脑进行连接。

手机显示已有一个客户端。

网上介绍此方法对 Samsung Focus (US) 和 Samsung Omnia 7 可行。但是是耗电大、发热高,基本上就是救急使用了。

4月 08

python的聪明组合

  一直在买双色就是没有中过,看过高人指点,根据“聪明组合”写了这个脚本。在技术上没有任何难度,都是体力活。为了大家方便。
  运行脚本输入12个红球数,组合成10组。然后在自己加上篮球即可。

#!/bin/env python
# -*- coding:utf-8 -*-
# -------------------------------------------
# Filename:    clever12.py
# Revision:    1.0
# Date:        2012-3-13
# Author:      simonzhang
# WEB:         www.simonzhang.net
# Email:       simon-zzm@163.com
# -------------------------------------------

def run_group(di):
    fen = di.split(' ')
    A = fen[0]
    B = fen[1]
    C = fen[2]
    D = fen[3]
    E = fen[4]
    F = fen[5]
    G = fen[6]
    H = fen[7]
    I = fen[8]
    J = fen[9]
    K = fen[10]
    L = fen[11]
    print("%s %s %s %s %s %s"%(A,B,D,E,K,L))
    print("%s %s %s %s %s %s"%(A,B,E,F,H,I))
    print("%s %s %s %s %s %s"%(A,B,E,G,I,K))
    print("%s %s %s %s %s %s"%(A,B,E,I,J,L))
    print("%s %s %s %s %s %s"%(A,C,D,E,F,L))
    print("%s %s %s %s %s %s"%(A,C,D,G,H,J))
    print("%s %s %s %s %s %s"%(A,C,D,I,K,L))
    print("%s %s %s %s %s %s"%(A,C,F,G,H,L))
    print("%s %s %s %s %s %s"%(A,C,F,H,J,K))
    print("%s %s %s %s %s %s"%(A,D,F,G,J,L))

def main():
    get_list = raw_input("12 number :")
    if len(get_list) == 35:
        run_group(get_list)
    else:
        print "input error"

if __name__ == "__main__":
    main()
4月 07

android的monkey测试简单记录

  需要对android的一个软软件做个疲劳测试,使用android SDK自带的工具最为方便。所就开始做monkey测试,调用和回播的脚本是从网上搜集而来,自己做了小修改。原始脚本的网页url忘记记录,所以不能提供参考网连接。下面开始对我所做的简单测试做个记录。
  首先是在系统上安装java运行环境,这个比较简单。下载android SDK包,直接解压后就可以使用非常方便。
  进入android-sdk-windows/tools目录,在其下面写两个脚本。
录脚本的启动脚本名monkey_recorder.py脚本内容如下:

#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder

device = mr.waitForConnection()
recorder.start(device)

回放脚本名为monkey_playback.py脚本内容如下:

#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from com.android.monkeyrunner import MonkeyRunner

# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command.  The line is split into 2
# parts with a | character.  Text to the left of the pipe denotes
# which command to run.  The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command.  In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command. 

# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
    'TOUCH': lambda dev, arg: dev.touch(**arg),
    'DRAG': lambda dev, arg: dev.drag(**arg),
    'PRESS': lambda dev, arg: dev.press(**arg),
    'TYPE': lambda dev, arg: dev.type(**arg),
    'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
    }

# Process a single file for the specified device.
def process_file(fp, device):
    for line in fp:
        (cmd, rest) = line.split('|')
        try:
            # Parse the pydict
            rest = eval(rest)
        except:
            print 'unable to parse options'
            continue

        if cmd not in CMD_MAP:
            print 'unknown command: ' + cmd
            continue
        CMD_MAP[cmd](device, rest)
        
def go(file,num):
    n = num
    device = MonkeyRunner.waitForConnection()
    for i in range(int(n)):
        print 'now %s'%i
        fp = open(file, 'r')
        process_file(fp, device)
        fp.close();

def main():
    file = sys.argv[1]
    try :
        number = sys.argv[2]
    except :
        number = 1
    go(file,number)
 
if __name__ == '__main__':
    main()

  到此环境和脚本就算部署完了。下面开始记录脚本使用。
  首先将手机和电脑用usb线连好,使用“cmd”调出命令行,然后进入“android-sdk-windows/tools”目录。输入命令:
monkeyrunner.bat monkey_recorder.py
如果没有报错,并且出现以下界面,就可以开始录制脚本了。

  “wait”为每步操作间的等待时间。“Press a Button“发送,MENU,HOME,or SEARCH 按钮。“Type Something”为输入文字。“Fling”为模拟滑动操作。“Export Actions”为保存刚才录制的脚本。最后一个为刷新。   
  保存的脚本可以直接用文本编辑器手动编辑。假如我们录制的脚本为text.txt。下一步就是回放脚本,使用命令为:
monkeyrunner.bat monkey_playback.py test.txt 100
  最后的数字是将这个脚本循环100次。
  我只需要到此即可了。如果需要抓图片\照相\判断等高级功能,将来需要时再学习。

4月 06

读《稻盛和夫》

  稻盛和夫的经营哲学被众人推崇,中国的国学大师季羡林对其也有高度评价。此书是曹岫云著,记录了稻盛和夫生平的经典事迹,和稻盛和夫经营哲学的实践。
  书中的“恩师”一节讲述了稻盛和夫起初在一家经营管理都不好的工厂工作。后来遇到国到日本外寻找技术的人,此人很赏识稻盛和夫的技术,开出了丰厚的待遇,稻盛和夫非常高兴,感觉这是一个极好的机会。但是在高兴之余盗圣有找到老师,告知当前的事情,并希望得到指点。老师讲,到国外去就是卖技术,时间久了国内技术发展迅速,就失去了学习新知识的机会,几年后再回来就会落后。稻盛和夫经过思考,最终留在了日本。多年后回忆起这件事,非常感谢老师的指导。
  现在很多人为了增加几百或一两千就要跳槽,工作不了一年就觉得能力受到了限制就要另谋高就。放映出来的就是浮躁,既然不能踏踏实实的工作\学习,即使换了“更好”的地方也是一时之幸。如果需要换工作我想应该有两中情况:一\公司转换经营方向,与自己的职业规划不符。二\公司经营不善,已经不能满足自己的最低生活开支。有许多人认为自己就是因为这两点才离职,这时需要思考,这个是不是自己的底线。公司是不是跨行业转变了,是不是连住地下室一天吃三顿饼的工资都开不出来了。如果不是这两点,如果公司经营不善是无能所致,那自己也应该承担一部分责任,并且知道自己也是无能的。  
image