Search in sources :

Example 1 with SingleCacheStateInformationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType in project midpoint by Evolveum.

the class InternalsCachePanel method getCacheInformation.

private String getCacheInformation() {
    StringBuilder sb = new StringBuilder();
    CachesStateInformationType state = MidPointApplication.get().getCacheRegistry().getStateInformation();
    List<KeyValueTreeNode<String, SizeInformation>> trees = new ArrayList<>();
    for (SingleCacheStateInformationType entry : state.getEntry()) {
        KeyValueTreeNode<String, SizeInformation> root = new KeyValueTreeNode<>(entry.getName(), new SizeInformation(entry));
        trees.add(root);
        addComponents(root, entry.getComponent());
    }
    Holder<Integer> maxLabelLength = new Holder<>(0);
    // to avoid issues with log10
    Holder<Integer> maxSize = new Holder<>(1);
    // to avoid issues with log10
    Holder<Integer> maxSecondarySize = new Holder<>(1);
    trees.forEach(tree -> tree.acceptDepthFirst(node -> {
        int labelLength = node.getUserObject().getKey().length() + node.getDepth() * 2;
        int size = node.getUserObject().getValue().size;
        int secondarySize = node.getUserObject().getValue().secondarySize;
        if (labelLength > maxLabelLength.getValue()) {
            maxLabelLength.setValue(labelLength);
        }
        if (size > maxSize.getValue()) {
            maxSize.setValue(size);
        }
        if (secondarySize > maxSecondarySize.getValue()) {
            maxSecondarySize.setValue(secondarySize);
        }
    }));
    int labelSize = Math.max(maxLabelLength.getValue() + 1, 30);
    int sizeSize = Math.max((int) Math.log10(maxSize.getValue()) + 2, 7);
    int secondarySizeSize = Math.max((int) Math.log10(maxSecondarySize.getValue()) + 2, 8);
    int firstPart = labelSize + 3;
    int secondPart = sizeSize + 2;
    int thirdPart = secondarySizeSize + 3;
    String headerFormatString = "  %-" + labelSize + "s | %" + sizeSize + "s | %" + secondarySizeSize + "s\n";
    String valueFormatString = "  %-" + labelSize + "s | %" + sizeSize + "d | %" + secondarySizeSize + "s\n";
    sb.append("\n");
    sb.append(String.format(headerFormatString, "Cache", "Size", "Sec. size"));
    sb.append(StringUtils.repeat("=", firstPart)).append("+").append(StringUtils.repeat("=", secondPart)).append("+").append(StringUtils.repeat("=", thirdPart)).append("\n");
    trees.forEach(tree -> {
        tree.acceptDepthFirst(node -> printNode(sb, valueFormatString, node));
        sb.append(StringUtils.repeat("-", firstPart)).append("+").append(StringUtils.repeat("-", secondPart)).append("+").append(StringUtils.repeat("-", thirdPart)).append("\n");
    });
    return sb.toString();
}
Also used : Holder(com.evolveum.midpoint.util.Holder) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) TreeNode(com.evolveum.midpoint.util.TreeNode) StringUtils(org.apache.commons.lang3.StringUtils) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) CachesStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachesStateInformationType) ComponentSizeInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ComponentSizeInformationType) ArrayList(java.util.ArrayList) List(java.util.List) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) Pair(org.apache.commons.lang3.tuple.Pair) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) KeyValueTreeNode(com.evolveum.midpoint.util.KeyValueTreeNode) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) KeyValueTreeNode(com.evolveum.midpoint.util.KeyValueTreeNode) Holder(com.evolveum.midpoint.util.Holder) ArrayList(java.util.ArrayList) CachesStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachesStateInformationType) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)

Example 2 with SingleCacheStateInformationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType in project midpoint by Evolveum.

the class LocalRepoCacheCollection method getStateInformation.

public void getStateInformation(List<SingleCacheStateInformationType> rv) {
    rv.add(new SingleCacheStateInformationType(prismContext).name(LocalObjectCache.class.getName()).size(LocalObjectCache.getTotalSize(LOCAL_OBJECT_CACHE_INSTANCE)));
    rv.add(new SingleCacheStateInformationType(prismContext).name(LocalVersionCache.class.getName()).size(LocalVersionCache.getTotalSize(LOCAL_VERSION_CACHE_INSTANCE)));
    rv.add(new SingleCacheStateInformationType(prismContext).name(LocalQueryCache.class.getName()).size(LocalQueryCache.getTotalSize(LOCAL_QUERY_CACHE_INSTANCE)).secondarySize(LocalQueryCache.getTotalCachedObjects(LOCAL_QUERY_CACHE_INSTANCE)));
}
Also used : SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)

Example 3 with SingleCacheStateInformationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType in project midpoint by Evolveum.

the class GlobalQueryCache method getStateInformation.

public Collection<SingleCacheStateInformationType> getStateInformation() {
    Map<Class<?>, MutablePair<Integer, Integer>> counts = new HashMap<>();
    AtomicInteger queries = new AtomicInteger(0);
    AtomicInteger objects = new AtomicInteger(0);
    if (cache != null) {
        cache.invokeAll(cache.keys(), e -> {
            QueryKey queryKey = e.getKey();
            Class<?> objectType = queryKey.getType();
            int resultingObjects = e.getValue().getResult().size();
            MutablePair<Integer, Integer> value = counts.get(objectType);
            if (value == null) {
                value = new MutablePair<>(0, 0);
                counts.put(objectType, value);
            }
            value.setLeft(value.getLeft() + 1);
            value.setRight(value.getRight() + resultingObjects);
            queries.incrementAndGet();
            objects.addAndGet(resultingObjects);
            return null;
        });
        SingleCacheStateInformationType info = new SingleCacheStateInformationType(prismContext).name(GlobalQueryCache.class.getName()).size(queries.get()).secondarySize(objects.get());
        counts.forEach((type, pair) -> info.beginComponent().name(type.getSimpleName()).size(pair.getLeft()).secondarySize(pair.getRight()));
        return Collections.singleton(info);
    } else {
        return Collections.emptySet();
    }
}
Also used : HashMap(java.util.HashMap) QueryKey(com.evolveum.midpoint.repo.cache.local.QueryKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MutablePair(org.apache.commons.lang3.tuple.MutablePair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)

Example 4 with SingleCacheStateInformationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType in project midpoint by Evolveum.

the class GlobalObjectCache method getStateInformation.

public Collection<SingleCacheStateInformationType> getStateInformation() {
    Map<Class<?>, Integer> counts = new HashMap<>();
    AtomicInteger size = new AtomicInteger(0);
    if (cache != null) {
        cache.invokeAll(cache.keys(), e -> {
            Class<?> objectType = e.getValue().getObjectType();
            counts.compute(objectType, (type, count) -> count != null ? count + 1 : 1);
            size.incrementAndGet();
            return null;
        });
        SingleCacheStateInformationType info = new SingleCacheStateInformationType(prismContext).name(GlobalObjectCache.class.getName()).size(size.get());
        counts.forEach((type, count) -> info.beginComponent().name(type.getSimpleName()).size(count));
        return Collections.singleton(info);
    } else {
        return Collections.emptySet();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)

Example 5 with SingleCacheStateInformationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType in project midpoint by Evolveum.

the class GlobalVersionCache method getStateInformation.

public Collection<SingleCacheStateInformationType> getStateInformation() {
    Map<Class<?>, Integer> counts = new HashMap<>();
    AtomicInteger size = new AtomicInteger(0);
    if (cache != null) {
        cache.invokeAll(cache.keys(), e -> {
            Class<?> objectType = e.getValue().getObjectType();
            counts.compute(objectType, (type, count) -> count != null ? count + 1 : 1);
            size.incrementAndGet();
            return null;
        });
        SingleCacheStateInformationType info = new SingleCacheStateInformationType(prismContext).name(GlobalVersionCache.class.getName()).size(size.get());
        counts.forEach((type, count) -> info.beginComponent().name(type.getSimpleName()).size(count));
        return Collections.singleton(info);
    } else {
        return Collections.emptySet();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)

Aggregations

SingleCacheStateInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)5 HashMap (java.util.HashMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)1 QueryKey (com.evolveum.midpoint.repo.cache.local.QueryKey)1 Holder (com.evolveum.midpoint.util.Holder)1 KeyValueTreeNode (com.evolveum.midpoint.util.KeyValueTreeNode)1 TreeNode (com.evolveum.midpoint.util.TreeNode)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 AceEditor (com.evolveum.midpoint.web.component.AceEditor)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)1 CachesStateInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachesStateInformationType)1 ComponentSizeInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ComponentSizeInformationType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectUtils.defaultIfNull (org.apache.commons.lang3.ObjectUtils.defaultIfNull)1 StringUtils (org.apache.commons.lang3.StringUtils)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1