@Test @Ignore public void perf_test() { String metric = "mem,host=GunMac.skbroadband,region=seoul used=11656097792i,free=1467994112i,cached=0i,buffered=0i,wired=2481405952i,slab=0i,available_percent=32.152581214904785,total=17179869184i,available=5523771392i,active=8165543936i,inactive=4055777280i,used_percent=67.84741878509521 1532269780000000000"; long start = System.currentTimeMillis(); for (int i = 0; i < 300000; i++) { InfluxSingleLine.of(metric, Configure.getInstance(), start); } System.out.println("[of millis]" + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (int i = 0; i < 300000; i++) { InfluxSingleLine.of(metric, Configure.getInstance(), start); } System.out.println("[of millis]" + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (int i = 0; i < 300000; i++) { InfluxSingleLine.of(metric, Configure.getInstance(), start); } System.out.println("[of millis]" + (System.currentTimeMillis() - start)); }
public static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime) { char[] chars = lineStr.toCharArray(); char sink = '\0'; int mode = 0; StringBuilder measurementSb = new StringBuilder(); StringBuilder tagKeySb = new StringBuilder(); StringBuilder tagValueSb = new StringBuilder(); boolean tagKeyMode = true; Map<String, String> tags = new HashMap<String, String>(); StringBuilder fieldKeySb = new StringBuilder(); StringBuilder fieldValueSb = new StringBuilder(); boolean fieldKeyMode = true; Map<String, String> fields = new HashMap<String, String>(); StringBuilder timestampSb = new StringBuilder(); for (int pos = 0; pos < lineStr.length(); pos++) { char c = chars[pos]; if (mode == 0) { if (sink == '\\') { measurementSb.append(c); sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ',': mode++; break; default: measurementSb.append(c); break; } } } else if (mode == 1) { if (sink == '\\') { if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ' ': mode++; if (tagKeySb.length() > 0) { tags.put(tagKeySb.toString(), tagValueSb.toString()); } break; case '=': tagKeyMode = false; break; case ',': tagKeyMode = true; tags.put(tagKeySb.toString(), tagValueSb.toString()); tagKeySb = new StringBuilder(); tagValueSb = new StringBuilder(); break; default: if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } break; } } } else if (mode == 2) { if (sink == '\\') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': if (sink != '"') { sink = '\\'; } break; case '"': if (sink == '"') { sink = '\0'; } else { sink = '"'; } break; case ' ': if (sink != '"') { mode++; if (fieldKeySb.length() > 0) { fields.put(fieldKeySb.toString(), fieldValueSb.toString()); } } break; case '=': if (sink != '"') { fieldKeyMode = false; } break; case ',': if (sink != '"') { fieldKeyMode = true; fields.put(fieldKeySb.toString(), fieldValueSb.toString()); fieldKeySb = new StringBuilder(); fieldValueSb = new StringBuilder(); } break; default: if (sink != '"') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } } break; } } } else if (mode == 3) { timestampSb.append(c); } } String measurement = measurementSb.toString(); ScouterTgMtConfig tConfig = configure.telegrafInputConfigMap.get(measurement); if (tConfig == null) { return null; } if (!configure.input_telegraf_debug_enabled && tConfig.isDebugEnabled()) { Logger.println("TG006", "[line protocol received] " + lineStr); } if (!tConfig.isEnabled()) { return null; } if (!tConfig.isValidConfig()) { return null; } if (!tConfig.isTagFilterMatching(tags)) { return null; } try { return new InfluxSingleLine(tConfig, measurement, tags, fields, receivedTime, Long.parseLong(timestampSb.toString()) / 1000000, tConfig.isDebugEnabled()); } catch (Throwable t) { t.printStackTrace(); return null; } }
InfluxSingleLine { public static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime) { char[] chars = lineStr.toCharArray(); char sink = '\0'; int mode = 0; StringBuilder measurementSb = new StringBuilder(); StringBuilder tagKeySb = new StringBuilder(); StringBuilder tagValueSb = new StringBuilder(); boolean tagKeyMode = true; Map<String, String> tags = new HashMap<String, String>(); StringBuilder fieldKeySb = new StringBuilder(); StringBuilder fieldValueSb = new StringBuilder(); boolean fieldKeyMode = true; Map<String, String> fields = new HashMap<String, String>(); StringBuilder timestampSb = new StringBuilder(); for (int pos = 0; pos < lineStr.length(); pos++) { char c = chars[pos]; if (mode == 0) { if (sink == '\\') { measurementSb.append(c); sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ',': mode++; break; default: measurementSb.append(c); break; } } } else if (mode == 1) { if (sink == '\\') { if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ' ': mode++; if (tagKeySb.length() > 0) { tags.put(tagKeySb.toString(), tagValueSb.toString()); } break; case '=': tagKeyMode = false; break; case ',': tagKeyMode = true; tags.put(tagKeySb.toString(), tagValueSb.toString()); tagKeySb = new StringBuilder(); tagValueSb = new StringBuilder(); break; default: if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } break; } } } else if (mode == 2) { if (sink == '\\') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': if (sink != '"') { sink = '\\'; } break; case '"': if (sink == '"') { sink = '\0'; } else { sink = '"'; } break; case ' ': if (sink != '"') { mode++; if (fieldKeySb.length() > 0) { fields.put(fieldKeySb.toString(), fieldValueSb.toString()); } } break; case '=': if (sink != '"') { fieldKeyMode = false; } break; case ',': if (sink != '"') { fieldKeyMode = true; fields.put(fieldKeySb.toString(), fieldValueSb.toString()); fieldKeySb = new StringBuilder(); fieldValueSb = new StringBuilder(); } break; default: if (sink != '"') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } } break; } } } else if (mode == 3) { timestampSb.append(c); } } String measurement = measurementSb.toString(); ScouterTgMtConfig tConfig = configure.telegrafInputConfigMap.get(measurement); if (tConfig == null) { return null; } if (!configure.input_telegraf_debug_enabled && tConfig.isDebugEnabled()) { Logger.println("TG006", "[line protocol received] " + lineStr); } if (!tConfig.isEnabled()) { return null; } if (!tConfig.isValidConfig()) { return null; } if (!tConfig.isTagFilterMatching(tags)) { return null; } try { return new InfluxSingleLine(tConfig, measurement, tags, fields, receivedTime, Long.parseLong(timestampSb.toString()) / 1000000, tConfig.isDebugEnabled()); } catch (Throwable t) { t.printStackTrace(); return null; } } }
InfluxSingleLine { public static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime) { char[] chars = lineStr.toCharArray(); char sink = '\0'; int mode = 0; StringBuilder measurementSb = new StringBuilder(); StringBuilder tagKeySb = new StringBuilder(); StringBuilder tagValueSb = new StringBuilder(); boolean tagKeyMode = true; Map<String, String> tags = new HashMap<String, String>(); StringBuilder fieldKeySb = new StringBuilder(); StringBuilder fieldValueSb = new StringBuilder(); boolean fieldKeyMode = true; Map<String, String> fields = new HashMap<String, String>(); StringBuilder timestampSb = new StringBuilder(); for (int pos = 0; pos < lineStr.length(); pos++) { char c = chars[pos]; if (mode == 0) { if (sink == '\\') { measurementSb.append(c); sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ',': mode++; break; default: measurementSb.append(c); break; } } } else if (mode == 1) { if (sink == '\\') { if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ' ': mode++; if (tagKeySb.length() > 0) { tags.put(tagKeySb.toString(), tagValueSb.toString()); } break; case '=': tagKeyMode = false; break; case ',': tagKeyMode = true; tags.put(tagKeySb.toString(), tagValueSb.toString()); tagKeySb = new StringBuilder(); tagValueSb = new StringBuilder(); break; default: if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } break; } } } else if (mode == 2) { if (sink == '\\') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': if (sink != '"') { sink = '\\'; } break; case '"': if (sink == '"') { sink = '\0'; } else { sink = '"'; } break; case ' ': if (sink != '"') { mode++; if (fieldKeySb.length() > 0) { fields.put(fieldKeySb.toString(), fieldValueSb.toString()); } } break; case '=': if (sink != '"') { fieldKeyMode = false; } break; case ',': if (sink != '"') { fieldKeyMode = true; fields.put(fieldKeySb.toString(), fieldValueSb.toString()); fieldKeySb = new StringBuilder(); fieldValueSb = new StringBuilder(); } break; default: if (sink != '"') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } } break; } } } else if (mode == 3) { timestampSb.append(c); } } String measurement = measurementSb.toString(); ScouterTgMtConfig tConfig = configure.telegrafInputConfigMap.get(measurement); if (tConfig == null) { return null; } if (!configure.input_telegraf_debug_enabled && tConfig.isDebugEnabled()) { Logger.println("TG006", "[line protocol received] " + lineStr); } if (!tConfig.isEnabled()) { return null; } if (!tConfig.isValidConfig()) { return null; } if (!tConfig.isTagFilterMatching(tags)) { return null; } try { return new InfluxSingleLine(tConfig, measurement, tags, fields, receivedTime, Long.parseLong(timestampSb.toString()) / 1000000, tConfig.isDebugEnabled()); } catch (Throwable t) { t.printStackTrace(); return null; } } private  InfluxSingleLine(ScouterTgMtConfig tConfig,
                             String measurement,
                             Map<String, String> tags,
                             Map<String, String> fields,
                             long receivedTime,
                             long timestampOrigin,
                             boolean debug); }
InfluxSingleLine { public static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime) { char[] chars = lineStr.toCharArray(); char sink = '\0'; int mode = 0; StringBuilder measurementSb = new StringBuilder(); StringBuilder tagKeySb = new StringBuilder(); StringBuilder tagValueSb = new StringBuilder(); boolean tagKeyMode = true; Map<String, String> tags = new HashMap<String, String>(); StringBuilder fieldKeySb = new StringBuilder(); StringBuilder fieldValueSb = new StringBuilder(); boolean fieldKeyMode = true; Map<String, String> fields = new HashMap<String, String>(); StringBuilder timestampSb = new StringBuilder(); for (int pos = 0; pos < lineStr.length(); pos++) { char c = chars[pos]; if (mode == 0) { if (sink == '\\') { measurementSb.append(c); sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ',': mode++; break; default: measurementSb.append(c); break; } } } else if (mode == 1) { if (sink == '\\') { if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ' ': mode++; if (tagKeySb.length() > 0) { tags.put(tagKeySb.toString(), tagValueSb.toString()); } break; case '=': tagKeyMode = false; break; case ',': tagKeyMode = true; tags.put(tagKeySb.toString(), tagValueSb.toString()); tagKeySb = new StringBuilder(); tagValueSb = new StringBuilder(); break; default: if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } break; } } } else if (mode == 2) { if (sink == '\\') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': if (sink != '"') { sink = '\\'; } break; case '"': if (sink == '"') { sink = '\0'; } else { sink = '"'; } break; case ' ': if (sink != '"') { mode++; if (fieldKeySb.length() > 0) { fields.put(fieldKeySb.toString(), fieldValueSb.toString()); } } break; case '=': if (sink != '"') { fieldKeyMode = false; } break; case ',': if (sink != '"') { fieldKeyMode = true; fields.put(fieldKeySb.toString(), fieldValueSb.toString()); fieldKeySb = new StringBuilder(); fieldValueSb = new StringBuilder(); } break; default: if (sink != '"') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } } break; } } } else if (mode == 3) { timestampSb.append(c); } } String measurement = measurementSb.toString(); ScouterTgMtConfig tConfig = configure.telegrafInputConfigMap.get(measurement); if (tConfig == null) { return null; } if (!configure.input_telegraf_debug_enabled && tConfig.isDebugEnabled()) { Logger.println("TG006", "[line protocol received] " + lineStr); } if (!tConfig.isEnabled()) { return null; } if (!tConfig.isValidConfig()) { return null; } if (!tConfig.isTagFilterMatching(tags)) { return null; } try { return new InfluxSingleLine(tConfig, measurement, tags, fields, receivedTime, Long.parseLong(timestampSb.toString()) / 1000000, tConfig.isDebugEnabled()); } catch (Throwable t) { t.printStackTrace(); return null; } } private  InfluxSingleLine(ScouterTgMtConfig tConfig,
                             String measurement,
                             Map<String, String> tags,
                             Map<String, String> fields,
                             long receivedTime,
                             long timestampOrigin,
                             boolean debug); static String toLineStringKey(String lineString); static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime); String getMeasurement(); String getHost(); String getFamily(); String getObjType(); String getObjTypeIcon(); String getObjName(); int getObjHash(); long getReceivedTime(); long getTimestampOrigin(); Map<String, String> getTags(); Map<CounterProtocol, NumberValue> getNumberFields(); boolean isDebug(); ObjectPack toObjectPack(String address, int deadTime); PerfCounterPack toPerfCounterPack(); @Override String toString(); }
InfluxSingleLine { public static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime) { char[] chars = lineStr.toCharArray(); char sink = '\0'; int mode = 0; StringBuilder measurementSb = new StringBuilder(); StringBuilder tagKeySb = new StringBuilder(); StringBuilder tagValueSb = new StringBuilder(); boolean tagKeyMode = true; Map<String, String> tags = new HashMap<String, String>(); StringBuilder fieldKeySb = new StringBuilder(); StringBuilder fieldValueSb = new StringBuilder(); boolean fieldKeyMode = true; Map<String, String> fields = new HashMap<String, String>(); StringBuilder timestampSb = new StringBuilder(); for (int pos = 0; pos < lineStr.length(); pos++) { char c = chars[pos]; if (mode == 0) { if (sink == '\\') { measurementSb.append(c); sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ',': mode++; break; default: measurementSb.append(c); break; } } } else if (mode == 1) { if (sink == '\\') { if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': sink = '\\'; break; case ' ': mode++; if (tagKeySb.length() > 0) { tags.put(tagKeySb.toString(), tagValueSb.toString()); } break; case '=': tagKeyMode = false; break; case ',': tagKeyMode = true; tags.put(tagKeySb.toString(), tagValueSb.toString()); tagKeySb = new StringBuilder(); tagValueSb = new StringBuilder(); break; default: if (tagKeyMode) { tagKeySb.append(c); } else { tagValueSb.append(c); } break; } } } else if (mode == 2) { if (sink == '\\') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } sink = '\0'; } else { switch (c) { case '\\': if (sink != '"') { sink = '\\'; } break; case '"': if (sink == '"') { sink = '\0'; } else { sink = '"'; } break; case ' ': if (sink != '"') { mode++; if (fieldKeySb.length() > 0) { fields.put(fieldKeySb.toString(), fieldValueSb.toString()); } } break; case '=': if (sink != '"') { fieldKeyMode = false; } break; case ',': if (sink != '"') { fieldKeyMode = true; fields.put(fieldKeySb.toString(), fieldValueSb.toString()); fieldKeySb = new StringBuilder(); fieldValueSb = new StringBuilder(); } break; default: if (sink != '"') { if (fieldKeyMode) { fieldKeySb.append(c); } else { fieldValueSb.append(c); } } break; } } } else if (mode == 3) { timestampSb.append(c); } } String measurement = measurementSb.toString(); ScouterTgMtConfig tConfig = configure.telegrafInputConfigMap.get(measurement); if (tConfig == null) { return null; } if (!configure.input_telegraf_debug_enabled && tConfig.isDebugEnabled()) { Logger.println("TG006", "[line protocol received] " + lineStr); } if (!tConfig.isEnabled()) { return null; } if (!tConfig.isValidConfig()) { return null; } if (!tConfig.isTagFilterMatching(tags)) { return null; } try { return new InfluxSingleLine(tConfig, measurement, tags, fields, receivedTime, Long.parseLong(timestampSb.toString()) / 1000000, tConfig.isDebugEnabled()); } catch (Throwable t) { t.printStackTrace(); return null; } } private  InfluxSingleLine(ScouterTgMtConfig tConfig,
                             String measurement,
                             Map<String, String> tags,
                             Map<String, String> fields,
                             long receivedTime,
                             long timestampOrigin,
                             boolean debug); static String toLineStringKey(String lineString); static InfluxSingleLine of(String lineStr, Configure configure, long receivedTime); String getMeasurement(); String getHost(); String getFamily(); String getObjType(); String getObjTypeIcon(); String getObjName(); int getObjHash(); long getReceivedTime(); long getTimestampOrigin(); Map<String, String> getTags(); Map<CounterProtocol, NumberValue> getNumberFields(); boolean isDebug(); ObjectPack toObjectPack(String address, int deadTime); PerfCounterPack toPerfCounterPack(); @Override String toString();  }