Source

nbandroid_patches / logcat_pname.patch

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# HG changeset patch
# Date 1307106891 -7200
# Parent 805c39e18401dcdd307127c74cee89b7fb08a87f
LogCat: added process names to log entries

diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/Bundle.properties
--- a/logcat/src/org/nyerel/nbandroid/logcat/Bundle.properties	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/Bundle.properties	Sun Jun 26 16:04:08 2011 +0200
@@ -18,7 +18,7 @@
 LogFilterDialog.title=Log Filter
 LogFilterDialog.jLabel1.text=Filter Name:
 LogFilterDialog.jLabel2.text=by Log Tag:
-LogFilterDialog.jLabel3.text=by pid:
+LogFilterDialog.jLabel3.text=by Process:
 LogFilterDialog.jLabel4.text=by Log level:
 LogFilterDialog.txtFilterName.text=
 LogFilterDialog.txtLogTag.text=
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/LogEvent.java	Sun Jun 26 16:04:08 2011 +0200
@@ -45,6 +45,14 @@
         return info.getPid();
     }
 
+    public String getProcessName() {
+        return info.getProcessName();
+    }
+
+    public String[] getProcessNameRef() {
+        return info.getProcessNameRef();
+    }
+
     public LogLevel getLevel() {
         return info.getLevel();
     }
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/LogEventInfo.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/LogEventInfo.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/LogEventInfo.java	Sun Jun 26 16:04:08 2011 +0200
@@ -22,6 +22,7 @@
 public class LogEventInfo {
 
     private final int pid;
+    private final String[] pNameRef;
     private final String time;
     private final String tag;
     private final LogLevel level;
@@ -34,6 +35,18 @@
         return pid;
     }
 
+    public String getProcessName() {
+        if (pNameRef[0] != null) {
+            return pNameRef[0];
+        }
+        
+        return '#' + Integer.toString(pid);
+    }
+    
+    public String[] getProcessNameRef() {
+        return pNameRef;
+    }
+
     public String getTag() {
         return tag;
     }
@@ -42,8 +55,9 @@
         return time;
     }
 
-    public LogEventInfo(int pid, String time, String tag, LogLevel level) {
+    public LogEventInfo(int pid, String[] pNameRef, String time, String tag, LogLevel level) {
         this.pid = pid;
+        this.pNameRef = pNameRef;
         this.time = time;
         this.tag = tag;
         this.level = level;
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/LogFilterDialog.form
--- a/logcat/src/org/nyerel/nbandroid/logcat/LogFilterDialog.form	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/LogFilterDialog.form	Sun Jun 26 16:04:08 2011 +0200
@@ -34,12 +34,12 @@
                   <Group type="102" attributes="0">
                       <EmptySpace max="-2" attributes="0"/>
                       <Group type="103" groupAlignment="0" attributes="0">
-                          <Component id="jSeparator2" alignment="0" pref="409" max="32767" attributes="0"/>
-                          <Component id="jSeparator1" alignment="0" pref="409" max="32767" attributes="0"/>
+                          <Component id="jSeparator2" alignment="0" pref="417" max="32767" attributes="0"/>
+                          <Component id="jSeparator1" alignment="0" pref="417" max="32767" attributes="0"/>
                           <Group type="102" alignment="0" attributes="0">
                               <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
                               <EmptySpace max="-2" attributes="0"/>
-                              <Component id="txtFilterName" pref="347" max="32767" attributes="0"/>
+                              <Component id="txtFilterName" pref="344" max="32767" attributes="0"/>
                           </Group>
                           <Group type="102" alignment="0" attributes="0">
                               <Group type="103" groupAlignment="1" max="-2" attributes="0">
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/LogFilterDialog.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/LogFilterDialog.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/LogFilterDialog.java	Sun Jun 26 16:04:08 2011 +0200
@@ -129,12 +129,12 @@
                     .addGroup(layout.createSequentialGroup()
                         .addContainerGap()
                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-                            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
-                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
+                            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
+                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
                             .addGroup(layout.createSequentialGroup()
                                 .addComponent(jLabel1)
                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                                .addComponent(txtFilterName, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE))
+                                .addComponent(txtFilterName, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE))
                             .addGroup(layout.createSequentialGroup()
                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                     .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/LogReader.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/LogReader.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/LogReader.java	Sun Jun 26 16:04:08 2011 +0200
@@ -15,13 +15,17 @@
 
 import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.AndroidDebugBridge;
+import com.android.ddmlib.Client;
+import com.android.ddmlib.ClientData;
 import com.android.ddmlib.IDevice;
 import com.android.ddmlib.Log.LogLevel;
 import com.android.ddmlib.MultiLineReceiver;
 import com.android.ddmlib.ShellCommandUnresponsiveException;
 import com.android.ddmlib.TimeoutException;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -64,6 +68,10 @@
     
     private String lastDeviceSN;
     private Set<LogEvent> loggedEvents;
+    
+    private Map<IDevice,Map<Integer, String[]>> processNameCache
+            = new HashMap<IDevice, Map<Integer, String[]>>();
+
 
     public LogReader() {
         
@@ -130,13 +138,13 @@
     }
 
     private void errorMessage(String message) {
-        LogEventInfo i = new LogEventInfo(0, "", "", LogLevel.ERROR);
+        LogEventInfo i = new LogEventInfo(0, new String[]{""}, "", "", LogLevel.ERROR);
         LogEvent e = new LogEvent(i, message);
         sendNewLogEvent(e);
     }
 
     private void infoMessage(String message) {
-        LogEventInfo i = new LogEventInfo(0, "", "", LogLevel.INFO);
+        LogEventInfo i = new LogEventInfo(0, new String[]{""}, "", "", LogLevel.INFO);
         LogEvent e = new LogEvent(i, message);
         sendNewLogEvent(e);
     }
@@ -246,6 +254,7 @@
             if (line.length() > 0) {
                 String time;
                 int pid;
+                String[] process;
                 LogLevel level;
                 String tag;
                 Matcher matcher = sLogPattern.matcher(line);
@@ -253,9 +262,10 @@
                     // this is a header line, parse the header and keep it around.
                     time = matcher.group(1);
                     pid = Integer.valueOf(matcher.group(2));
+                    process = getProcessName(device, pid);
                     level = LogLevel.getByLetterString(matcher.group(4));
                     tag = matcher.group(5).trim();
-                    lastLogEventInfo = new LogEventInfo(pid, time, tag, level);
+                    lastLogEventInfo = new LogEventInfo(pid, process, time, tag, level);
                 } else {
                     if (lastLogEventInfo == null) {
                         // The first line of output wasn't preceded
@@ -263,9 +273,10 @@
                         // that users of mc.data don't NPE.
                         time = "??-?? ??:??:??.???"; //$NON-NLS1$
                         pid = 0;
+                        process = new String[]{""};
                         level = LogLevel.INFO;
                         tag = "<unknown>"; //$NON-NLS1$
-                        lastLogEventInfo = new LogEventInfo(pid, time, tag, level);
+                        lastLogEventInfo = new LogEventInfo(pid, process, time, tag, level);
                     }
                     // tabs seem to display as only 1 tab so we replace the leading tabs
                     // by 4 spaces.
@@ -283,6 +294,42 @@
             }
         }
     }
+
+
+    /**
+     * Get a reference to the name of the process with the given ID.
+     * The reference may contain a null-object, couldn't be retrieved,
+     * but may be available later.
+     * @param device Device, where the process runs.
+     * @param pid    ID of the process.
+     * @return       A reference to a string containing the process name
+     *               or {@code null}, if the process couldn't be retrieved yet.
+     */
+    private String[] getProcessName(IDevice device, int pid) {
+        Map<Integer, String[]> cache = processNameCache.get(device);
+        if (cache == null) {
+            cache = new HashMap<Integer,String[]>();
+            processNameCache.put(device, cache);
+        }
+
+        String[] nameref = cache.get(pid);
+        if (nameref == null) {
+            nameref = new String[1];
+            cache.put(pid, nameref);
+        }
+        
+        if (nameref[0] == null) {
+            for(Client client : device.getClients()) {
+                ClientData data = client.getClientData();
+
+                if (data != null && data.getPid() == pid) {
+                    nameref[0] = data.getClientDescription();
+                }
+            }
+        }
+
+        return nameref;
+    }
     
     
    /**
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/logtable/Bundle.properties
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logcat/src/org/nyerel/nbandroid/logcat/logtable/Bundle.properties	Sun Jun 26 16:04:08 2011 +0200
@@ -0,0 +1,6 @@
+LogCatColumn.time=Time
+LogCatColumn.pid=PID
+LogCatColumn.pname=Process
+LogCatColumn.tag=Tag
+LogCatColumn.level=Level
+LogCatColumn.message=Message
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/logtable/LogFilter.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/logtable/LogFilter.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/logtable/LogFilter.java	Sun Jun 26 16:04:08 2011 +0200
@@ -23,19 +23,29 @@
     
     private final String name;
     private final String filterTag;
+    private final String filterProcess;
     private final int filterPid;
     private final LogLevel filterLevel;
 
 
-    public LogFilter(String name, String filterTag, String filterPid, LogLevel filterLevel) {
+    public LogFilter(String name, String filterTag, String filterProcess, LogLevel filterLevel) {
         this.name = name;
         this.filterTag = filterTag;
         this.filterLevel = filterLevel;
+        this.filterProcess = filterProcess;
         
-        if(filterPid == null) {
+        if(filterProcess == null) {
             this.filterPid = -1;
         } else {
-            this.filterPid = Integer.parseInt(filterPid);
+            int pid = -1;
+            
+            try {
+                pid = Integer.parseInt(filterProcess);
+            }
+            catch(NumberFormatException e) {
+            }
+            
+            this.filterPid = pid;
         }
     }
     
@@ -48,6 +58,10 @@
             ok &= filterTag.equals(event.getTag());
         }
         
+        if (filterProcess != null) {
+            ok &= filterProcess.equals(event.getProcessName());
+        }
+        
         if(filterPid != -1) {
             ok &= (filterPid == event.getPid());
         }
@@ -62,6 +76,10 @@
     public LogLevel getFilterLevel() {
         return filterLevel;
     }
+    
+    public String getFilterProcess() {
+        return filterProcess;
+    }
 
     public int getFilterPid() {
         return filterPid;
@@ -77,6 +95,6 @@
 
     @Override
     public String toString() {
-        return "[LogFilter name=" + name + " tag=" + filterTag + " pid=" + filterPid + " level=" + filterLevel + "]";
+        return "[LogFilter name=" + name + " tag=" + filterTag + " process=" + filterProcess + " pid=" + filterPid + " level=" + filterLevel + "]";
     }
 }
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/logtable/LogTableManager.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/logtable/LogTableManager.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/logtable/LogTableManager.java	Sun Jun 26 16:04:08 2011 +0200
@@ -44,24 +44,29 @@
     private void initTable() {
         TableColumn tagColumn = columnModel.getColumn(LogTableModel.COL_TAG);
         TableColumn pidColumn = columnModel.getColumn(LogTableModel.COL_PID);
+        TableColumn pNameColumn = columnModel.getColumn(LogTableModel.COL_PROCESS);
         TableColumn timeColumn = columnModel.getColumn(LogTableModel.COL_TIME);
         TableColumn levelColumn = columnModel.getColumn(LogTableModel.COL_LEVEL);
 
         tagColumn.setMinWidth(50);
-        tagColumn.setPreferredWidth(120);
+        tagColumn.setPreferredWidth(150);
         tagColumn.setMaxWidth(300);
 
         pidColumn.setMinWidth(35);
-        pidColumn.setPreferredWidth(35);
-        pidColumn.setMaxWidth(35);
+        pidColumn.setPreferredWidth(50);
+        pidColumn.setMaxWidth(70);
+
+        pNameColumn.setMinWidth(60);
+        pNameColumn.setPreferredWidth(80);
+        pNameColumn.setMaxWidth(300);
 
         timeColumn.setMinWidth(60);
-        timeColumn.setPreferredWidth(75);
+        timeColumn.setPreferredWidth(80);
         timeColumn.setMaxWidth(90);
 
         levelColumn.setMinWidth(20);
-        levelColumn.setPreferredWidth(40);
-        levelColumn.setMaxWidth(50);
+        levelColumn.setPreferredWidth(80);
+        levelColumn.setMaxWidth(80);
 
     }
 
diff -r 805c39e18401 logcat/src/org/nyerel/nbandroid/logcat/logtable/LogTableModel.java
--- a/logcat/src/org/nyerel/nbandroid/logcat/logtable/LogTableModel.java	Sun Jun 19 19:34:54 2011 +0200
+++ b/logcat/src/org/nyerel/nbandroid/logcat/logtable/LogTableModel.java	Sun Jun 26 16:04:08 2011 +0200
@@ -19,6 +19,7 @@
 import java.util.Calendar;
 import java.util.List;
 import javax.swing.table.AbstractTableModel;
+import org.openide.util.NbBundle;
 
 /**
  *
@@ -28,14 +29,16 @@
 
     public static final int COL_TIME = 0;
     public static final int COL_PID = 1;
-    public static final int COL_LEVEL = 2;
-    public static final int COL_TAG = 3;
-    public static final int COL_MESSAGE = 4;
-    public static final String COL_TIME_NAME = "Time";
+    public static final int COL_PROCESS = 2;
+    public static final int COL_LEVEL = 3;
+    public static final int COL_TAG = 4;
+    public static final int COL_MESSAGE = 5;
+    public static final String COL_TIME_NAME = "time";
     public static final String COL_PID_NAME = "pid";
+    public static final String COL_PROCESS_NAME = "pname";
     public static final String COL_LEVEL_NAME = "level";
     public static final String COL_TAG_NAME = "tag";
-    public static final String COL_MESSAGE_NAME = "Message";
+    public static final String COL_MESSAGE_NAME = "message";
     
     private List<LogEvent> data;
     private LogFilter filter;
@@ -62,6 +65,8 @@
                 return String.class;
             case COL_PID:
                 return Integer.class;
+            case COL_PROCESS:
+                return String.class;
             case COL_TIME:
                 return String.class; // TODO(radim): how to sort this properly
             case COL_TAG:
@@ -76,15 +81,17 @@
     public String getColumnName(int column) {
         switch (column) {
             case COL_TIME:
-                return COL_TIME_NAME;
+                return NbBundle.getMessage(getClass(), "LogCatColumn." + COL_TIME_NAME);
             case COL_PID:
-                return COL_PID_NAME;
+                return NbBundle.getMessage(getClass(), "LogCatColumn." + COL_PID_NAME);
+            case COL_PROCESS:
+                return NbBundle.getMessage(getClass(), "LogCatColumn." + COL_PROCESS_NAME);
             case COL_MESSAGE:
-                return COL_MESSAGE_NAME;
+                return NbBundle.getMessage(getClass(), "LogCatColumn." + COL_MESSAGE_NAME);
             case COL_TAG:
-                return COL_TAG_NAME;
+                return NbBundle.getMessage(getClass(), "LogCatColumn." + COL_TAG_NAME);
             case COL_LEVEL:
-                return COL_LEVEL_NAME;
+                return NbBundle.getMessage(getClass(), "LogCatColumn." + COL_LEVEL_NAME);
         }
         throw new IllegalArgumentException("This column does not exist: " + column);
     }
@@ -96,7 +103,7 @@
 
     @Override
     public int getColumnCount() {
-        return 5;
+        return 6;
     }
 
     public LogEvent getValueAt(int rowIndex) {
@@ -116,6 +123,8 @@
                 return e.getMessage();
             case COL_PID:
                 return e.getPid();
+            case COL_PROCESS:
+                return e.getProcessName();
             case COL_TIME:
                 return e.getTime();
             case COL_TAG:
@@ -140,7 +149,7 @@
     }
 
     public void showError(String errorMessage) {
-        LogEventInfo info = new LogEventInfo(0, "LogCat Error", "-----", LogLevel.ERROR);
+        LogEventInfo info = new LogEventInfo(0, new String[]{""}, "LogCat Error", "-----", LogLevel.ERROR);
         LogEvent event = new LogEvent(info, errorMessage);
         addNewEvent(event);
     }
@@ -163,7 +172,7 @@
 
         String time = h+":" + m + ":" + s + "." + ms;
         return new LogEvent(
-            new LogEventInfo(event.getPid(), time, event.getTag(), event.getLevel()),
+            new LogEventInfo(event.getPid(), event.getProcessNameRef(), time, event.getTag(), event.getLevel()),
             event.getMessage());
     }