JMeter二次封装之源码解析初步

       近日,正在做一个压测平台,主要功能是想整合压力机资源,通过一个统一的web平台,创建和管理压测任务,并展示包括实时压测结果、压力机性能数据、应用服务器性能数据等数据的性能测试报告。

  本系统的核心是对JMeter进行二次封装,从而实现web版的JMeter平台。针对其中的实现原理,会逐一通过文章记录。本文主要是对JMeter的源码进行初步解析。

  我们以非GUI模式运行JMeter为例,了解下JMeter的运行机制。首先我们找到入口类NewDriver,代码如下。

public static void main(String[] args) {
        if(!EXCEPTIONS_IN_INIT.isEmpty()) {
            System.err.println("Configuration error during init, see exceptions:"+exceptionsToString(EXCEPTIONS_IN_INIT));
        } else {
            Thread.currentThread().setContextClassLoader(loader);

            setLoggingProperties(args);

            try {
                Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$
                Object instance = initialClass.newInstance();
                Method startup = initialClass.getMethod("start", new Class[] { new String[0].getClass() });// $NON-NLS-1$
                startup.invoke(instance, new Object[] { args });
            } catch(Throwable e){ // NOSONAR We want to log home directory in case of exception
                e.printStackTrace(); // NOSONAR No logger at this step
                System.err.println("JMeter home directory was detected as: "+JMETER_INSTALLATION_DIRECTORY);
            }
        }
    }

  很明显,这里是通过反射调用JMeter类的start方法。接下来我们看下start方法,如下。

    public 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值