Search in sources :

Example 26 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ThreadContextBenchmark method setup.

@Setup
public void setup() {
    System.setProperty("log4j2.threadContextMap", IMPLEMENTATIONS.get(threadContextMapAlias).getName());
    ThreadContextBenchmarkAccess.init();
    injector = ContextDataInjectorFactory.createInjector();
    System.out.println(threadContextMapAlias + ": Injector = " + injector);
    reusableContextData = threadContextMapAlias.contains("Array") ? new SortedArrayStringMap() : new OpenHashStringMap<>();
    keys = new String[count];
    values = new String[count];
    final Random r = new Random();
    for (int j = 0; j < keys.length; j++) {
        final char[] str = new char[KEY_LENGTH];
        for (int i = 0; i < str.length; i++) {
            str[i] = (char) r.nextInt();
        }
        keys[j] = new String(str);
        values[j] = new String(str);
    }
    // count
    final int PROPERTIES_COUNT = 5;
    propertyList = new ArrayList<>(PROPERTIES_COUNT);
    for (int j = 0; j < PROPERTIES_COUNT; j++) {
        final char[] str = new char[KEY_LENGTH];
        for (int i = 0; i < str.length; i++) {
            str[i] = (char) r.nextInt();
        }
        propertyList.add(Property.createProperty(new String(str), new String(str)));
    }
    // ensure ThreadContext contains values
    clearAndPut();
}
Also used : Random(java.util.Random) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) OpenHashStringMap(org.apache.logging.log4j.perf.nogc.OpenHashStringMap) Setup(org.openjdk.jmh.annotations.Setup)

Example 27 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class SortedArrayVsHashMapBenchmark method setup.

@Setup
public void setup() {
    openHashMapContextData = new OpenHashStringMap<>();
    sortedStringArrayMap = new SortedArrayStringMap();
    map = new HashMap<>();
    keys = new String[count];
    final Random r = new Random();
    for (int j = 0; j < keys.length; j++) {
        final char[] str = new char[length];
        for (int i = 0; i < str.length; i++) {
            str[i] = (char) r.nextInt();
        }
        keys[j] = new String(str);
    }
    populatedMap = new HashMap<>();
    for (int i = 0; i < count; i++) {
        populatedMap.put(keys[i], value);
    }
    populatedSortedStringArrayMap = new SortedArrayStringMap();
    for (int i = 0; i < count; i++) {
        populatedSortedStringArrayMap.putValue(keys[i], value);
    }
    populatedOpenHashContextData = new OpenHashStringMap<>();
    for (int i = 0; i < count; i++) {
        populatedOpenHashContextData.putValue(keys[i], value);
    }
}
Also used : Random(java.util.Random) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Setup(org.openjdk.jmh.annotations.Setup)

Example 28 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project instrumentation-java by census-instrumentation.

the class ContextDataUtils method getContextAndTracingData.

static StringMap getContextAndTracingData() {
    SpanContext spanContext = getCurrentSpanContext();
    ReadOnlyThreadContextMap context = ThreadContext.getThreadContextMap();
    SortedArrayStringMap stringMap;
    if (context == null) {
        stringMap = new SortedArrayStringMap(ThreadContext.getImmutableContext());
    } else {
        StringMap contextData = context.getReadOnlyContextData();
        stringMap = new SortedArrayStringMap(contextData.size() + 3);
        stringMap.putAll(contextData);
    }
    // TODO(sebright): Move the calls to TraceId.toLowerBase16() and SpanId.toLowerBase16() out of
    // the critical path by wrapping the trace and span IDs in objects that call toLowerBase16() in
    // their toString() methods, after there is a fix for
    // https://github.com/census-instrumentation/opencensus-java/issues/1436.
    stringMap.putValue(OpenCensusTraceContextDataInjector.TRACE_ID_CONTEXT_KEY, spanContext.getTraceId().toLowerBase16());
    stringMap.putValue(OpenCensusTraceContextDataInjector.SPAN_ID_CONTEXT_KEY, spanContext.getSpanId().toLowerBase16());
    stringMap.putValue(OpenCensusTraceContextDataInjector.TRACE_SAMPLED_CONTEXT_KEY, spanContext.getTraceOptions().isSampled() ? "true" : "false");
    return stringMap;
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) SpanContext(io.opencensus.trace.SpanContext) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) ReadOnlyThreadContextMap(org.apache.logging.log4j.spi.ReadOnlyThreadContextMap)

Aggregations

SortedArrayStringMap (org.apache.logging.log4j.util.SortedArrayStringMap)28 StringMap (org.apache.logging.log4j.util.StringMap)19 LogEvent (org.apache.logging.log4j.core.LogEvent)9 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)9 Test (org.junit.Test)9 Test (org.junit.jupiter.api.Test)9 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)8 Message (org.apache.logging.log4j.message.Message)4 ReadOnlyStringMap (org.apache.logging.log4j.util.ReadOnlyStringMap)4 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Random (java.util.Random)2 LogEventAdapter (org.apache.log4j.bridge.LogEventAdapter)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 Marker (org.apache.logging.log4j.Marker)2 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)2 ClockFactoryTest (org.apache.logging.log4j.core.time.ClockFactoryTest)2 JsonTemplateLayout (org.apache.logging.log4j.layout.template.json.JsonTemplateLayout)2