Archive

Archive for the ‘base’ Category

一段btrace代码

February 21st, 2010 No comments

最近想要优化一下本地cache,不知道数据的使用情况,故写了一个btrace脚本来做分析,也可以顺便熟悉一下强大的btrace
btrace目前已经到了1.0,可以从下面的地址下载:
https://btrace.dev.java.net/files/documents/8510/135506/btrace-bin.tar.gz

以下是今天写的btrace脚本:

import java.util.Map;
 
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.OnEvent;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.OnTimer;
import com.sun.btrace.annotations.Property;
 
/**
 * @author chua 2010-2-20 16:36:44
 */
@BTrace
public class CacheProbe {
 
    @Property
    private static Map map = BTraceUtils.newHashMap();
 
    @OnMethod(
        clazz = "com.meichua.sample.model.Cache", 
        method = "/getAllAttributes|getAllLocators/"
    )
    public static void visitCategory() {
        if (!BTraceUtils.containsKey(map, "category")) {
            BTraceUtils.put(map, "category", "yes");
        }
    }
 
    @OnMethod(clazz = "com.meichua.sample.model.Cache", method = "/getAreaMap|getAreaTree/")
    public static void visitArea() {
        if (!BTraceUtils.containsKey(map, "area")) {
            BTraceUtils.put(map, "area", "yes");
        }
    }
 
    .
    .
    .
 
    @OnEvent
    public static void onEvent() {
        BTraceUtils.println("BTrace probe will print the used original data:");
        BTraceUtils.printMap(map);
        BTraceUtils.println("BTrace program exits!");
        BTraceUtils.exit();
    } 
 
    @OnTimer(1000*60*5)
    public static void ontimer() {
        BTraceUtils.println("--------------------------------------:");
        BTraceUtils.printMap(map);
    }
 
}

@BTrace 这个annotation表明这个类是个btrace的脚本
@Property 这个annotation标注的field是可以在JMX client中,如jconsole中可以看到
@OnMethod 这个annotation标注要监控的类中的方法,我的例子中,是一个正则表达式,当然还可以是更复杂的正则表达式
@OnEvent 这个annotation表明事件处理时,打印map中的内容,这个事件,可以在运行btrace脚本的控制台中用ctrl+c,再选择2触发
@OnTimer 这个annotation是一个定时器,有定义的时间触发一次执行,打印map内容,时间单位是毫秒

另外: map的创建,操作,打印必须有BTraceUtils的方法创建,在一个事件中,不能调用任何自己写的方法
运行: btrace <pid> CacheProbe.java

Categories: base Tags: , , , , ,

搬砖 砌墙 盖教堂

January 26th, 2010 No comments

有一个人经过一个工地,看到一群建筑工人正在忙碌地工作着。于是,他凑上前去,问一个工人:“你在干什么?

那人没好气地答道:“你没看见我正在搬砖头吗?”

[这是个悲观主义者,为了生活而生活着,是地地道道的生活苦役。他只知道周而复始地机械地劳作,觉得前途暗淡、渺茫,当下的辛苦让他看不到朗朗的天空;更看不到光明的未来。]

第二个人平和地说:“我在砌墙。”

[这是个职业主义者,他看到的是局部的成品,坚守职业的底线。他没有看到劳作的目标,也就是说他只是有着孔子所说的“君子不器”中“器”的境界。(其实,人应该博学而放眼,广泛地涉猎各种知识,培养各种才能,才不会像器物一样,只能作有限目的之使用;应有宽广的胸襟来看待万事万物,气度应似江海纳百川,才不会像器物一般有容量之限制;待人处事时,不应像器物一般定型而一成不变,而应适时适地适人适事地采取合宜之行动。)]

第三个人说:“我在盖教堂。”

[第三个人目光透露出祥和的光芒,是个理想主义者。他的每一块砖、每一滴汗都是为梦想而歌,是为了一个伟大的梦想,正走着从自我脚下到崇高理想的一个艰难历程。他目光深邃,高瞻远瞩,正在努力为远大的理想而付出,他的付出是为了最终成就最为崇高的理想。]

———————————————————————
其实工作很多年了,没多大成绩,或许是我们没有明确的目标所致.

Categories: base Tags: , ,

在ubuntu中安装dtrace

October 16th, 2009 No comments

准备:
下载最新的dtrace for linux的源包
到这个ftp下找一个最新版本,下载,解压
先看一下readme,有关于作者的信息,我贴一下相关信息,以表达对作者的尊敬

Linux port of DTrace
June 2009
Paul D. Fox
fox@crisp.demon.co.uk

http://www.twitter.com/crispeditor

http://www.crisp.demon.co.uk

Blog – latest news and stuff about the dtrace project:
http://www.crisp.demon.co.uk/blog/
Download dtrace tarballs for linux here:
ftp://crisp.dynalias.com/pub/release/website/dtrace

安装/install
1:make all
报错:

1
2
3
4
5
6
BUILD_DIR=build-2.6.28-11-generic tools/build.pl build-2.6.28-11-generic `uname -m`
Sorry - but I cannot find bison or yacc on your system.
You may need to install more packages. See utils/get-deps.pl
for a script to semi-automate this for you.
Continue ? [y/n] n
make: *** [all] 错误 1

事实上,utils/get-deps.pl并不存在,而tools目录下是有,而这个脚本就是用来在ubuntu下install dtrace的,于是
tools/get-deps.pl
你可以看一下这个脚本,其实就是一个安装脚本,他会下载dtrace的一个源包,然后在安装一些依赖的包

1
2
sudo apt-get install zlib1g-dev flex bison \
	elfutils libelf-dev libc6-dev linux-libc-dev

http://khushildep.blogspot.com这个blog上,也指出了ubuntu要安装的包,当然要看到这个blog得翻墙
sudo apt-get install zlib1g-dev bison flex libelf-dev
再次make all,ok了

2: sudo make install

3: sudo make load
安装完成!!!

4: 接下来验证一下dtrace是否可用
先启一个java程序
然后shell中执行:
dtrace -n ‘syscall::read:entry /execname == “java”/ { jstack(); }’

输出:

1
2
3
4
5
6
7
8
9
10
11
12
dtrace: description 'syscall::read:entry ' matched 1 probe
CPU     ID                    FUNCTION:NAME
  0 257149                       read:entry 
              aux[0]: type=32
aux[1]: type=33
aux[2]: type=16
aux[3]: type=6
aux[4]: type=17
aux[5]: type=3
.
.
.

5:下面的地址是dtrace和java的相关资料,可作为入门学习用
http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_Java

Categories: base Tags: , , , ,

在inove中添加visitor map

October 12th, 2009 No comments

1: 关于visitor map有很多网站都提供这个功能,我选用了clustrmaps.com的,速度满快的,你要在他的网站里用你的首页链接注册一个帐户,他会给你一段代码,如:

1
2
3
<a href="http://www3.clustrmaps.com/counter/maps.php?url=http://www.meichua.com" id="clustrMapsLink">
  <img src="http://www3.clustrmaps.com/counter/index2.php?url=http://www.meichua.com" style="border:0px;" alt="Locations of visitors to this page" title="Locations of visitors to this page" id="clustrMapsImg" onerror="this.onerror=null; this.src='http://www2.clustrmaps.com/images/clustrmaps-back-soon.jpg'; document.getElementById('clustrMapsLink').href='http://www2.clustrmaps.com';" />
</a>

2: 修改inove的style.css文件,在#southsidebar .widget的样式后面加入visitor,visitorimg两个样式,如:

575
576
577
578
579
580
581
582
583
584
585
586
587
588
#southsidebar .widget {
	background:url(img/widgetsep.png) bottom no-repeat;
	padding:10px 15px 16px;
}
 
#southsidebar .visitor {
	padding:20px 30px 16px;
}
 
#southsidebar .visitorimg {
    border:0px;
    width:240px;
    height:160px;
}

这里我的sidebar的宽度是默认的300px,图片的大小设定为240px*160px,稍微有点模糊,clustrmap提供的原始图片是160*106的,我觉得略小,所以放大了一些. 图片显示在sidebar的中间,故两边刚好都留下30px的空隙.

3:在sidebar.php里south End结束的div标签前插入clustrmap给的代码,修改后如下:

175
176
177
178
179
    <div class="visitor">
        <a href="http://www3.clustrmaps.com/counter/maps.php?url=http://www.meichua.com" id="clustrMapsLink" target="_blank"><img src="http://www3.clustrmaps.com/counter/index2.php?url=http://www.meichua.com" class="visitorimg" alt="Locations of visitors to this page" title="Locations of visitors to this page" id="clustrMapsImg" onerror="this.onerror=null; this.src='http://www2.clustrmaps.com/images/clustrmaps-back-soon.jpg'; document.getElementById('clustrMapsLink').href='http://www2.clustrmaps.com';" /></a>
    </div>
</div>
<!-- sidebar south END -->

这里定义了一个div,class用的是刚定义的visitor,同时修改了clustrmap给的代码,把img的style修改了一下,使用之前定义的vistorimg样式.

4:发布,上传,ok

Categories: base Tags: , ,

为blog制作了一个favicon.ico

October 11th, 2009 No comments

blog迁移后,在本地打开主页显示的还是原来dlog.cn的ico图片,觉得怪怪的. 于是自己动手做了这么一个图片.

灵感来源于电影<骇客帝国>,以前看那部片子的时候,觉得那一串串往下流的字节码很cool,于是网上找来了那图片的样式,黑底,黄绿的字. 本来就是娱乐一下,自己觉得cool就行了,哈哈. 再说呢,这个favicon.ico也符合我的工作内容.

但是画图不是一件很简单的事,我那盗版的photoshop用的实在不熟,搞了很久也没法弄出来,可能制作16*16像素的小图不需要photeshop这样的大工具. 于是想起很刚工作时,我在那个游戏公司写手机游戏时用到的一个小工具,一个一个像素点一点,就能出来像样的图. 怪我离开那家公司时,没有记得那工具的名字,或许那工具也没有盗版的吧! 网上找了好久,那种可以像素画图的工具,后来找到了Pro Motion这个工具,有免费版本可以用,接着一切就简单了. 很快就做好了,上传,测试,ok,搞定!

在找软件的时候还发生了一个小插曲,下载的其他软件安装时,把我的ie默认首页修改了,nnd,又费劲的下了360来搞,幽默的是,那恶意修改只是在浏览器的快捷方式的目标里加了一个url启动参数. 360也搞不来. 最后是一个个修改浏览器的快捷方式.

Categories: base Tags: ,