diff --git a/src/main/java/com/alibaba/druid/support/profile/ProfileEntry.java b/src/main/java/com/alibaba/druid/support/profile/ProfileEntry.java new file mode 100644 index 0000000000..2e370d2e73 --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/profile/ProfileEntry.java @@ -0,0 +1,42 @@ +package com.alibaba.druid.support.profile; + +public class ProfileEntry { + + private final Key key; + private final String type; + + public ProfileEntry(Key key, String type){ + super(); + this.key = key; + this.type = type; + } + + public Key getKey() { + return key; + } + + public String getType() { + return type; + } + + public static class Key { + + private String parent; + private String name; + + public Key(String parentName, String name){ + super(); + this.parent = parentName; + this.name = name; + } + + public String getParent() { + return parent; + } + + public String getName() { + return name; + } + + } +} diff --git a/src/main/java/com/alibaba/druid/support/profile/Profiler.java b/src/main/java/com/alibaba/druid/support/profile/Profiler.java new file mode 100644 index 0000000000..178fd7667e --- /dev/null +++ b/src/main/java/com/alibaba/druid/support/profile/Profiler.java @@ -0,0 +1,59 @@ +package com.alibaba.druid.support.profile; + +import java.util.HashMap; +import java.util.Map; + +import com.alibaba.druid.support.profile.ProfileEntry.Key; + +public class Profiler { + + public static ThreadLocal enableLocal = new ThreadLocal(); + + private static ThreadLocal> entriesLocal = new ThreadLocal>(); + + private final static ThreadLocal currentLocal = new ThreadLocal(); + + public static void setThreadLocalEnable() { + enableLocal.set(true); + } + + public static void setThreadLocalDisable() { + enableLocal.remove(); + } + + public static boolean isEnable() { + return Boolean.TRUE == enableLocal.get(); + } + + public static void enter(String name, String type, long startNano) { + ProfileEntry parent = currentLocal.get(); + String parentName = null; + if (parent != null) { + parentName = parent.getKey().getName(); + } + + ProfileEntry.Key key = new ProfileEntry.Key(parentName, name); + + Map entries = entriesLocal.get(); + if (entries == null) { + entries = new HashMap(); + entriesLocal.set(entries); + } + + ProfileEntry entry = entries.get(key); + if (entry == null) { + entry = new ProfileEntry(key, type); + entries.put(key, entry); + } + + currentLocal.set(entry); + } + + public static ProfileEntry current() { + return currentLocal.get(); + } + + public static void release(long nanoSpan) { + + } +}