Package org.jboss.profiler

Source Code of org.jboss.profiler.AOPMonitoringService

/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.profiler;

import java.util.Iterator;

import org.jboss.aop.AspectManager;
import org.jboss.aop.advice.AdviceBinding;
import org.jboss.aop.pointcut.ast.ParseException;
import org.jboss.profiler.aop.monitoring.MonitoringInterceptor;
import org.jboss.profiler.aop.monitoring.control.MonitoringController;
import org.jboss.profiler.aop.monitoring.model.MeasureAggregation;
import org.jboss.profiler.aop.monitoring.model.MonitoringMeasure;

/**
* @author Clebert Suconic
*/
public class AOPMonitoringService implements AOPMonitoringServiceMBean{

    /* (non-Javadoc)
     * @see org.jboss.profiler.AOPMonitoringServiceMBean#addPointcuts(java.lang.String)
     */
    private static final int ONE_MINUTE = 60000;

    public void addPointcut(String pointcutExpression) throws ParseException {
        AdviceBinding binding = new AdviceBinding("all("+pointcutExpression+")", null);
        binding.addInterceptor(MonitoringInterceptor.class);
        AspectManager.instance().addBinding(binding);
    }


    public void printMeasures() {
        Iterator aggregations = MonitoringController.getAggregationsSet().iterator();
        while (aggregations.hasNext()) {
            MeasureAggregation aggregation = (MeasureAggregation) aggregations.next();
            System.out.println("_____________________________________________________");
            System.out.println("Aggregation=" + aggregation.getName());
            Iterator measures = aggregation.getMeasureSet().iterator();
            while (measures.hasNext()) {
                MonitoringMeasure measure = (MonitoringMeasure)measures.next();
                System.out.print("Measure=" + measure.getName() + " callings="+ measure.getRootValue().getCallings() + " Time elements=" + measure.getValues().size());
                if (measure.getRootValue().getCallings()!=0) {
                    System.out.println(" avg time=" + (measure.getRootValue().getTotalTime()/measure.getRootValue().getCallings()));
                } else {
                    System.out.println();
                }
            }
        }
    }

    public void setGradeInMinutes(int grade) {
        MonitoringController.setGrade(grade * ONE_MINUTE);
    }



    /* (non-Javadoc)
     * @see org.jboss.profiler.AOPMonitoringServiceMBean#getGradeInMinutes()
     */
    public int getGradeInMinutes() {
        return MonitoringController.getGrade()/ONE_MINUTE;
    }
}
TOP

Related Classes of org.jboss.profiler.AOPMonitoringService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.