[hg] cnd-main: [remote] file read statistics: added actions to r...

  • From: Vladimir Kvashin < >
  • To: ,
  • Subject: [hg] cnd-main: [remote] file read statistics: added actions to r...
  • Date: Mon, 21 Jan 2013 07:19:46 -0800

changeset 99d2a1aff556 in cnd-main ((none))
details: http://hg.netbeans.org/cnd-main/rev/99d2a1aff556
description:
        [remote] file read statistics: added actions to report and clear (can 
be enabled via -J-Dremote.host.actions.statistics=true), upgraded 
dependencies to o.n.m.dlight.libs.common

diffstat:

 cnd.api.remote/nbproject/project.xml                                         
      |    2 +-
 cnd.dwarfdiscovery/nbproject/project.xml                                     
      |    2 +-
 cnd.makeproject/nbproject/project.xml                                        
      |    2 +-
 cnd.modelimpl/nbproject/project.xml                                          
      |    2 +-
 cnd.remote.projectui/nbproject/project.xml                                   
      |    2 +-
 cnd.remote/nbproject/project.xml                                             
      |    8 +
 cnd.remote/src/org/netbeans/modules/remote/ui/Bundle.properties              
      |    4 +-
 cnd.remote/src/org/netbeans/modules/remote/ui/StatisticsActions.java         
      |  112 ++++++++++
 cnd.utils/nbproject/project.xml                                              
      |    2 +-
 dlight.libs.common/nbproject/project.properties                              
      |    2 +-
 dlight.libs.common/nbproject/project.xml                                     
      |    1 +
 
dlight.libs.common/src/org/netbeans/modules/dlight/libs/common/FileStatistics.java
 |   58 +++-
 dlight.remote.impl/nbproject/project.xml                                     
      |    2 +-
 
dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObject.java
   |    2 +-
 dlight.remote/nbproject/project.xml                                          
      |    2 +-
 15 files changed, 170 insertions(+), 33 deletions(-)

diffs (428 lines):

diff --git a/cnd.api.remote/nbproject/project.xml 
b/cnd.api.remote/nbproject/project.xml
--- a/cnd.api.remote/nbproject/project.xml
+++ b/cnd.api.remote/nbproject/project.xml
@@ -18,7 +18,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.8</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/cnd.dwarfdiscovery/nbproject/project.xml 
b/cnd.dwarfdiscovery/nbproject/project.xml
--- a/cnd.dwarfdiscovery/nbproject/project.xml
+++ b/cnd.dwarfdiscovery/nbproject/project.xml
@@ -77,7 +77,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.13</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/cnd.makeproject/nbproject/project.xml 
b/cnd.makeproject/nbproject/project.xml
--- a/cnd.makeproject/nbproject/project.xml
+++ b/cnd.makeproject/nbproject/project.xml
@@ -88,7 +88,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.8</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/cnd.modelimpl/nbproject/project.xml 
b/cnd.modelimpl/nbproject/project.xml
--- a/cnd.modelimpl/nbproject/project.xml
+++ b/cnd.modelimpl/nbproject/project.xml
@@ -122,7 +122,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.7</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/cnd.remote.projectui/nbproject/project.xml 
b/cnd.remote.projectui/nbproject/project.xml
--- a/cnd.remote.projectui/nbproject/project.xml
+++ b/cnd.remote.projectui/nbproject/project.xml
@@ -113,7 +113,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        
<specification-version>1.9.1.1</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/cnd.remote/nbproject/project.xml 
b/cnd.remote/nbproject/project.xml
--- a/cnd.remote/nbproject/project.xml
+++ b/cnd.remote/nbproject/project.xml
@@ -94,6 +94,14 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    
<code-name-base>org.netbeans.modules.dlight.libs.common</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>1.19</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     
<code-name-base>org.netbeans.modules.dlight.nativeexecution</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
diff --git a/cnd.remote/src/org/netbeans/modules/remote/ui/Bundle.properties 
b/cnd.remote/src/org/netbeans/modules/remote/ui/Bundle.properties
--- a/cnd.remote/src/org/netbeans/modules/remote/ui/Bundle.properties
+++ b/cnd.remote/src/org/netbeans/modules/remote/ui/Bundle.properties
@@ -50,4 +50,6 @@
 RefreshMenuItem=&Schedule file system refresh
 StatisticsMenuItem=Start Statistics
 RefreshScheduled=File system refresh on {0} is scheduled
-AddToFavoritesAction.AddOther.DoNotInvoke.getRoot.directly=Do not invoke 
getRoot() directly
\ No newline at end of file
+AddToFavoritesAction.AddOther.DoNotInvoke.getRoot.directly=Do not invoke 
getRoot() directly
+ClearStatisticsAction=Clear File Read Statistics
+ReportStatisticsAction=Report File Read Statistics
diff --git 
a/cnd.remote/src/org/netbeans/modules/remote/ui/StatisticsActions.java 
b/cnd.remote/src/org/netbeans/modules/remote/ui/StatisticsActions.java
new file mode 100644
--- /dev/null
+++ b/cnd.remote/src/org/netbeans/modules/remote/ui/StatisticsActions.java
@@ -0,0 +1,112 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.remote.ui;
+
+import org.netbeans.modules.dlight.libs.common.FileStatistics;
+import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
+import org.netbeans.modules.remote.spi.FileSystemProvider;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.nodes.Node;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author vkvashin
+ */
+public class StatisticsActions {
+
+    @ActionID(id = "org.netbeans.modules.remote.ui.ClearStatisticsAction", 
category = "NativeRemote")
+    @ActionRegistration(displayName = "ClearStatisticsAction")
+    @ActionReference(path = "Remote/Host/Actions", name = 
"ClearStatisticsAction", position = 99998)
+    public static class ClearStatisticsAction extends SingleHostAction {
+
+        @Override
+        public String getName() {
+            return NbBundle.getMessage(HostListRootNode.class, 
"ClearStatisticsAction");
+        }
+
+        @Override
+        protected boolean enable(ExecutionEnvironment env) {
+            return true;
+        }
+
+        @Override
+        public boolean isVisible(Node node) {
+            return Boolean.getBoolean("remote.host.actions.statistics");
+        }
+
+        @Override
+        protected void performAction(final ExecutionEnvironment env, Node 
node) {
+            
FileStatistics.getInstance(FileSystemProvider.getFileSystem(env)).clear();
+        }
+    }
+    
+    @ActionID(id = "org.netbeans.modules.remote.ui.ReportStatisticsAction", 
category = "NativeRemote")
+    @ActionRegistration(displayName = "ReportStatisticsAction")
+    @ActionReference(path = "Remote/Host/Actions", name = 
"ReportStatisticsAction", position = 99997)
+    public static class ReportStatisticsAction extends SingleHostAction {
+
+        @Override
+        public String getName() {
+            return NbBundle.getMessage(HostListRootNode.class, 
"ReportStatisticsAction");
+        }
+
+        @Override
+        protected boolean enable(ExecutionEnvironment env) {
+            return true;
+        }
+
+        @Override
+        public boolean isVisible(Node node) {
+            return Boolean.getBoolean("remote.host.actions.statistics");
+        }
+
+        @Override
+        protected void performAction(final ExecutionEnvironment env, Node 
node) {
+            
FileStatistics.getInstance(FileSystemProvider.getFileSystem(env)).report();
+        }
+    }
+    
+    
+}
diff --git a/cnd.utils/nbproject/project.xml b/cnd.utils/nbproject/project.xml
--- a/cnd.utils/nbproject/project.xml
+++ b/cnd.utils/nbproject/project.xml
@@ -10,7 +10,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.7</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/dlight.libs.common/nbproject/project.properties 
b/dlight.libs.common/nbproject/project.properties
--- a/dlight.libs.common/nbproject/project.properties
+++ b/dlight.libs.common/nbproject/project.properties
@@ -1,6 +1,6 @@
 is.autoload=true
 javac.source=1.6
 javac.compilerargs=-Xlint -Xlint:-serial
-spec.version.base=1.18.0
+spec.version.base=1.19.0
 
 test.config.stableBTD.includes=**/*Test.class
diff --git a/dlight.libs.common/nbproject/project.xml 
b/dlight.libs.common/nbproject/project.xml
--- a/dlight.libs.common/nbproject/project.xml
+++ b/dlight.libs.common/nbproject/project.xml
@@ -62,6 +62,7 @@
                 <friend>org.netbeans.modules.cnd.dwarfdiscovery</friend>
                 <friend>org.netbeans.modules.cnd.makeproject</friend>
                 <friend>org.netbeans.modules.cnd.modelimpl</friend>
+                <friend>org.netbeans.modules.cnd.remote</friend>
                 <friend>org.netbeans.modules.cnd.remote.projectui</friend>
                 <friend>org.netbeans.modules.cnd.utils</friend>
                 <friend>org.netbeans.modules.dlight.nativeexecution</friend>
diff --git 
a/dlight.libs.common/src/org/netbeans/modules/dlight/libs/common/FileStatistics.java
 
b/dlight.libs.common/src/org/netbeans/modules/dlight/libs/common/FileStatistics.java
--- 
a/dlight.libs.common/src/org/netbeans/modules/dlight/libs/common/FileStatistics.java
+++ 
b/dlight.libs.common/src/org/netbeans/modules/dlight/libs/common/FileStatistics.java
@@ -51,6 +51,8 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import org.openide.filesystems.FileSystem;
 import org.openide.modules.OnStop;
 
 /**
@@ -59,7 +61,8 @@
  */
 public class FileStatistics {
     
-    private static final FileStatistics INSTANCE = new FileStatistics();
+    private static final ConcurrentHashMap<FileSystem, FileStatistics> 
instances = new ConcurrentHashMap<FileSystem, FileStatistics>();
+    
     private static final boolean REPORT_FIRST = 
Boolean.getBoolean("dlight.file.read.statistics.report.first"); //NOI18N
     private static final String PREFIX = "### FRS "; //NOI18N
     
@@ -83,16 +86,26 @@
     
     private final PrintStream out = System.err;
 
+    private final FileSystem fileSystem;
+    
     private final Map<String, StatEntry> stacks = new HashMap<String, 
StatEntry>();
     private final Map<String, StatEntry> files = new HashMap<String, 
StatEntry>();
     private final Object lock = new Object();
     
-    public static FileStatistics getInstance() {
-        return INSTANCE;
+    public static FileStatistics getInstance(FileSystem fs) {
+        FileStatistics instance = instances.get(fs);
+        if (instance == null) {
+            instance = new FileStatistics(fs);
+            FileStatistics oldInstance = instances.putIfAbsent(fs, instance);
+            if (oldInstance != null) {
+                instance = oldInstance;
+            }
+        }
+        return instance;
     }
 
-    private FileStatistics() {
-
+    private FileStatistics(FileSystem fileSystem) {
+        this.fileSystem = fileSystem;
     }
 
     private List<StackTraceElement> filter(StackTraceElement[] stack) {
@@ -138,6 +151,13 @@
         return result;        
     }
         
+    public void clear() {
+        synchronized (lock) {
+            files.clear();
+            stacks.clear();
+        }
+    }
+
     public void logPath(String path) {
         
         String fileName = PathUtilities.getBaseName(path);
@@ -162,19 +182,14 @@
         }
         String stackKey = sb.toString();
         
-        StatEntry pathEntry;        
-        synchronized (lock) {
+        StatEntry pathEntry, stackEntry;        
+        boolean report = false;
+        synchronized (lock) {            
             pathEntry = files.get(path);
             if (pathEntry == null) {
                 pathEntry = new StatEntry(path, stackKey);                
                 files.put(path, pathEntry);
             }            
-        }
-        pathEntry.increment();
-
-        StatEntry stackEntry;
-        boolean report = false;
-        synchronized (lock) {            
             stackEntry = stacks.get(stackKey);
             if (stackEntry == null) {
                 stackEntry = new StatEntry(path, stackKey);
@@ -184,6 +199,7 @@
                 }
             }            
         }
+        pathEntry.increment();        
         stackEntry.increment();
         if (report) {
             report(stackEntry);
@@ -192,14 +208,10 @@
     }
         
     private void printf(String pattern, Object... args) {
-        printf("", pattern, args);
-    }
-
-    private void printf(String indent, String pattern, Object... args) {
         String formattedString = String.format(pattern, args);
         String[] lines = formattedString.split("\n"); // NOI18N
         for (int i = 0; i < lines.length; i++) {
-            out.printf("%s%s%s\n", PREFIX,  indent, lines[i]); // NOI18N
+            out.printf("%s%s\n", PREFIX,  lines[i]); // NOI18N
         }
         out.flush();
     }
@@ -208,14 +220,16 @@
     public static class Reporter implements Runnable {
         @Override
         public void run() {
-            FileStatistics.getInstance().report();
+            for (FileStatistics fileStatistics : instances.values()) {
+                fileStatistics.report();
+            }
         }        
     }
     
     private void report(StatEntry entry) {
         String stack = entry.getStack();
         printf("%6d @%d  1-st path: %s\n", entry.getCount(), 
stack.hashCode(), entry.getPath()); // NOI18N
-        printf("        ", "%s\n", stack); // NOI18N        
+        printf("    %s\n", stack); // NOI18N        
     }
     
     public void report() {
@@ -225,7 +239,7 @@
         }
         {
             out.printf("\n\n\n"); // NOI18N
-            printf("\nFile Read Statistics by Path\n"); // NOI18N
+            printf("\nFile Read Statistics by Path [%s]\n", 
fileSystem.getDisplayName()); // NOI18N
             printf("Files count: %d reads count: %d\n", files.size(), 
readCount); // NOI18N
             printf("\t   Cnt  File\n"); // NOI18N
             for (Map.Entry<String, StatEntry> mapEntry : sortByCount(files)) 
{
@@ -236,7 +250,7 @@
         }
 
         {
-            printf("\n\nFile Read Statistics by Stack\n"); // NOI18N
+            printf("\n\nFile Read Statistics by Stack [%s]\n", 
fileSystem.getDisplayName()); // NOI18N
             printf("Stacks count: %d reads count: %d\n", stacks.size(), 
readCount); // NOI18N
             for (Map.Entry<String, StatEntry> mapEntry : 
sortByCount(stacks)) {
                 StatEntry statEntry = mapEntry.getValue();
diff --git a/dlight.remote.impl/nbproject/project.xml 
b/dlight.remote.impl/nbproject/project.xml
--- a/dlight.remote.impl/nbproject/project.xml
+++ b/dlight.remote.impl/nbproject/project.xml
@@ -28,7 +28,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.18</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git 
a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObject.java
 
b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObject.java
--- 
a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObject.java
+++ 
b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObject.java
@@ -391,7 +391,7 @@
 
     @Override
     public InputStream getInputStream() throws FileNotFoundException {
-        FileStatistics.getInstance().logPath(getPath());
+        FileStatistics.getInstance(fileSystem).logPath(getPath());
         if (!getImplementor().hasCache()) {
             if (isMimeResolving()) {
                 byte[] b = getImplementor().getMagic();
diff --git a/dlight.remote/nbproject/project.xml 
b/dlight.remote/nbproject/project.xml
--- a/dlight.remote/nbproject/project.xml
+++ b/dlight.remote/nbproject/project.xml
@@ -19,7 +19,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.7</specification-version>
+                        <specification-version>1.19</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>

[hg] cnd-main: [remote] file read statistics: added actions to r...

Vladimir Kvashin 01/21/2013

Project Features

About this Project

CND was started in November 2009, is owned by DimaZh, and has 130 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close