[Title] Add org.tizen.common.dlog package for dlogutil
authorTaeyoung Son <taeyoung2.son@samsung.com>
Fri, 30 Aug 2013 08:08:08 +0000 (17:08 +0900)
committerTaeyoung Son <taeyoung2.son@samsung.com>
Mon, 16 Sep 2013 07:53:40 +0000 (16:53 +0900)
        Add PsReceiver
[Desc.]
[Issue]

Change-Id: I16671c99c154a6cb5045912d7a1e606be13f3536

13 files changed:
org.tizen.common.sdblib/META-INF/MANIFEST.MF
org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogBriefParser.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogFormat.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogInfo.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogLongParser.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogParserFactory.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/IDlogParser.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/DlogReceiver.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/PsInfo.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/PsReceiver.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/util/DlogUtil.java [new file with mode: 0644]
org.tizen.common.sdblib/src/org/tizen/sdblib/util/StringUtil.java
org.tizen.common/src/org/tizen/common/util/StringUtil.java

index 6529013..0173fb5 100644 (file)
@@ -7,6 +7,7 @@ Bundle-Version: 2.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Export-Package: org.tizen.sdblib,
  org.tizen.sdblib.daemon,
+ org.tizen.sdblib.dlog,
  org.tizen.sdblib.exception,
  org.tizen.sdblib.receiver,
  org.tizen.sdblib.service,
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogBriefParser.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogBriefParser.java
new file mode 100644 (file)
index 0000000..808bd8b
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.dlog;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.tizen.sdblib.util.StringUtil;
+import org.tizen.sdblib.util.LogLevel;
+
+/**
+ * The parser that is used when sdb execute dlogutil with "-v brief" option. 
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ * 
+ */
+public class DlogBriefParser implements IDlogParser {
+    /**
+     * log's format: <br>
+     *      level/tag( pid): message
+     */
+    private static final Pattern pattern = Pattern.compile("^([VDIWEF])/(.+)\\(\\s*(\\d+)\\):\\s(.+)");
+
+    @Override
+    public DlogInfo[] parse(String... lines) {
+        List<DlogInfo> infos = new ArrayList<DlogInfo>();
+        
+        DlogInfo info = null;
+
+        for (String line : lines) {
+            // ignore empty line.
+            if (line.length() <= 0) {
+                continue;
+            }
+
+            // check if the line is header line.
+            String[] matches = StringUtil.split(line, pattern);
+
+            // a header line
+            if (matches!=null && matches.length == 4) {
+                info = new DlogInfo();
+                info.setLogLevel(LogLevel.getByLetter(matches[0]));
+                info.setTag(matches[1]);
+                info.setPid(Integer.parseInt(matches[2]));
+                info.setCommand(matches[3]);
+
+                infos.add(info);
+            }
+        } 
+
+        return infos.toArray(new DlogInfo[0]);
+    }
+
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogFormat.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogFormat.java
new file mode 100644 (file)
index 0000000..61e78ae
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.dlog;
+
+/**
+ * enum class about dlogutil command's "-v" option values.
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ *
+ */
+public enum DlogFormat {
+    BRIEF("brief"), //$NON-NLS-1$
+//    PROCESS, //$NON-NLS-1$
+//    TAG, //$NON-NLS-1$
+//    THREAD, //$NON-NLS-1$
+//    RAW, //$NON-NLS-1$
+//    TIME, //$NON-NLS-1$
+//    THREADTIME, //$NON-NLS-1$
+    LONG("long");
+    
+    String vOption;
+
+    /**
+     * dlogutil command's "-v" option format
+     * @param vOption
+     */
+    DlogFormat(String vOption) {
+        this.vOption = vOption;
+    }
+    
+    /**
+     * Get option value
+     * @return option value
+     */
+    public String getOption() {
+        return this.vOption;
+    }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogInfo.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogInfo.java
new file mode 100644 (file)
index 0000000..fe5ff71
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.dlog;
+
+import org.tizen.sdblib.util.LogLevel;
+
+/**
+ * DlogInfo
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ *
+ */
+public class DlogInfo {
+
+    private LogLevel logLevel;
+    private int pid;
+    private String command;
+    private String time;
+    private int tid;
+    private String tag;
+
+    /**
+     * Get {@link LogLevel}
+     * 
+     * @return {@link LogLevel}
+     */
+    public LogLevel getLogLevel() {
+        return logLevel;
+    }
+    /**
+     * Set {@link LogLevel}
+     * @param logLevel the {@link LogLevel}
+     */
+    public void setLogLevel(LogLevel logLevel) {
+        this.logLevel = logLevel;
+    }
+    /**
+     * Get pid
+     * @return the pid
+     */
+    public int getPid() {
+        return pid;
+    }
+    /**
+     * @param pid the pid to set
+     */
+    public void setPid(int pid) {
+        this.pid = pid;
+    }
+    /**
+     * @return the command
+     */
+    public String getCommand() {
+        return command;
+    }
+    /**
+     * @return the tag
+     */
+    public String getTag() {
+        return tag;
+    }
+    /**
+     * @param command the command to set
+     */
+    public void setCommand(String command) {
+        this.command = command;
+    }
+    /**
+     * @return the time
+     */
+    public String getTime() {
+        return time;
+    }
+    /**
+     * @param time the time to set
+     */
+    public void setTime(String time) {
+        this.time = time;
+    }
+    /**
+     * @return the tid
+     */
+    public int getTid() {
+        return tid;
+    }
+    /**
+     * @param tid the tid to set
+     */
+    public void setTid(int tid) {
+        this.tid = tid;
+    }
+
+    /**
+     * @param tag the tag to set
+     */
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogLongParser.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogLongParser.java
new file mode 100644 (file)
index 0000000..032a7c4
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.dlog;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.tizen.sdblib.util.StringUtil;
+import org.tizen.sdblib.util.LogLevel;
+
+/**
+ * The parser that is used when sdb execute dlogutil with "-v long" option. 
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ * 
+ */
+public class DlogLongParser implements IDlogParser {
+    /**
+     * log's format: 
+     *      [ time pid: tid level/tag ]\n
+     *      message
+     */
+    private static final Pattern pattern = Pattern.compile("^\\[\\s(\\d\\d-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d\\.\\d+)" + "\\s+(\\d*):\\s*(\\d+)\\s([VDIWEF])/(.+)\\s+\\]$");
+
+    @Override
+    public DlogInfo[] parse(String... lines) {
+        List<DlogInfo> infos = new ArrayList<DlogInfo>();
+
+        DlogInfo info = null;
+
+        for (String line : lines) {
+            // ignore empty line.
+            if (line.length() <= 0) {
+                continue;
+            }
+
+            // check if the line is header line.
+            String[] matches = StringUtil.split(line, pattern);
+
+            // a header line
+            if (matches!=null && matches.length == 5) {
+                info = new DlogInfo();
+                info.setTime(matches[0]);
+                info.setPid(Integer.parseInt(matches[1]));
+                info.setTid(Integer.parseInt(matches[2]));
+                info.setLogLevel(LogLevel.getByLetter(matches[3]));
+                info.setTag(matches[4]);
+
+                infos.add(info);
+            } else {
+                if (info == null) {
+                    continue;
+                }
+                info.setCommand(line.replaceAll("\t", "    "));
+            }
+        } 
+
+        return infos.toArray(new DlogInfo[0]);
+    }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogParserFactory.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/DlogParserFactory.java
new file mode 100644 (file)
index 0000000..6db3ead
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.dlog;
+
+/**
+ * Dlogutil's parser factory
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ *
+ */
+public class DlogParserFactory {
+    /**
+     * Get parser
+     * 
+     * @param {@link DlogFormat}
+     * @return
+     */
+    public static IDlogParser getParser(DlogFormat format) {
+        IDlogParser parser = null;
+        if (format.equals(DlogFormat.BRIEF)) {
+            parser = new DlogBriefParser();
+        } else if (format.equals(DlogFormat.LONG)) {
+            parser = new DlogLongParser();
+        } else {
+            //could not support yet.
+        }
+        return parser;
+    }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/IDlogParser.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/dlog/IDlogParser.java
new file mode 100644 (file)
index 0000000..cf67b84
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.dlog;
+
+/**
+ * Parse the dlogutil command's logs.
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ *
+ */
+public interface IDlogParser {
+    /**
+     * Parse each lines and add to {@link DlogInfo} list
+     * @param lines target line list for parse.
+     * @return {@link DlogInfo} list
+     */
+    public DlogInfo[] parse(String... lines);
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/DlogReceiver.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/DlogReceiver.java
new file mode 100644 (file)
index 0000000..7d5c5ee
--- /dev/null
@@ -0,0 +1,35 @@
+package org.tizen.sdblib.receiver;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.tizen.sdblib.dlog.DlogFormat;
+import org.tizen.sdblib.dlog.DlogInfo;
+import org.tizen.sdblib.util.DlogUtil;
+
+public class DlogReceiver extends MultiLineReceiver {
+
+    private DlogFormat dlogFormat;
+    private Collection<DlogInfo> dlogUtilLogs = new ArrayList<DlogInfo>();
+
+    public DlogReceiver(DlogFormat format) {
+        this.dlogFormat = format;
+    }
+
+    @Override
+    public void processNewLines(String[] lines) {
+        DlogInfo[] infos = DlogUtil.getDlogInfos(dlogFormat, lines);
+
+        for (DlogInfo info : infos) {
+            dlogUtilLogs.add(info);
+        }
+    }
+
+    public DlogInfo[] getDlogInfos() {
+        return dlogUtilLogs.toArray(new DlogInfo[dlogUtilLogs.size()]);
+    }
+    
+    protected DlogFormat getDlogFormat() {
+        return this.dlogFormat;
+    }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/PsInfo.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/PsInfo.java
new file mode 100644 (file)
index 0000000..815d131
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.receiver;
+
+import java.util.HashMap;
+
+/**
+ * Target(device or emulator)'s process status information
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ * 
+ */
+public class PsInfo extends HashMap<String, String>{
+
+    /**
+     * generated version id
+     */
+    private static final long serialVersionUID = -2462043900990234213L;
+
+    /**
+     * Set information of process status
+     * @param key the key what you want to set.(UID, PID, PPID,,, etc.)
+     * @param value the value about key
+     */
+    public void set(String key, String value) {
+        put(key, value);
+    }
+
+    /**
+     * Get information of process status
+     * @param key the key what you want to get value
+     * @return the value about the key
+     */
+    public String get(String key) {
+        String value = super.get(key);
+        return (value==null) ? "" : value;
+    }
+}
\ No newline at end of file
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/PsReceiver.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/receiver/PsReceiver.java
new file mode 100644 (file)
index 0000000..fd0c345
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.receiver;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.sdblib.util.ArrayUtil;
+import org.tizen.sdblib.util.StringUtil;
+
+/**
+ * The Receiver that is used when sdb execute "ps" command.
+ * 
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ * 
+ */
+public class PsReceiver extends MultiLineReceiver {
+
+    private final static String DELIMITER = " ";
+
+    /**
+     * Column list
+     */
+    private String[] keys = null;
+
+    /**
+     * {@link PsInfo} list
+     */
+    private List<PsInfo> psInfos = new ArrayList<PsInfo>();
+
+    @Override
+    public void processNewLines(String[] lines) {
+        generatePsInfos(lines);
+    }
+
+    /**
+     * Create {@link PsInfo} and add to list.<br>
+     * If the {@link #keys} not set, <code>lines</code> parameter's first array will be set to {@link #keys}.
+     * @param lines "ps" command's result array
+     * @return
+     */
+    private void generatePsInfos(String[] lines) {
+        int startLine=0;
+        if (ArrayUtil.isEmpty(keys)) {
+            keys = StringUtil.split(lines[startLine], DELIMITER);
+            startLine++;
+        }
+
+        for (int i=startLine; i<lines.length;i++) {
+            PsInfo psInfo = createPsInfo(lines[i], keys);
+            if (psInfo != null) {
+                add(psInfo);
+            }
+        }
+    }
+
+    /**
+     * Add {@link PsInfo} to list
+     * @param psInfo
+     */
+    private void add(PsInfo psInfo) {
+        psInfos.add(psInfo);
+    }
+
+    /**
+     * Create {@link PsInfo}
+     * @param line
+     * @param keys
+     * @return
+     */
+    private PsInfo createPsInfo(String line, String[] keys) {
+        /* 
+         * like this:
+         * UID        PID  PPID  C STIME TTY          TIME CMD
+           root         1     0  0 Sep02 ?        00:00:00 /usr/lib/systemd/systemd
+         */
+
+        PsInfo psInfo = new PsInfo();
+        String[] values = StringUtil.split(line, DELIMITER);
+        if (keys.length > values.length) {
+            return null;
+        }
+
+        for (int i=0; i<keys.length; i++) {
+            StringBuffer value = new StringBuffer();
+            if (i==keys.length-1) {
+                for (int j=i;j<values.length;j++) {
+                    value.append(values[j]);
+                }
+            } else {
+                value.append(values[i]);
+            }
+
+            psInfo.set(keys[i], value.toString());
+        }
+        return psInfo;
+    }
+
+    /**
+     * Get all generated {@link PsInfo} list
+     * 
+     * @return {@link #psInfos}
+     */
+    public PsInfo[] getPsInfos() {
+        return this.psInfos.toArray(new PsInfo[0]);
+    }
+
+    /**
+     * Get {@link PsInfo} list what equals key and value.
+     * 
+     * @param key the key what you find
+     * @param value the value what you find
+     * @return {@link PsInfo} list
+     */
+    public PsInfo[] getPsInfos(String key, String value) {
+        List<PsInfo> psInfos = new ArrayList<PsInfo>();
+
+        for (PsInfo psInfo : getPsInfos()) {
+            if (psInfo.get(key).equals(value)) {
+                psInfos.add(psInfo);
+            }
+        }
+        return psInfos.toArray(new PsInfo[0]);
+    }
+    
+    /**
+     * Clean {@link #keys} and {@link #psInfos}
+     */
+    public void clear() {
+        this.keys = null;
+        this.psInfos.clear();
+    }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/util/DlogUtil.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/util/DlogUtil.java
new file mode 100644 (file)
index 0000000..2a13fa8
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+*  Common
+*
+* Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: 
+* Taeyoung Song <taeyoung2.son@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib.util;
+
+import org.tizen.sdblib.dlog.DlogFormat;
+import org.tizen.sdblib.dlog.DlogInfo;
+import org.tizen.sdblib.dlog.DlogParserFactory;
+import org.tizen.sdblib.dlog.IDlogParser;
+
+/**
+ * Helper related to dlogutil command.
+ * @author Taeyoung Son {@literal <taeyoung2.son@samsung.com>} (S-Core)
+ */
+public class DlogUtil {
+
+    /**
+     * Get dlogutil's information list. It will parse <code>lines</code> using dlogutil's format.<p>
+     * format's context is like this:<br>
+     * <pre>
+     * brief - level/tag( pid): message
+     * process - level( pid) message (tag)
+     * tag - level/tag: message
+     * thread - level(pid: tid) message
+     * raw - message
+     * time - time level/tag( pid): message
+     * threadtime - time pid tid level tag: message
+     * </pre>
+     * 
+     * @param format dlogutil's format
+     * @param logs logs about dlogutil
+     * @return
+     */
+    public static DlogInfo[] getDlogInfos(DlogFormat format, String[] logs) {
+
+        IDlogParser parser = DlogParserFactory.getParser(format);
+
+        if (parser == null) {
+            return null;
+        }
+
+        DlogInfo[] infos = parser.parse(logs);
+        return infos;
+    }
+}
+
index ed31576..da6a385 100644 (file)
@@ -34,6 +34,8 @@ import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * StringUtil
@@ -151,6 +153,21 @@ public class StringUtil
         return new ByteArrayInputStream( src.getBytes() );
     }
 
+    public static String[] split(String str, Pattern pattern) {
+        List<String> result = null;
+
+        // check if the line is header line.
+        Matcher matcher = pattern.matcher(str);
+        if (matcher.matches()) {
+            result = new ArrayList<String>();
+            for (int i=0; i<matcher.groupCount(); i++) {
+                result.add(matcher.group(i+1));
+            }
+        }
+
+        return (result==null) ? null : result.toArray(new String[0]);
+    }
+
     /**
      * Split <code>str</code> with <code>delimiters</code>
      * 
index 32f44e2..fea64b8 100755 (executable)
@@ -33,6 +33,8 @@ import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -1242,4 +1244,19 @@ public class StringUtil
 
         return distance[str1.length()][str2.length()];
     }
+
+    public static String[] split(String str, Pattern pattern) {
+        List<String> result = null;
+
+        // check if the line is header line.
+        Matcher matcher = pattern.matcher(str);
+        if (matcher.matches()) {
+            result = new ArrayList<String>();
+            for (int i=0; i<matcher.groupCount(); i++) {
+                result.add(matcher.group(i+1));
+            }
+        }
+
+        return (result==null) ? null : result.toArray(new String[0]);
+    }
 }