From d2613c4d5667f3f7729a1a47b91e72e0e606445d Mon Sep 17 00:00:00 2001 From: Anna Dushistova Date: Tue, 28 Apr 2009 19:32:03 +0000 Subject: [PATCH] [175300] deferred populating usernames until it's really needed. --- .../shell/linux/LinuxProcessHelper.java | 24 +++++++++++++------ .../linux/LinuxShellProcessResources.java | 7 ++++-- .../LinuxShellProcessResources.properties | 10 ++++---- .../shell/linux/LinuxShellProcessService.java | 18 ++++++++++---- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxProcessHelper.java b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxProcessHelper.java index cc9aaa21bd1..86c9d0913d6 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxProcessHelper.java +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxProcessHelper.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2005, 2008 IBM Corporation and others. All rights reserved. + * Copyright (c) 2005, 2009 IBM Corporation and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,11 +11,12 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * Yu-Fen Kuo (MontaVista) - adapted from RSE UniversalLinuxProcessHandler + * Yu-Fen Kuo (MontaVista) - adapted from RSE UniversalLinuxProcessHandler * Martin Oberhuber (Wind River) - [refactor] "shell" instead of "ssh" everywhere * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API * David McKnight (IBM) - [175308] Need to use a job to wait for shell to exit * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error + * Anna Dushistova (MontaVista) - [175300][performance] processes.shell.linux subsystem is slow over ssh *******************************************************************************/ package org.eclipse.rse.internal.subsystems.processes.shell.linux; @@ -43,18 +44,21 @@ public class LinuxProcessHelper { private HashMap _usernamesByUid; private HashMap _uidsByUserName; + + private IHost _host; private static String COMMAND_GET_PASSWD = "getent passwd"; //$NON-NLS-1$ /** * constructor */ - public LinuxProcessHelper() { + public LinuxProcessHelper(IHost host) { super(); stateMap = new HashMap(); for (int i = ISystemProcessRemoteConstants.STATE_STARTING_INDEX; i < ISystemProcessRemoteConstants.STATE_ENDING_INDEX; i++) { stateMap.put(new Character(ISystemProcessRemoteConstants.ALL_STATES[i]), ISystemProcessRemoteConstants.ALL_STATES_STR[i]); } + _host = host; } /** @@ -86,13 +90,13 @@ public class LinuxProcessHelper { * this code is adapted from * org.eclipse.rse.services.clientserver.processes.handlers.UniversalLinuxProcessHandler */ - public void populateUsernames(IHost host) { - if (_usernamesByUid != null && _uidsByUserName != null || host == null) + public void populateUsernames() { + if (_usernamesByUid != null && _uidsByUserName != null || _host == null) return; _usernamesByUid = new HashMap(); _uidsByUserName = new HashMap(); - IShellService shellService = Activator.getShellService(host); + IShellService shellService = Activator.getShellService(_host); Process p = null; try { IHostShell hostShell = shellService.launchShell("", null, new NullProgressMonitor()); //$NON-NLS-1$ @@ -112,7 +116,6 @@ public class LinuxProcessHelper { new InputStreamReader(p.getInputStream())); String nextLine; - try { while ((nextLine = bufferReader.readLine()) != null && !nextLine.equals(Activator.DONE_MARKUP_STRING)) { @@ -161,4 +164,11 @@ public class LinuxProcessHelper { protected String getUserNameCommand() { return Activator.formatShellCommand(COMMAND_GET_PASSWD); } + + public boolean isInitialized(){ + if (_usernamesByUid != null && _uidsByUserName != null){ + return true; + } + return false; + } } diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.java b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.java index 11e3e3e3fcb..102b755f61e 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.java +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Martin Oberhuber (Wind River) - initial API and implementation + * Martin Oberhuber (Wind River) - initial API and implementation + * Anna Dushistova (MontaVista) - [175300][performance] processes.shell.linux subsystem is slow over ssh *******************************************************************************/ package org.eclipse.rse.internal.subsystems.processes.shell.linux; @@ -24,6 +25,8 @@ public class LinuxShellProcessResources extends NLS { public static String LinuxRemoteProcessService_getSignalTypes_empty; + public static String LinuxShellProcessService_initHelper; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, LinuxShellProcessResources.class); diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.properties index b0a2bc83758..24ffc36b4e7 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.properties +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessResources.properties @@ -1,14 +1,15 @@ ################################################################################ -# Copyright (c) 2006, 2008 MontaVista Software, Inc. and others. +# Copyright (c) 2006, 2009 MontaVista Software, Inc. and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: -# Yu-Fen Kuo (MontaVista) - initial API and implementation +# Yu-Fen Kuo (MontaVista) - initial API and implementation # Martin Oberhuber (Wind River) - [refactor] "shell" instead of "ssh" everywhere -# Xuan Chen (IBM) - added NLS_MESSAGEFORMAT comments +# Xuan Chen (IBM) - added NLS_MESSAGEFORMAT comments +# Anna Dushistova (MontaVista) - [175300][performance] processes.shell.linux subsystem is slow over ssh ################################################################################ # NLS_MESSAGEFORMAT_VAR @@ -17,4 +18,5 @@ LinuxRemoteProcessService_name=Shell Process Service LinuxRemoteProcessService_description=listing processes on the remote target through a contributed shell service LinuxRemoteProcessService_monitor_fetchProcesses=Fetching Remote Process Information... -LinuxRemoteProcessService_getSignalTypes_empty=Failed to retrieve signal types from remote target. \ No newline at end of file +LinuxRemoteProcessService_getSignalTypes_empty=Failed to retrieve signal types from remote target. +LinuxShellProcessService_initHelper=Populating usernames diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessService.java b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessService.java index 29aab2efcd6..4a980801128 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessService.java +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux/src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessService.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Yu-Fen Kuo (MontaVista) - initial API and implementation + * Yu-Fen Kuo (MontaVista) - initial API and implementation * Martin Oberhuber (Wind River) - [refactor] "shell" instead of "ssh" everywhere * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API * David McKnight (IBM) - [175308] Need to use a job to wait for shell to exit @@ -14,6 +14,7 @@ * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error * Anna Dushistova (MontaVista) - [239159] The shell process subsystem not working without the shells subsystem present for the systemType * David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService() + * Anna Dushistova (MontaVista) - [175300][performance] processes.shell.linux subsystem is slow over ssh *******************************************************************************/ package org.eclipse.rse.internal.subsystems.processes.shell.linux; @@ -116,11 +117,22 @@ public class LinuxShellProcessService extends AbstractProcessService { filter.setUsername(connectionUserId); } } + if (monitor != null) { monitor.beginTask( LinuxShellProcessResources.LinuxRemoteProcessService_monitor_fetchProcesses, 100); } + if(!linuxProcessHelper.isInitialized()){ + // initialize username /uid hashmap before getting any process + if (monitor != null) { + monitor.setTaskName(LinuxShellProcessResources.LinuxShellProcessService_initHelper); + } + linuxProcessHelper.populateUsernames(); + if (monitor != null) { + monitor.setTaskName(LinuxShellProcessResources.LinuxRemoteProcessService_monitor_fetchProcesses); + } + } IShellService shellService = Activator.getShellService(host); IHostShell hostShell = shellService.launchShell( "", null, new NullProgressMonitor()); //$NON-NLS-1$ @@ -190,9 +202,7 @@ public class LinuxShellProcessService extends AbstractProcessService { public void initService(final IProgressMonitor monitor) throws SystemMessageException { super.initService(monitor); - linuxProcessHelper = new LinuxProcessHelper(); - // initialize username /uid hashmap before getting any process - linuxProcessHelper.populateUsernames(host); + linuxProcessHelper = new LinuxProcessHelper(host); } private boolean progressWorked(final IProgressMonitor monitor,