Java Code Examples for org.perf4j.StopWatch#stop()

The following examples show how to use org.perf4j.StopWatch#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractViewRepository.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void init() {
    StopWatch initTiming = new Slf4JStopWatch("ViewRepository.init." + getClass().getSimpleName());

    storage.clear();
    readFileNames.clear();

    String configName = AppContext.getProperty("cuba.viewsConfig");
    if (!StringUtils.isBlank(configName)) {
        Element rootElem = DocumentHelper.createDocument().addElement("views");

        StringTokenizer tokenizer = new StringTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            addFile(rootElem, fileName);
        }

        viewLoader.checkDuplicates(rootElem);

        for (Element viewElem : Dom4j.elements(rootElem, "view")) {
            deployView(rootElem, viewElem, new HashSet<>());
        }
    }

    initTiming.stop();
}
 
Example 2
Source File: AbstractTreeDatasource.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadData(Map<String, Object> params) {
    String tag = getLoggingTag("TDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));

    clear();

    this.tree = loadTree(params);

    Map<K, Node<T>> targetNodes = new HashMap<>();
    if (tree != null) {
        for (Node<T> node : tree.toList()) {
            final T entity = node.getData();
            final K id = entity.getId();

            data.put(id, entity);
            attachListener(entity);

            targetNodes.put(id, node);
        }
    }

    this.nodes = targetNodes;

    sw.stop();
}
 
Example 3
Source File: WebJarResourceResolver.java    From cuba with Apache License 2.0 6 votes vote down vote up
@EventListener
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 200)
protected void init(AppContextInitializedEvent event) {
    StopWatch stopWatch = new Slf4JStopWatch("WebJARs");
    try {
        ApplicationContext applicationContext = event.getApplicationContext();

        ClassLoader classLoader = applicationContext.getClassLoader();

        log.debug("Scanning WebJAR resources in {}", classLoader);

        scanResources(applicationContext);

        log.debug("Loaded {} WebJAR paths", mapping.size());
    } catch (IOException e) {
        throw new RuntimeException("Unable to load WebJAR resources", e);
    } finally {
        stopWatch.stop();
    }
}
 
Example 4
Source File: ValueGroupDatasourceImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadData(Map<String, Object> params) {
    String tag = getLoggingTag("VGDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));

    delegate.loadData(params);

    sw.stop();
}
 
Example 5
Source File: ValueCollectionDatasourceImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadData(Map<String, Object> params) {
    String tag = getLoggingTag("VDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));

    delegate.loadData(params);

    sw.stop();
}
 
Example 6
Source File: ValueHierarchicalDatasourceImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadData(Map<String, Object> params) {
    String tag = getLoggingTag("VHDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));

    delegate.loadData(params);

    sw.stop();
}
 
Example 7
Source File: FragmentHelper.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ComponentLoader.ComponentContext windowContext, Frame window) {
    String loggingId = getFullFrameId(this.fragment);

    StopWatch injectStopWatch = createStopWatch(ScreenLifeCycle.INJECTION, loggingId);

    FrameOwner controller = fragment.getFrameOwner();
    beanLocator.getAll(ControllerDependencyInjector.class).values()
            .forEach(uiControllerDependencyInjector ->
                    uiControllerDependencyInjector.inject(new ControllerDependencyInjector.InjectionContext(controller, options))
            );
    injectStopWatch.stop();
}
 
Example 8
Source File: DesktopTableCellEditor.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Component getCellComponent(int row) {
    Entity item = desktopAbstractTable.getTableModel().getItem(row);

    StopWatch sw = new Slf4JStopWatch("TableColumnGenerator." + desktopAbstractTable.getId());
    @SuppressWarnings("unchecked")
    com.haulmont.cuba.gui.components.Component component = columnGenerator.generateCell(item);
    sw.stop();

    Component comp;
    if (component == null) {
        comp = new JLabel("");
    } else if (component instanceof Table.PlainTextCell) {
        comp = new JLabel(((Table.PlainTextCell) component).getText());
    } else {
        if (component instanceof BelongToFrame) {
            BelongToFrame belongToFrame = (BelongToFrame) component;
            if (belongToFrame.getFrame() == null) {
                belongToFrame.setFrame(desktopAbstractTable.getFrame());
            }
        }
        component.setParent(desktopAbstractTable);

        JComponent jComposition = DesktopComponentsHelper.getComposition(component);
        jComposition.putClientProperty(CELL_EDITOR_TABLE, desktopAbstractTable.getComponent());
        jComposition.putClientProperty(CELL_COMPONENT, component);

        comp = jComposition;
    }

    cache.put(row, comp);
    return comp;
}
 
Example 9
Source File: EmailSender.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void sendEmail(SendingMessage sendingMessage) throws MessagingException {
    MimeMessage msg = createMimeMessage(sendingMessage);

    StopWatch sw = new Slf4JStopWatch("EmailSender.send");
    mailSender.send(msg);
    sw.stop();

    log.info("Email '{}' to '{}' has been sent successfully", msg.getSubject(), sendingMessage.getAddress());
}
 
Example 10
Source File: ClusterManager.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void receive(Message msg) {
    byte[] bytes = msg.getBuffer();
    if (bytes == null) {
        log.debug("Null buffer received");
        return;
    }
    StopWatch sw = new Slf4JStopWatch();
    String simpleClassName = null;
    try {
        Serializable data;
        try {
            data = (Serializable) SerializationSupport.deserialize(bytes);
        } catch (Exception e) {
            log.error("Cluster message deserialization error", e);
            throw new RuntimeException("Cluster message deserialization error", e);
        }
        String className = data.getClass().getName();
        simpleClassName = data.getClass().getSimpleName();
        log.debug("Received message: {}: {} ({} bytes)", data.getClass(), data, bytes.length);
        MessageStat stat = messagesStat.get(className);
        if (stat != null) {
            stat.updateReceived(bytes.length);
        }
        @SuppressWarnings("unchecked")
        ClusterListener<Serializable> listener = listeners.get(className);
        if (listener != null) {
            listener.receive(data);
        }
    } finally {
        sw.stop(String.format("receiveClusterMessage(%s)", simpleClassName));
    }
}
 
Example 11
Source File: AbstractMessages.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected String searchClasspath(String pack, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
    StopWatch stopWatch = new Slf4JStopWatch("Messages.searchClasspath");
    try {
        String cacheKey = makeCacheKey(pack, key, locale, truncatedLocale);

        String msg = strCache.get(cacheKey);
        if (msg != null)
            return msg;

        log.trace("searchClasspath: {}", cacheKey);

        String packPath = "/" + pack.replaceAll("\\.", "/");
        while (packPath != null) {
            Properties properties = loadPropertiesFromResource(packPath, locale, truncatedLocale);
            if (properties != PROPERTIES_NOT_FOUND) {
                msg = getMessageFromProperties(pack, key, locale, truncatedLocale, properties, passedPacks);
                if (msg != null)
                    return msg;
            }
            // not found, keep searching
            int pos = packPath.lastIndexOf("/");
            if (pos < 0)
                packPath = null;
            else
                packPath = packPath.substring(0, pos);
        }
        return null;
    } finally {
        stopWatch.stop();
    }
}
 
Example 12
Source File: JavaClassLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Class loadClass(final String fullClassName, boolean resolve) throws ClassNotFoundException {
    String containerClassName = StringUtils.substringBefore(fullClassName, "$");

    StopWatch loadingWatch = new Slf4JStopWatch("LoadClass");
    try {
        lock(containerClassName);
        Class clazz;

        //first check if there is a ".class" file in the "conf" directory
        File classFile = classFilesProvider.getClassFile(containerClassName);
        if (classFile.exists()) {
            return loadClassFromClassFile(fullClassName, containerClassName, classFile);
        }

        //then check if a ".java" source file is deployed to the "conf" directory
        if (sourceProvider.getSourceFile(containerClassName).exists()) {
            return loadClassFromJavaSources(fullClassName, containerClassName);
        }

        //default class loading
        clazz = super.loadClass(fullClassName, resolve);
        return clazz;
    } finally {
        unlock(containerClassName);
        loadingWatch.stop();
    }
}
 
Example 13
Source File: Perform.java    From ns4_frame with Apache License 2.0 4 votes vote down vote up
public void performMethodOnce() throws Exception{
    StopWatch stopWatch = new Slf4JStopWatch(LogUtils.getFullyMethodName());
    TimeUnit.MILLISECONDS.sleep(200);
    stopWatch.stop();
}
 
Example 14
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the height of each row into the preferred height of the tallest cell in that row.
 */
public void packRows() {
    if (!contentRepaintEnabled) {
        return;
    }

    impl.setRowHeight(defaultRowHeight);

    for (Column column : columnsOrder) {
        if (column.isEditable()) {
            impl.setRowHeight(defaultEditableRowHeight);
            break;
        }
    }

    if (allColumnsAreInline()) {
        return;
    }

    int preferredRowHeight = -1;
    boolean equalsRowHeight = true;

    StopWatch sw = new Slf4JStopWatch("DAT packRows " + id);
    for (int r = 0; r < impl.getRowCount(); r++) {
        int h = getPreferredRowHeight(r);

        if (preferredRowHeight == -1) {
            preferredRowHeight = h;
        } else if (preferredRowHeight != h) {
            equalsRowHeight = false;
        }

        if (impl.getRowHeight(r) != h) {
            impl.setRowHeight(r, h);
        }
    }

    if (equalsRowHeight && preferredRowHeight > 0) {
        impl.setRowHeight(preferredRowHeight);
    }

    sw.stop();
}
 
Example 15
Source File: FragmentComponentLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void createComponent() {
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("screen");
    if (src == null
            && screenId == null) {
        throw new GuiDevelopmentException("Either 'src' or 'screen' must be specified for 'frame'",
                context, "fragment", element.attributeValue("id"));
    }

    String fragmentId;
    if (element.attributeValue("id") != null) {
        fragmentId = element.attributeValue("id");
    } else if (screenId != null){
        fragmentId = screenId;
    } else {
        fragmentId = src;
    }

    FragmentHelper fragmentHelper = getFragmentHelper();

    WindowInfo windowInfo;
    if (src == null) {
        // load screen class only once
        windowInfo = getWindowConfig().getWindowInfo(screenId).resolve();
    } else {
        windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
    }

    StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());

    Fragment fragment = factory.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);

    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();

    FrameOwner hostController = parentContext.getFrame().getFrameOwner();

    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller,
            new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController))
    );
    setScreenData(controller, new ScreenDataImpl());

    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);

    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);

    // load from XML if needed

    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }

        innerContext = new ComponentLoaderContext(getComponentContext().getOptions());
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        innerContext.setProperties(loadProperties(element));

        LayoutLoader layoutLoader = getLayoutLoader(innerContext);

        ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);

        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(),
                getComponentContext().getParams());

        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }

        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }

    createStopWatch.stop();

    this.resultComponent = fragment;
}
 
Example 16
Source File: Perform.java    From ns4_frame with Apache License 2.0 4 votes vote down vote up
public void performMethod() throws Exception{
    StopWatch stopWatch = new Slf4JStopWatch(LogUtils.getFullyMethodName());
    TimeUnit.MILLISECONDS.sleep(100);
    stopWatch.stop();
}
 
Example 17
Source File: WebScreens.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected <T extends Screen> T createScreen(WindowInfo windowInfo, LaunchMode launchMode, ScreenOptions options) {
    if (windowInfo.getType() != WindowInfo.Type.SCREEN) {
        throw new IllegalArgumentException(
                String.format("Unable to create screen %s with type %s", windowInfo.getId(), windowInfo.getType())
        );
    }

    @SuppressWarnings("unchecked")
    Class<T> resolvedScreenClass = (Class<T>) windowInfo.getControllerClass();

    // load XML document here in order to get metadata before Window creation, e.g. forceDialog from <dialogMode>
    Element element = loadScreenXml(windowInfo, options);

    ScreenOpenDetails openDetails = prepareScreenOpenDetails(resolvedScreenClass, element, launchMode);

    checkPermissions(openDetails.getOpenMode(), windowInfo);

    StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());

    Window window = createWindow(windowInfo, resolvedScreenClass, openDetails);

    T controller = createController(windowInfo, window, resolvedScreenClass);

    // setup screen and controller

    setWindowId(controller, windowInfo.getId());
    setFrame(controller, window);
    setScreenContext(controller,
            new ScreenContextImpl(windowInfo, options,
                    this,
                    ui.getDialogs(),
                    ui.getNotifications(),
                    ui.getFragments(),
                    ui.getUrlRouting(),
                    ui.getWebBrowserTools())
    );
    setScreenData(controller, new ScreenDataImpl());

    WindowImplementation windowImpl = (WindowImplementation) window;
    windowImpl.setFrameOwner(controller);
    windowImpl.setId(controller.getId());

    createStopWatch.stop();

    // load UI from XML

    StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId());

    ComponentLoaderContext componentLoaderContext = new ComponentLoaderContext(options);
    componentLoaderContext.setFullFrameId(windowInfo.getId());
    componentLoaderContext.setCurrentFrameId(windowInfo.getId());
    componentLoaderContext.setMessagesPack(getPackage(resolvedScreenClass));
    componentLoaderContext.setFrame(window);

    if (element != null) {
        loadWindowFromXml(element, windowInfo, window, controller, componentLoaderContext);
    }

    loadStopWatch.stop();

    // inject top level screen dependencies
    StopWatch injectStopWatch = createStopWatch(ScreenLifeCycle.INJECTION, windowInfo.getId());

    for (ControllerDependencyInjector dependencyInjector : dependencyInjectors) {
        dependencyInjector.inject(new ControllerDependencyInjector.InjectionContext(controller, options));
    }

    injectStopWatch.stop();

    // perform injection in nested fragments
    componentLoaderContext.executeInjectTasks();

    // run init

    StopWatch initStopWatch = createStopWatch(ScreenLifeCycle.INIT, windowInfo.getId());

    fireEvent(controller, InitEvent.class, new InitEvent(controller, options));

    initStopWatch.stop();

    componentLoaderContext.executeInitTasks();
    componentLoaderContext.executePostInitTasks();

    fireEvent(controller, AfterInitEvent.class, new AfterInitEvent(controller, options));

    return controller;
}
 
Example 18
Source File: FragmentComponentLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void loadComponent() {
    loadAliases();

    if (getComponentContext().getFrame() != null) {
        resultComponent.setFrame(getComponentContext().getFrame());
    }

    String src = element.attributeValue("src");
    String screenId = element.attributeValue("screen");
    String screenPath = StringUtils.isEmpty(screenId) ? src : screenId;
    if (element.attributeValue("id") != null) {
        screenPath = element.attributeValue("id");
    }
    if (getComponentContext().getFrame() != null) {
        String parentId = getComponentContext().getFullFrameId();
        if (StringUtils.isNotEmpty(parentId)) {
            screenPath = parentId + "." + screenPath;
        }
    }

    StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, screenPath);

    // if fragment has XML descriptor

    if (fragmentLoader != null) {
        fragmentLoader.loadComponent();
    }

    // load properties after inner context, they must override values defined inside of fragment

    assignXmlDescriptor(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEnable(resultComponent, element);

    loadStyleName(resultComponent, element);
    loadResponsive(resultComponent, element);
    loadCss(resultComponent, element);

    loadAlign(resultComponent, element);

    loadHeight(resultComponent, element);
    loadWidth(resultComponent, element);

    loadIcon(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);

    loadStopWatch.stop();

    // propagate init phases

    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();

    if (innerContext != null) {
        parentContext.getInjectTasks().addAll(innerContext.getInjectTasks());
        parentContext.getInitTasks().addAll(innerContext.getInitTasks());
        parentContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
    }

    ScreenOptions options = parentContext.getOptions();
    parentContext.addInjectTask(new FragmentLoaderInjectTask(resultComponent, options, beanLocator));
    parentContext.addInitTask(new FragmentLoaderInitTask(resultComponent, options, innerContext, beanLocator));
}
 
Example 19
Source File: ManagedBeanInfoDatasource.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected Tree<ManagedBeanInfo> loadTree(Map<String, Object> params) {
    String tag = getLoggingTag("TDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));
    List<Node<ManagedBeanInfo>> nodes = new ArrayList<>();

    if (jmxInstance != null) {
        List<ManagedBeanDomain> domains = jmxControlAPI.getDomains(jmxInstance);

        Map<String, Node<ManagedBeanInfo>> domainMap = new HashMap<>();

        for (ManagedBeanDomain mbd : domains) {
            ManagedBeanInfo dummy = metadata.create(ManagedBeanInfo.class);
            dummy.setDomain(mbd.getName());

            Node<ManagedBeanInfo> node = new Node<>(dummy);
            domainMap.put(mbd.getName(), node);
            nodes.add(node);
        }

        List<ManagedBeanInfo> list = loadManagedBeans(params);
        for (ManagedBeanInfo mbi : list) {
            if (mbi != null) {
                if (domainMap.containsKey(mbi.getDomain())) {
                    domainMap.get(mbi.getDomain()).addChild(new Node<>(mbi));
                }
            }
        }

        // remove root nodes that might have left without children after filtering
        for (Node<ManagedBeanInfo> rootNode : new ArrayList<>(nodes)) {
            if (rootNode.getChildren().isEmpty()) {
                nodes.remove(rootNode);
            }
        }
    }

    sw.stop();

    return new Tree<>(nodes);
}
 
Example 20
Source File: WebScreens.java    From cuba with Apache License 2.0 2 votes vote down vote up
@Override
public void show(Screen screen) {
    checkNotNullArgument(screen);
    checkNotYetOpened(screen);

    StopWatch uiPermissionsWatch = createStopWatch(ScreenLifeCycle.UI_PERMISSIONS, screen.getId());

    windowCreationHelper.applyUiPermissions(screen.getWindow());

    uiPermissionsWatch.stop();

    StopWatch beforeShowWatch = createStopWatch(ScreenLifeCycle.BEFORE_SHOW, screen.getId());

    applyDataLoadingSettings(screen);

    fireEvent(screen, BeforeShowEvent.class, new BeforeShowEvent(screen));

    loadDataBeforeShow(screen);

    beforeShowWatch.stop();

    LaunchMode launchMode = screen.getWindow().getContext().getLaunchMode();

    if (launchMode instanceof OpenMode) {
        OpenMode openMode = (OpenMode) launchMode;

        switch (openMode) {
            case ROOT:
                showRootWindow(screen);
                break;

            case THIS_TAB:
                showThisTabWindow(screen);
                break;

            case NEW_WINDOW:
            case NEW_TAB:
                showNewTabWindow(screen);
                break;

            case DIALOG:
                showDialogWindow(screen);
                break;

            default:
                throw new UnsupportedOperationException("Unsupported OpenMode " + openMode);
        }
    }

    userActionsLog.trace("Screen {} {} opened", screen.getId(), screen.getClass());

    afterShowWindow(screen);

    changeUrl(screen);

    StopWatch afterShowWatch = createStopWatch(ScreenLifeCycle.AFTER_SHOW, screen.getId());

    fireEvent(screen, AfterShowEvent.class, new AfterShowEvent(screen));

    afterShowWatch.stop();

    events.publish(new ScreenOpenedEvent(screen));
}