MISC : apply the improvements of the on-demand installation feature of valgrind 75/25375/1
authorseokgil.kang <seokgil.kang@samsung.com>
Mon, 4 Aug 2014 11:58:02 +0000 (20:58 +0900)
committerseokgil.kang <seokgil.kang@samsung.com>
Mon, 4 Aug 2014 11:58:02 +0000 (20:58 +0900)
Change-Id: I0ee85255bcb5402c2b78ff4b3ee380926001f9c1
Signed-off-by: seokgil.kang <seokgil.kang@samsung.com>
org.eclipse.linuxtools.valgrind.launch.exe/src/org/eclipse/linuxtools/valgrind/launch/CommandManager.java
org.eclipse.linuxtools.valgrind.launch.exe/src/org/eclipse/linuxtools/valgrind/launch/TizenValgrindLaunchDelegate.java
org.eclipse.linuxtools.valgrind.launch.exe/src/org/eclipse/linuxtools/valgrind/launch/ValgrindRuntimeProcess.java
org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/valgrind/launch/messages.properties

index 34fb614..2b48b82 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.linuxtools.profiling.launch.Messages;
 import org.eclipse.linuxtools.profiling.launch.ProfileLaunchPlugin;
+import org.tizen.common.TizenPlatformConstants;
 import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.exception.SdbCommandRejectedException;
@@ -226,10 +227,10 @@ public class CommandManager {
                } catch (IOException e) {
                        e.printStackTrace();
                }
-               FileInputStream fileIn = null;
-               try
-               {
-                       fileIn = new FileInputStream( src );
+//             FileInputStream fileIn = null;
+//             try
+//             {
+//                     fileIn = new FileInputStream( src );
                        if (syncService == null) {
                                MessageDialog
                                .openError(
@@ -237,17 +238,18 @@ public class CommandManager {
                                                Messages.getString("ProfileLaunchShortcut.Valgrind_Launcher"), "SyncService is null"); //$NON-NLS-1$
                                return false;
                        }
-                       SyncResult result = syncService.doPush( fileIn, device.getFileEntry( dest ), null, -1 );
+//                     SyncResult result = syncService.doPush( fileIn, device.getFileEntry( dest ), null, -1 );
+                       SyncResult result = syncService.push(src, device.getFileEntry(dest));
                        return result.isOk();
-               }
-               catch ( final FileNotFoundException e )
-        {
-                       return false;
-        }
-               finally
-               {
-                       tryClose( fileIn );
-               }
+//             }
+//             catch ( final FileNotFoundException e )
+//        {
+//                     return false;
+//        }
+//             finally
+//             {
+//                     tryClose( fileIn );
+//             }
        }
 
        public static boolean isPathExist(String path) {
@@ -276,4 +278,10 @@ public class CommandManager {
                
                return false;
        }
+       
+       public static boolean isExist(String fullPath) {
+               String cmd = "ls " + fullPath + TizenPlatformConstants.CMD_SUFFIX;
+               String[] resultRsp = CommandManager.runCommandReturningResult(cmd);
+               return isRunSuccessfuly(resultRsp);
+       }
 }
index 1dd8621..a589790 100644 (file)
@@ -50,6 +50,8 @@ import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.window.Window;
@@ -58,6 +60,7 @@ import org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut;
 import org.eclipse.linuxtools.valgrind.core.ValgrindCommand;
 import org.eclipse.linuxtools.valgrind.core.utils.LaunchConfigurationConstants;
 import org.eclipse.linuxtools.valgrind.ui.ValgrindUIPlugin;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.MessageBox;
@@ -68,7 +71,11 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.TwoPaneElementSelector;
 import org.tizen.common.TizenPlatformConstants;
 import org.tizen.common.TizenProjectType;
+import org.tizen.common.connection.debugtools.OnDemandInstallMessages;
+import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.common.util.RootJob;
 import org.tizen.common.util.SWTUtil;
+import org.tizen.common.util.SdbCommandUtil;
 import org.tizen.common.util.log.UserInteraction;
 import org.tizen.common.util.log.UserLogger;
 import org.tizen.nativecommon.IXMLStore;
@@ -118,7 +125,15 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
        protected static final String LAUNCHPAD_LAUNCHER = "launch_app ";
        protected static final String LAUNCHPAD_SYNCMODE = " __AUL_SDK__ VALGRIND __DLP_VALGRIND_ARG__ ";
        
-       private static final String VALGRIND_ERROR_MESSAGE = "This target does not support profiling with valgrind for low HW specifications.";
+       private static final String LD_FILE_PATH = "/usr/lib/debug/lib/ld-2.13.so.debug";
+       private static final String VALGRIND_EXECUTABLE_PATH = "/valgrind/usr/bin/valgrind";
+       private static final String VALGRIND_BINARY_PATH = "/platforms/common/user-demand";
+       private static final String MOVE_WORKING_DIR_COMMAND = "cd "
+                       + TizenPlatformConstants.TOOLS_TARGET_PATH;
+       private static final String REMOVE_TOOL_COMMAND = "rm -f %s";
+       private static final String TAR_INSTALL_COMMAND = MOVE_WORKING_DIR_COMMAND + " && tar -xf %s"
+                       + " && " + REMOVE_TOOL_COMMAND;
+       private boolean userAnswer = false;
 
        protected String toolID;
        protected int confirmMsg = 0;
@@ -169,6 +184,36 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                                        Messages.getString("ValgrindOptionsTab.nodevice"), null);
                        return;
                }
+               
+               // check for ld-2.13.so.debug file
+               if (!CommandManager.isExist(LD_FILE_PATH)) {
+                       monitor.done();
+                       ProfileLaunchShortcut.showErrorDialog(Messages.getString("ValgrindOptionsTab.cannotrun"),
+                                       Messages.getString("TizenValgrindLaunchDelegate.ld_file_doesnt_exist"), null);
+                       return;
+               }
+               
+               // check for Valgrind executable
+               if (!CommandManager.isExist(TizenPlatformConstants.TOOLS_TARGET_PATH + VALGRIND_EXECUTABLE_PATH)) {
+                       Display.getDefault().syncExec(new Runnable() {
+                               public void run() {
+                                       userAnswer = MessageDialog.openQuestion(null, 
+                                                       Messages.getString("TizenValgrindLaunchDelegate.valgrind_warning"), 
+                                                       Messages.getString("TizenValgrindLaunchDelegate.valgrind_doesnt_exist"));
+                               }
+                       });
+                       
+                       if (!userAnswer) {
+                               monitor.done();
+                               return;
+                       } else {
+                               // install valgrind
+                               if (!installValgrind()) {
+                                       monitor.done();
+                                       return;
+                               }
+                       }
+               }
 
                try {
                        ProfileLaunchPlugin.startProfiling();
@@ -199,7 +244,7 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                                if (mode.equals(ILaunchManager.PROFILE_MODE)) {
                                        launchPlatformApplicationWithValgrind(launch, config, monitor);
                                } else {
-                                       newCoreException(VALGRIND_ERROR_MESSAGE, null);
+                                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), null);
                                }
                        } else {
                                if (ProjectUtil.getTizenProjectType(project) != null) {
@@ -236,7 +281,7 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
 
                                                        launchApplicationWithValgrind(launch, config, monitor);
                                                } else {
-                                                       newCoreException(VALGRIND_ERROR_MESSAGE, null);
+                                                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), null);
                                                }
                                        } else if (ProjectUtil.getTizenProjectType(project).isWebProject()){
                                                /**  web project */
@@ -259,6 +304,99 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                }
        }
        
+       private boolean installValgrind() {
+               // push & unzip (references. OnDemandInstall - deployPackage())
+
+               //  check for valgrind binary
+               File binaryDir = null;
+               String[] binaryFiles = null;
+               String binaryPath = InstallPathConfig.getSDKPath() + VALGRIND_BINARY_PATH;
+               try {
+                       binaryDir = new File(binaryPath);
+                       if (binaryDir.isDirectory()) {
+                               binaryFiles = binaryDir.list();
+                               if (binaryFiles == null || binaryFiles.length != 2) 
+                                       newCoreException(null, null);
+                       } else {
+                               newCoreException(null, null);                   
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       ProfileLaunchShortcut.showErrorDialog(
+                                       Messages.getString("TizenValgrindLaunchDelegate.valgrind_warning"),
+                                       Messages.getString("TizenValgrindLaunchDelegate.valgrind_binary_doesnt_exist"),
+                                       null);
+                       return false;
+               } 
+               
+               String binaryName = null;
+               if (CommandManager.isEmulator()) {
+                       for (String fileName : binaryFiles) {
+                               if (fileName.contains("i386")) {
+                                       binaryName = String.valueOf(fileName);
+                                       break;
+                               }
+                       }
+               } else {
+                       for (String fileName : binaryFiles) {
+                               if (fileName.contains("armel")) {
+                                       binaryName = String.valueOf(fileName);
+                                       break;
+                               }
+                       }
+               }
+               
+               // push valgrind binary file to the target
+               if (!CommandManager.push(binaryPath + File.separator + binaryName,
+                               TizenPlatformConstants.TOOLS_TARGET_PATH)) {
+                       ProfileLaunchShortcut
+                       .showErrorDialog(
+                                       Messages.getString("TizenValgrindLaunchDelegate.valgrind_warning"),
+                                       Messages.getString("TizenValgrindLaunchDelegate.failed_to_valgrind_installation"),
+                                       null);
+                       return false;
+               }
+
+               // unzip & remove valgrin binary file
+               final String unzipCmd = String.format(TAR_INSTALL_COMMAND, binaryName, binaryName
+                               + TizenPlatformConstants.CMD_SUFFIX);
+               
+               class InstallJob implements RootJob {
+                       private boolean isSuccess = false;
+                       @Override
+                       public void run() {
+                               try {
+                                       if (CommandManager.isRunSuccessfuly(CommandManager
+                                                       .runCommandReturningResult(unzipCmd))) {
+                                               isSuccess = true;
+                                       }
+                               } catch (Exception e) {
+                                       e.printStackTrace();
+                                       isSuccess = false;
+                                       return;
+                               }
+                       }
+                       
+                       public boolean isSuccess() {
+                               return isSuccess;
+                       }
+               }
+               
+               InstallJob installJob = new InstallJob();
+               installJob.run();
+        
+               if (installJob.isSuccess()) {
+                       return true;
+               } else {
+                       ProfileLaunchShortcut
+                                       .showErrorDialog(
+                                                       Messages.getString("TizenValgrindLaunchDelegate.valgrind_warning"),
+                                                       Messages.getString("TizenValgrindLaunchDelegate.failed_to_valgrind_installation"),
+                                                       null);
+                       return false;
+               }
+       }
+       
        protected void verifyDeviceReachabilityForPlatform(ILaunchConfiguration config, IProgressMonitor monitor)
             throws CoreException {
         try {
@@ -484,15 +622,6 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                // Process remoteShellProcess = null;
                
                try {
-                       // find Valgrind executable
-                       String valgrindCmd = TizenPlatformConstants.TOOLS_TARGET_PATH + "/valgrind/usr/bin/valgrind";
-                       String cmd = "ls " + valgrindCmd + TizenPlatformConstants.CMD_SUFFIX;
-                       String[] resultRsp = CommandManager.runCommandReturningResult(cmd);
-                       if (!CommandManager.isRunSuccessfuly(resultRsp)) {
-                               newCoreException(VALGRIND_ERROR_MESSAGE,        new Exception(
-                                               "No valgrind in this target (" + TizenPlatformConstants.TOOLS_TARGET_PATH + "/valgrind/usr/bin/valgrind)."));
-                       }
-
                        if (monitor.isCanceled())
                                throw new OperationCanceledException();
 
@@ -509,11 +638,11 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                                        remoteExePath = remoteExePath.substring(0, remoteExePath.length() - BADA_EXT.length());
                                }
                                
-                               cmd = ValgrindCommand.OPROFILE_SCRIPT + " lsapp " + remoteExePath;
-                               resultRsp = CommandManager.runHostCommandReturningResult(cmd);
+                               String cmd = ValgrindCommand.OPROFILE_SCRIPT + " lsapp " + remoteExePath;
+                               String[] resultRsp = CommandManager.runHostCommandReturningResult(cmd);
                                if (!CommandManager.isRunSuccessfuly(resultRsp))
                                {
-                                       newCoreException(VALGRIND_ERROR_MESSAGE,        new Exception(
+                                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"),      new Exception(
                                                        "Executable does not exist on a valid path. You must install your application before running it."));
                                }
                        }
@@ -556,7 +685,7 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                                        fullcommand = LAUNCHPAD_LAUNCHER + getPackageName(config) + "." + getExecutableName(config) + LAUNCHPAD_SYNCMODE;
                                }
                        } catch (CoreException e) {
-                               newCoreException(VALGRIND_ERROR_MESSAGE, e.getCause());
+                               newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e.getCause());
                        }
                        
 //                     for (int i = 0; i < commandArray.length; i++) {
@@ -628,11 +757,11 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                                }
                        });
                } catch (CoreException e) {
-                       newCoreException(VALGRIND_ERROR_MESSAGE, e.getCause());
+                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e.getCause());
                } catch (IOException e) {
-                       newCoreException(VALGRIND_ERROR_MESSAGE, e);
+                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e);
                } catch (Exception e) {
-                       newCoreException(VALGRIND_ERROR_MESSAGE, e);
+                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e);
                } finally {
                        monitor.done();
                        ProfileLaunchPlugin.stopProfiling();
@@ -645,15 +774,6 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                // Process remoteShellProcess = null;
 
                try {
-                       // find Valgrind executable
-                       String valgrindCmd = TizenPlatformConstants.TOOLS_TARGET_PATH + "/valgrind/usr/bin/valgrind";
-                       String cmd = "ls " + valgrindCmd + TizenPlatformConstants.CMD_SUFFIX;
-                       String[] resultRsp = CommandManager.runCommandReturningResult(cmd);
-                       if (!CommandManager.isRunSuccessfuly(resultRsp)) {
-                               newCoreException(VALGRIND_ERROR_MESSAGE,        new Exception(
-                                               "No valgrind in this target (" + TizenPlatformConstants.TOOLS_TARGET_PATH + "/valgrind/usr/bin/valgrind)."));
-                       }
-
                        if (monitor.isCanceled())
                                throw new OperationCanceledException();
 
@@ -762,11 +882,11 @@ public class TizenValgrindLaunchDelegate extends TizenLaunchDelegate {
                                }
                        });
                } catch (CoreException e) {
-                       newCoreException(VALGRIND_ERROR_MESSAGE, e.getCause());
+                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e.getCause());
                } catch (IOException e) {
-                       newCoreException(VALGRIND_ERROR_MESSAGE, e);
+                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e);
                } catch (Exception e) {
-                       newCoreException(VALGRIND_ERROR_MESSAGE, e);
+                       newCoreException(Messages.getString("TizenValgrindLaunchDelegate.valgrind_error_message"), e);
                } finally {
                        monitor.done();
                        ProfileLaunchPlugin.stopProfiling();
index c17d3a6..5330032 100644 (file)
@@ -33,7 +33,6 @@ import org.eclipse.debug.internal.core.StreamsProxy;
 import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.sdblib.exception.SdbCommandRejectedException;
 import org.eclipse.linuxtools.valgrind.core.ValgrindCommand;
-import org.eclipse.linuxtools.valgrind.launch.CommandManager;
 
 /**
  * Standard implementation of an <code>IProcess</code> that wrappers a system
index d4e79b2..ac97ac2 100644 (file)
@@ -1,3 +1,9 @@
+TizenValgrindLaunchDelegate.ld_file_doesnt_exist=The target device does not support the valgrind profiling.
+TizenValgrindLaunchDelegate.failed_to_valgrind_installation=Failed to the Valgrind installation.
+TizenValgrindLaunchDelegate.valgrind_binary_doesnt_exist=The valgrind binary files do not exist.
+TizenValgrindLaunchDelegate.valgrind_doesnt_exist=The IDE will install the valgrind to the target device. The valgrind possesses 7MB of the device's storage.\nThe valgrind can profile your application in stable when the device's available memory size is more than 150MB.\nDo you want to continue installing the valgrind?
+TizenValgrindLaunchDelegate.valgrind_error_message=This target does not support profiling with valgrind for low HW specifications.
+TizenValgrindLaunchDelegate.valgrind_warning=Valgrind warning!!
 ValgrindLaunchConfigurationDelegate.Error_starting_process=Error starting process
 ValgrindLaunchConfigurationDelegate.Profiling_Local_CCPP_Application=Profiling Local C/C++ Application
 ValgrindLaunchConfigurationDelegate.Saving_Valgrind_output=Saving Valgrind output
@@ -37,5 +43,5 @@ ValgrindOptionsTab.noemul=Emulator isn't connected or activated.
 ValgrindOptionsTab.noemul_option=Emulator isn't activated.(valgrind is supported in emulator only)
 ValgrindOptionsTab.nodevice=No device is connected.
 ValgrindOptionsTab.cannotrun=Cannot run valgrind profiling.
-ValgrindOptionsTab.isprofiling=Another profiling is running. Please rerun after terminate the profiling.
+ValgrindOptionsTab.isprofiling=Another profiling is running. Please rerun after terminate the profiling.