From: HyungKyu Song Date: Fri, 15 Feb 2013 15:59:18 +0000 (+0900) Subject: Tizen 2.0 Release X-Git-Tag: submit/tizen_2.0/20130215.192345^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_2.0;p=sdk%2Fide%2Fprofiler-eplugin.git Tizen 2.0 Release --- diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..21370e0 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Jaewon Lim +Juyoung Kim +HyunGoo Kang diff --git a/LICENSE.EPL b/LICENSE.EPL new file mode 100644 index 0000000..3998fce --- /dev/null +++ b/LICENSE.EPL @@ -0,0 +1,261 @@ + + + + + + +Eclipse Public License - Version 1.0 + + + + + + +

Eclipse Public License - v 1.0

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS +AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) in the case of the initial Contributor, the initial +code and documentation distributed under this Agreement, and

+

b) in the case of each subsequent Contributor:

+

i) changes to the Program, and

+

ii) additions to the Program;

+

where such changes and/or additions to the Program +originate from and are distributed by that particular Contributor. A +Contribution 'originates' from a Contributor if it was added to the +Program by such Contributor itself or anyone acting on such +Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) +are not derivative works of the Program.

+ +

"Contributor" means any person or entity that distributes +the Program.

+ +

"Licensed Patents" mean patent claims licensable by a +Contributor which are necessarily infringed by the use or sale of its +Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions distributed in accordance +with this Agreement.

+ +

"Recipient" means anyone who receives the Program under +this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free copyright license to reproduce, prepare derivative works +of, publicly display, publicly perform, distribute and sublicense the +Contribution of such Contributor, if any, and such derivative works, in +source code and object code form.

+ +

b) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free patent license under Licensed Patents to make, use, sell, +offer to sell, import and otherwise transfer the Contribution of such +Contributor, if any, in source code and object code form. This patent +license shall apply to the combination of the Contribution and the +Program if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to be covered +by the Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) Recipient understands that although each Contributor +grants the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility to +secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow Recipient +to distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program.

+ +

d) Each Contributor represents that to its knowledge it +has sufficient copyright rights in its Contribution, if any, to grant +the copyright license set forth in this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the Program in object code +form under its own license agreement, provided that:

+ +

a) it complies with the terms and conditions of this +Agreement; and

+ +

b) its license agreement:

+ +

i) effectively disclaims on behalf of all Contributors +all warranties and conditions, express and implied, including warranties +or conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose;

+ +

ii) effectively excludes on behalf of all Contributors +all liability for damages, including direct, indirect, special, +incidental and consequential damages, such as lost profits;

+ +

iii) states that any provisions which differ from this +Agreement are offered by that Contributor alone and not by any other +party; and

+ +

iv) states that source code for the Program is available +from such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for software +exchange.

+ +

When the Program is made available in source code form:

+ +

a) it must be made available under this Agreement; and

+ +

b) a copy of this Agreement must be included with each +copy of the Program.

+ +

Contributors may not remove or alter any copyright notices contained +within the Program.

+ +

Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and +indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") +arising from claims, lawsuits and other legal actions brought by a third +party against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In +order to qualify, an Indemnified Contributor must: a) promptly notify +the Commercial Contributor in writing of such claim, and b) allow the +Commercial Contributor to control, and cooperate with the Commercial +Contributor in, the defense and any related settlement negotiations. The +Indemnified Contributor may participate in any such claim at its own +expense.

+ +

For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable laws, +damage to or loss of data, programs or equipment, and unavailability or +interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further action +by the parties hereto, such provision shall be reformed to the minimum +extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the +date such litigation is filed.

+ +

All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of time +after becoming aware of such noncompliance. If all Recipient's rights +under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute copies of this +Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The +Agreement Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other than the +Agreement Steward has the right to modify this Agreement. The Eclipse +Foundation is the initial Agreement Steward. The Eclipse Foundation may +assign the responsibility to serve as the Agreement Steward to a +suitable separate entity. Each new version of the Agreement will be +given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version +of the Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives no +rights or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved.

+ +

This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No party +to this Agreement will bring a legal action under this Agreement more +than one year after the cause of action arose. Each party waives its +rights to a jury trial in any resulting litigation.

+ + + + \ No newline at end of file diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..a8d404b --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Eclipse Public License, Version 1.0. +Please, see the LICENSE.EPL file for Eclipse Public License, Version 1.0 terms and conditions. + diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..fea82ab --- /dev/null +++ b/build.sh @@ -0,0 +1,164 @@ +#!/bin/bash +start_path=`pwd` + +############################################################### +## +## Please modify parameter value. +## +############################################################### +build_type=N +build_id=profiler_build +build_path="`pwd`/../build_result" + +############################################################### +## +## Do not touch here. +## +############################################################### +build_result_directory=${build_type}.${build_id} +build_result_path="$build_path/$build_result_directory" +builder_path="$start_path/builder" +equinox_launcher=`echo org.eclipse.equinox.launcher_*.jar` +pde_build=`echo org.eclipse.pde.build_*` +metadata_path=$start_path/builder +fresh_ide_path=$3 + +if [ "x$1" = "x" ] +then + echo " +Usage : build.sh PLATFORM_NAME TARGET_ECLIPSE_PATH + + PLATFORM_NAME You can set \"linux\" or \"windows\" + TARGET_ECLIPSE_PATH Set target eclipse path. + For example, $HOME/git/fresh-ide-pde +" + exit 1 +fi + +if [ "x$2" = "x" ] +then + echo " +Usage : build.sh $1 TARGET_ECLIPSE_PATH + TARGET_ECLIPSE_PATH Set target eclipse path. + For example, $HOME/git/fresh-ide-pde +" + exit 1 +fi + +#if [ "x$3" != "x" ] +#then +# build_path=$3 +#fi + +platform=$1 +based_eclipse_path=$2 +parent_path_of_based_eclipse=${based_eclipse_path}/.. +architecture=x86 + +case ${platform} in + linux) + archive_platform_name=linux + windowing=gtk + ;; + windows) + archive_platform_name=win32 + windowing=win32 + ;; + *) + echo "${platform} is not support yet." + exit 1 + ;; +esac + +result_archive_file=${build_id}-${archive_platform_name}.${windowing}.${architecture}.zip + +if [ -d $build_path ] +then + echo "Build result directory : [$build_path]" +else + echo "Make build result directory [$build_path]" + mkdir -p $build_path +fi + +echo "Remove legacy build files..." +if [ -d ${build_result_path}/${archive_platform_name}.${windowing}.${architecture} ] +then + rm -rf ${build_result_path}/${archive_platform_name}.${windowing}.${architecture} +fi +if [ -e ${build_result_path}/${result_archive_file} ] +then + rm -rf ${build_result_path}/${result_archive_file} +fi + +if [ -d $build_path/plugins ] +then + echo "plugins directory recreate..." + rm -rf $build_path/plugins + mkdir $build_path/plugins +else + echo "Make plugins directory..." + mkdir $build_path/plugins +fi +if [ -d $build_path/features/ ] +then + echo "features directory recreate..." + rm -rf $build_path/features + mkdir $build_path/features +else + echo "Make features directory..." + mkdir $build_path/features +fi + +echo "Copy features from $start_path to $build_path/features" +cp -r $start_path/*.feature $build_path/features + +echo "Copy plugins from $start_path to $build_path/plugins" +cp -r $start_path/* $build_path/plugins +rm -rf $build_path/plugins/*.feature + +echo "Copy fresh ide plugins..." +if [ -d ${fresh_ide_path} ] +then + cp -rf ${fresh_ide_path}/${archive_platform_name}.${windowing}.${architecture}/IDE/plugins/* ${build_path}/plugins + cp -rf ${fresh_ide_path}/${archive_platform_name}.${windowing}.${architecture}/IDE/features/* ${build_path}/features +else + echo "ERROR : Fresh IDE does not exist..." + exit 1 +fi + +echo "Make build.properties file..." +if [ ! -e $builder_path/build.properties.clean ] ; then + echo "ERROR : \"build.properties.clean\" file does not exist..." + exit 1 +fi +cp $builder_path/build.properties.clean $build_path +cp $builder_path/customTargets.xml $build_path + +if [ -d $based_eclipse_path ] +then + sed -e "s;\(^buildDirectory=\).*;\1${build_path};g" -e "s;\(^base=\).*;\1${parent_path_of_based_eclipse};g" -e "s;\(^baseLocation=\).*;\1${based_eclipse_path};g" -e "s;\(^configs=\).*;\1${archive_platform_name},${windowing},${architecture};g" -e "s;\(^buildType=\).*;\1${build_type};g" -e "s;\(^buildId=\).*;\1${build_id};g" < $build_path/build.properties.clean > $build_path/build.properties +else + echo "ERROR : target eclipse is not exist." + exit 1 +fi + +echo "Execute Product Ant Builder..." +java -server -XX:+UseParNewGC -jar ${based_eclipse_path}/plugins/$equinox_launcher -application org.eclipse.ant.core.antRunner -buildfile ${based_eclipse_path}/plugins/$pde_build/scripts/productBuild/productBuild.xml -Dbuilder=$build_path 2>&1 + +if [ $? != 0 ]; +then + echo "Build failed..." + exit 1 +fi + +echo "unzip to $build_result_path" +unzip -a $build_result_path/${result_archive_file} -d $build_result_path/${archive_platform_name}.${windowing}.${architecture} + +#echo "Delete temp files..." +#rm -rf $build_path/features +#rm -rf $build_path/plugins +#rm $build_path/*.xml +#rm $build_path/*.properties +#rm $build_path/*.properties.clean + +echo "Build SUCCESS. You will find SDK IDE in \"${build_result_path}\"." diff --git a/builder/build.properties.clean b/builder/build.properties.clean new file mode 100644 index 0000000..2b8a31f --- /dev/null +++ b/builder/build.properties.clean @@ -0,0 +1,260 @@ +############################################################################### +# Copyright (c) 2003, 2006 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 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +##################### +# Parameters describing how and where to execute the build. +# Typical users need only update the following properties: +# baseLocation - where things you are building against are installed +# bootclasspath - The base jars to compile against (typicaly rt.jar) +# configs - the list of {os, ws, arch} configurations to build. +# +# Of course any of the settings here can be overridden by spec'ing +# them on the command line (e.g., -DbaseLocation=d:/eclipse + +#The type of the top level element we are building, generally "feature" +topLevelElementType=feature +#The id of the top level element we are building +topLevelElementId=org.tizen.profiler.feature + +############# PRODUCT/PACKAGING CONTROL ############# +#product=/org.tizen.base.platform/TizenIDE_base_linux.product +#runPackager=true + +#Set the name of the archive that will result from the product build. +#archiveNamePrefix= + +# The prefix that will be used in the generated archive. +archivePrefix=profiler + +# The location underwhich all of the build output will be collected. +collectingFolder=${archivePrefix} + +# The list of {os, ws, arch} configurations to build. This +# value is a '&' separated list of ',' separate triples. For example, +# configs=win32,win32,x86 & linux,motif,x86 +# By default the value is *,*,* +configs="Do not touch here." +#configs=win32, win32, x86 & \ +# win32,win32,x86_64 & \ +# win32,win32,wpf & \ +# linux, gtk, ppc & \ +# linux, gtk, x86 & \ +# linux, gtk, x86_64 & \ +# linux, motif, x86 & \ +# solaris, motif, sparc & \ +# solaris, gtk, sparc & \ +# aix, motif, ppc & \ +# hpux, motif, ia64_32 & \ +# macosx, carbon, ppc & \ +# macosx, carbon, x86 & \ +# macosx, cocoa, ppc & \ +# macosx, cocoa, x86 & \ +# macosx, cocoa, x86_64 + +# By default PDE creates one archive (result) per entry listed in the configs property. +# Setting this value to true will cause PDE to only create one output containing all +# artifacts for all the platforms listed in the configs property. +# To control the output format for the group, add a "group, group, group - " entry to the +# archivesFormat. +#groupConfigurations=true + +#The format of the archive. By default a zip is created using antZip. +#The list can only contain the configuration for which the desired format is different than zip. +#archivesFormat=win32, win32, x86 - antZip& \ +# linux, gtk, ppc - antZip &\ +# linux, gtk, x86 - antZip& \ +# linux, gtk, x86_64 - antZip& \ +# linux, motif, x86 - antZip& \ +# solaris, motif, sparc - antZip& \ +# solaris, gtk, sparc - antZip& \ +# aix, motif, ppc - antZip& \ +# hpux, motif, PA_RISC - antZip& \ +# macosx, carbon, ppc - antZip + +#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles. +allowBinaryCycles=true + +#Sort bundles depenedencies across all features instead of just within a given feature. +#flattenDependencies = true + +#Parallel compilation, requires flattenedDependencies=true +#parallelCompilation=true +#parallelThreadCount= +#parallelThreadsPerProcessor= + +#Set to true if you want the output to be ready for an update jar (no site.xml generated) +#outputUpdateJars = false + +#Set to true for Jnlp generation +#codebase should be a URL that will be used as the root of all relative URLs in the output. +#generateJnlp=false +#jnlp.codebase= +#jnlp.j2se= +#jnlp.locale= +#jnlp.generateOfflineAllowed=true or false generate attribute in the generated features +#jnlp.configs=${configs} #uncomment to filter the content of the generated jnlp files based on the configuration being built + +#Set to true if you want to sign jars +#signJars=false +#sign.alias= +#sign.keystore= +#sign.storepass= +#sign.keypass= + +#Arguments to send to the zip executable +#zipargs= + +#Arguments to send to the tar executable +#tarargs= + +#Control the creation of a file containing the version included in each configuration - on by default +#generateVersionsLists=false + +############## BUILD NAMING CONTROL ################ +# The directory into which the build elements are fetched and where +# the build takes place. +buildDirectory="Do not touch here" + +# Type of build. Used in naming the build output. Typically this value is +# one of I, N, M, S, ... +buildType="Do not touch here" + +# ID of the build. Used in naming the build output. +buildId="Do not touch here" + +# Label for the build. Used in naming the build output +buildLabel=${buildType}.${buildId} + +# Timestamp for the build. Used in naming the build output +timestamp=007 + +#The value to be used for the qualifier of a plugin or feature when you want to override the value computed by pde. +#The value will only be applied to plugin or features indicating build.properties, qualifier = context +#forceContextQualifier= + +#Enable / disable the generation of a suffix for the features that use .qualifier. +#The generated suffix is computed according to the content of the feature +#generateFeatureVersionSuffix=true + +############# BASE CONTROL ############# +# Settings for the base Eclipse components and Java class libraries +# against which you are building. +# Base location for anything the build needs to compile against. For example, +# in most RCP app or a plug-in, the baseLocation should be the location of a previously +# installed Eclipse against which the application or plug-in code will be compiled and the RCP delta pack. + +base="Do not touch here" +baseLocation="Do not touch here" + + +#Folder containing repositories whose content is needed to compile against +#repoBaseLocation=${base}/repos +#Folder where the content of the repositories from ${repoBaseLocation} will be made available as a form suitable to be compiled against +#transformedRepoLocation=${base}/transformedRepos + +#Os/Ws/Arch/nl of the eclipse specified by baseLocation +baseos=linux +basews=gtk +basearch=x86 + +#this property indicates whether you want the set of plug-ins and features to be considered during the build to be limited to the ones reachable from the features / plugins being built +filteredDependencyCheck=false + +#this property indicates whether the resolution should be done in development mode (i.e. ignore multiple bundles with singletons) +resolution.devMode=false + +#pluginPath is a list of locations in which to find plugins and features. This list is separated by the platform file separator (; or :) +#a location is one of: +#- the location of the jar or folder that is the plugin or feature : /path/to/foo.jar or /path/to/foo +#- a directory that contains a /plugins or /features subdirectory +#- the location of a feature.xml, or for 2.1 style plugins, the plugin.xml or fragment.xml +#pluginPath= + +skipBase=true +eclipseURL= +eclipseBuildId= +eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip + + +############# MAP FILE CONTROL ################ +# This section defines CVS tags to use when fetching the map files from the repository. +# If you want to fetch the map file from repository / location, change the getMapFiles target in the customTargets.xml + +skipMaps=true +mapsRepo=:pserver:anonymous@example.com/path/to/repo +mapsRoot=path/to/maps +mapsCheckoutTag=HEAD + +#tagMaps=true +mapsTagTag=v${buildId} + + +############ REPOSITORY CONTROL ############### +# This section defines properties parameterizing the repositories where plugins, fragments +# bundles and features are being obtained from. + +# The tags to use when fetching elements to build. +# By default thebuilder will use whatever is in the maps. +# This value takes the form of a comma separated list of repository identifier (like used in the map files) and the +# overriding value +# For example fetchTag=CVS=HEAD, SVN=v20050101 +# fetchTag=HEAD +skipFetch=true + + +############# P2 OPTIONS ############## +#p2.gathering = true +#p2.compress=true + +############# JAVA COMPILER OPTIONS ############## +# The location of the Java jars to compile against. Typically the rt.jar for your JDK/JRE +#bootclasspath=${java.home}/lib/rt.jar + +# specific JRE locations to compile against. These values are used to compile bundles specifying a +# Bundle-RequiredExecutionEnvironment. Uncomment and set values for environments that you support +#CDC-1.0/Foundation-1.0= /path/to/rt.jar +#CDC-1.1/Foundation-1.1= +#OSGi/Minimum-1.0= +#OSGi/Minimum-1.1= +#JRE-1.1= +#J2SE-1.2= +#J2SE-1.3= +#J2SE-1.4= +#J2SE-1.5= +#JavaSE-1.6= +#PersonalJava-1.1= +#PersonalJava-1.2= +#CDC-1.0/PersonalBasis-1.0= +#CDC-1.0/PersonalJava-1.0= +#CDC-1.1/PersonalBasis-1.1= +#CDC-1.1/PersonalJava-1.1= + +# Specify the output format of the compiler log when eclipse jdt is used +logExtension=.log + +# Whether or not to include debug info in the output jars +javacDebugInfo=false + +# Whether or not to fail the build if there are compiler errors +javacFailOnError=true + +# Enable or disable verbose mode of the compiler +javacVerbose=true + +# Extra arguments for the compiler. These are specific to the java compiler being used. +#compilerArg= + +# Default value for the version of the source code. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacSource in build.properties +javacSource=1.6 + +# Default value for the version of the byte code targeted. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacTarget in build.properties. +javacTarget=1.6 + + diff --git a/builder/customTargets.xml b/builder/customTargets.xml new file mode 100644 index 0000000..cc059b7 --- /dev/null +++ b/builder/customTargets.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/builder/metadata/data/platforms/tizen2.0/on-demand/eglibc-debuginfo_0.0.1_armel.tar b/builder/metadata/data/platforms/tizen2.0/on-demand/eglibc-debuginfo_0.0.1_armel.tar new file mode 100644 index 0000000..31a3bbf Binary files /dev/null and b/builder/metadata/data/platforms/tizen2.0/on-demand/eglibc-debuginfo_0.0.1_armel.tar differ diff --git a/builder/metadata/data/platforms/tizen2.0/on-demand/eglibc-debuginfo_0.0.1_i386.tar b/builder/metadata/data/platforms/tizen2.0/on-demand/eglibc-debuginfo_0.0.1_i386.tar new file mode 100644 index 0000000..a8a39b2 Binary files /dev/null and b/builder/metadata/data/platforms/tizen2.0/on-demand/eglibc-debuginfo_0.0.1_i386.tar differ diff --git a/builder/metadata/pkginfo.manifest b/builder/metadata/pkginfo.manifest new file mode 100644 index 0000000..5cf0990 --- /dev/null +++ b/builder/metadata/pkginfo.manifest @@ -0,0 +1,6 @@ +Package: Profiler +Version: 1.0 +Architecture: i386 +Maintainer: Jaewon Lim , Juyoung Kim +Description: Tizen SDK profiler +Category: IDE/Tizen IDE/Plugins/Dynamic analysis diff --git a/org.eclipse.linuxtools.oprofile.core/.classpath b/org.eclipse.linuxtools.oprofile.core/.classpath new file mode 100644 index 0000000..ad32c83 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.oprofile.core/.project b/org.eclipse.linuxtools.oprofile.core/.project new file mode 100644 index 0000000..f6a0d69 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.oprofile.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.oprofile.core/.settings/org.eclipse.core.resources.prefs b/org.eclipse.linuxtools.oprofile.core/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..04d1538 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Wed Dec 01 09:13:12 CET 2010 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.linuxtools.oprofile.core/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.linuxtools.oprofile.core/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000..98f42b9 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Tue Dec 14 16:36:19 CET 2010 +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF new file mode 100644 index 0000000..18715ed --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tizen SDK Oprofile Core +Bundle-SymbolicName: org.eclipse.linuxtools.oprofile.core;singleton:=true +Bundle-Version: 1.3.18.qualifier +Bundle-Activator: org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin +Bundle-Vendor: Eclipse Linux Tools +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.0", + org.eclipse.ui;bundle-version="3.4.0", + org.eclipse.linuxtools.profiling.launch, + org.tizen.common, + org.tizen.common.connection +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: org.tizen.oprofile.core, + org.tizen.oprofile.core.processor.modeldata.handler, + org.eclipse.linuxtools.oprofile.core, + org.eclipse.linuxtools.oprofile.core.daemon, + org.eclipse.linuxtools.oprofile.core.linux, + org.eclipse.linuxtools.oprofile.core.model, + org.eclipse.linuxtools.oprofile.core.opxml, + org.eclipse.linuxtools.oprofile.core.opxml.checkevent, + org.eclipse.linuxtools.oprofile.core.opxml.info, + org.eclipse.linuxtools.oprofile.core.opxml.modeldata, + org.eclipse.linuxtools.oprofile.core.opxml.sessions +Import-Package: org.tizen.sdblib diff --git a/org.eclipse.linuxtools.oprofile.core/NOTICE b/org.eclipse.linuxtools.oprofile.core/NOTICE new file mode 100644 index 0000000..a6b69ae --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/NOTICE @@ -0,0 +1,79 @@ +2010-02-10 SPRC SDK Team + * MANIFEST.MF : delete Bundle-Localization + * build.properties : fix bin.includes + * Oprofile.java : commented _OPROFILE_CPU_TYPE_FILES member + * OprofileCorePlugin.java : commented some member varaible (OPXMLPROVIDER_XPT_NAME, _opcontrolDataProvider) + * LinuxOpcontrolProvider.java : commented some variables and functions + +2010-10-21 HyungJong, Shin + * opxml, scripts directory : remove unnecessary files + +2010-10-21 HyungJong, Shin + * build.properties : modify bin.includes + * remove unused code (38 files in ./native/linux/*.*) + +2010-11-03 HyungJong, Shin + * LinuxOpcontrolProvider.java : modify 'session.run' code + * OpxmlRunner.java : modify 'session.run' code + +2010-11-05 sdk + * MANIFEST.MF : changed some package name + * Oprofile.java : changed some package name + * LinuxOpcontrolProvider.java : changed some package name + * LinuxOpxmlProvider.java : changed some package name + * OpxmlRunner.java : changed some package name + * OpModelRoot.java : changed some package name + +2011-06-09 jaewon81.lim + * MANIFEST.MF : rearrange plugins dependency + +2011-06-13 jaewon81.lim + * LinuxOpcontrolProvider.java : some bug fix + +2011-07-13 jaewon81.lim + * MANIFEST.MF : modified import package name + * LinuxOpcontrolProvider.java : modified import package name + * OpxmlRunner.java : modified import package name + +2011-08-22 joogwan.kim + * MANIFEST.MF : Change plug-in name + * LinuxOpcontrolProvider.java : Change plug-in name + * OpxmlRunner.java : Change plug-in name + +2011-10-14 wonhyoung2.park + * PathParser.java : profile bug fix for window + * OpxmlRunner.java : profile bug fix for window + +2011-11-16 wonhyoung2.park + * MANIFEST.MF : Profiler sdb apply + * CommandManager.java : added new file + * PathParser.java : deleted file + * LinuxOpcontrolProvider.java : Profiler sdb apply + * OpxmlRunner.java : Profiler sdb apply + +2011-11-29 wonhyoung2.park + * MANIFEST.MF : chagne slp to tizen + * CommandManager.java : chagne slp to tizen + * Oprofile.java : chagne slp to tizen + * LinuxOpcontrolProvider.java : chagne slp to tizen + * LinuxOpxmlProvider.java : chagne slp to tizen + * OpxmlRunner.java : chagne slp to tizen + * OpModelRoot.java : chagne slp to tizen + +2011-11-30 wonhyoung2.park + * MANIFEST.MF : provider and plugin name modify + +2011-12-02 taeyoung2.son + * MANIFEST.MF : Delete dependency feature's version value. + +2011-12-03 wonhyoung2.park + * MANIFEST.MF : package instll routine chage + * plugin.xml : package instll routine chage + * CommandManager.java : package instll routine chage + +2011-12-04 wonhyoung2.park + * plugin.xml : deleted file + +2011-12-05 wonhyoung2.park + * LinuxOpcontrolProvider.java : add console (profile stop available) + * OpxmlRunner.java : add console (profile stop available) diff --git a/org.eclipse.linuxtools.oprofile.core/README b/org.eclipse.linuxtools.oprofile.core/README new file mode 100644 index 0000000..f872c8a --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/README @@ -0,0 +1,23 @@ +An extra step is required to install the plugin (due to OProfile's lack of a user-space mode): + +* Run the install script in the natives/linux/scripts directory (must be as root): + + # ./install + + * This will ensure all the necessary programs are installed, and create a wrapper for opcontrol + which prompts for the root password (since OProfile must be run as root). It will also load the + OProfile kernel module, however it is not loaded persistently. Hence, after the computer is + restarted and any functions of the plugin are used, there will be an extra prompt to run + opcontrol that would not normally appear. + + * If there are any programs missing or an error occurs, the script will fail and display the error. + If there are no errors, you will see the message: + + Eclipse-OProfile plugin install successful. + + +* To uninstall the plugin, run the uninstall script in the natives/linux/scripts (must be root): + + # ./uninstall + + * This will simply remove the same files the install script created. diff --git a/org.eclipse.linuxtools.oprofile.core/about.html b/org.eclipse.linuxtools.oprofile.core/about.html new file mode 100644 index 0000000..0c6525d --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/about.html @@ -0,0 +1,33 @@ + + + +About + + + +

About This Content

+ +

24th October, 2008

+

License

+

The Eclipse Software Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

Contributions

+ +

If this Content is licensed to you under the terms and conditions of the EPL, any Contributions, as defined in the EPL, uploaded, submitted, or otherwise +made available to the Eclipse Foundation, its members and/or the host of the Eclipse Foundation web site, by you that relate to such +Content are provided under the terms and conditions of the Terms of Use +for the Eclipse Foundation web site and can be made available to others under the terms of the licenses as set out in the +Terms of Use.

+ +

If this Content is licensed to you under license terms and conditions other than the EPL ("Other License"), any modifications, enhancements and/or +other code and/or documentation ("Modifications") uploaded, submitted, or otherwise made available to the Eclipse Foundation, its members and/or the +host of the Eclipse Foundation web site, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available +to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also +providing the Modifications under the terms and conditions of the Terms of Use +for the Eclipse Foundation web site and such Modifications can be made available to others under the terms of the licenses as set out in the +Terms of Use.

+ + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.oprofile.core/build.properties b/org.eclipse.linuxtools.oprofile.core/build.properties new file mode 100644 index 0000000..fb21e3e --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +bin.includes = META-INF/,\ + README,\ + about.html,\ + . +javacSource = 1.6 +javacTarget = 1.6 diff --git a/org.eclipse.linuxtools.oprofile.core/schema/OpxmlProvider.exsd b/org.eclipse.linuxtools.oprofile.core/schema/OpxmlProvider.exsd new file mode 100644 index 0000000..8b02e63 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/schema/OpxmlProvider.exsd @@ -0,0 +1,70 @@ + + + + + + + + + An extension point to allow architecture fragments to provide the opxml binary. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/IOpcontrolProvider.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/IOpcontrolProvider.java new file mode 100644 index 0000000..3d55bb6 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/IOpcontrolProvider.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core; + +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonOptions; + +/** + * Interface for oprofile core to utilize opcontrol program. Platform plugins should define/register + * an OpcontrolProvider for the core to use. + */ +public interface IOpcontrolProvider { + + /** + * Initialize the Oprofile kernel module + * @throws OpcontrolException + */ + public void initModule() throws OpcontrolException; + + /** + * De-initialize (unload) the kernel module + * @throws OpcontrolException + */ + public void deinitModule() throws OpcontrolException; + + /** + * Clears out data from the current session + * @throws OpcontrolException + */ + public void reset() throws OpcontrolException; + + /** + * Flush the current oprofiled sample buffers to disk + * @throws OpcontrolException + */ + public void dumpSamples() throws OpcontrolException; + + /** + * Setup oprofiled collection parameters + * @param options a list of command-line arguments for opcontrol + * @param events list of events to collect + * @throws OpcontrolException + */ + public void setupDaemon(OprofileDaemonOptions options, OprofileDaemonEvent[] events) throws OpcontrolException; + + //jinu added at 20090602 + public void setupDaemon(OprofileDaemonOptions options, OprofileDaemonEvent[] events, String defaultEvent) throws OpcontrolException; + + /** + * Start data collection by oprofiled (will start oprofiled if necessary) + * @throws OpcontrolException + */ + public void startCollection() throws OpcontrolException; + + /** + * Stop data collection (does NOT stop daemon) + * @throws OpcontrolException + */ + public void stopCollection() throws OpcontrolException; + + /** + * Stop data collection and shutdown oprofiled + * @throws OpcontrolException + */ + public void shutdownDaemon() throws OpcontrolException; + + /** + * Start oprofiled (does NOT start data collection) + * @throws OpcontrolException + */ + public void startDaemon() throws OpcontrolException; + + /** + * Save the current session + * @throws OpcontrolException + */ + public void saveSession(String name) throws OpcontrolException; + + //jinu added at 20090526 + public void removeDaemonSetting() throws OpcontrolException; +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/IOpxmlProvider.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/IOpxmlProvider.java new file mode 100644 index 0000000..97e05bc --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/IOpxmlProvider.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core; + +import java.util.ArrayList; + +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; + +/** + * Interface for the core to utilize opxml. Platform plugins should define/register an + * OpxmlProvider for the core to use. + */ +public interface IOpxmlProvider { + + /** + * Returns an IRunnableWithProgress that fetches generic information from opxml + * @param info OpInfo object for results + * @return IRunnableWithProgress that may be run by the caller + */ + public IRunnableWithProgress info(OpInfo info); + + /** + * Returns an IRunnableWithProgress that fetches samples for the + * given OpModelSession + * @param eventName the event for which to fetch samples + * @param sessionName the session for which to fetch samples + * @param image the image being profiled to be returned to the caller + * @return IRunnableWithProgress that may be run by the caller + */ + public IRunnableWithProgress modelData(String eventName, String sessionName, OpModelImage image); + + /** + * Returns an IRunnableWithProgress that checks the validity of the given + * event, unit mask, and counter combination + * @param ctr the counter + * @param event the integer event number + * @param um the integer unit mask + * @param eventValid a size one array to hold the return result (see CheckKernelProcessor) + * @return IRunnableWithProgress that may be run by the caller + */ + public IRunnableWithProgress checkEvents(int ctr, int event, int um, int[] eventValid); + + /** + * Returns an /code>IRunnableWithProgress that fetches the list of sessions + * @param info the OpInfo for oprofile + * @param sessionList an ArrayList in which to return the list of sessions + * @return IRunnableWithProgress that may be run by the caller + */ + public IRunnableWithProgress sessions(ArrayList sessionList); +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OpcontrolException.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OpcontrolException.java new file mode 100644 index 0000000..f6de34b --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OpcontrolException.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; + +public class OpcontrolException extends CoreException { + //without this there's a warning.. + private static final long serialVersionUID = 8508930482724912901L; + + public OpcontrolException(IStatus status) { + super(status); + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java new file mode 100644 index 0000000..60fe4a3 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java @@ -0,0 +1,324 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.linuxtools.oprofile.core.daemon.OpEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.opxml.checkevent.CheckEventsProcessor; + +import org.tizen.oprofile.core.OprofileComm; +import org.tizen.oprofile.core.provider.OpcontrolDataProvider; + + +/** + * Common class wrapper for all things Oprofile. + */ +public abstract class Oprofile +{ + // Ugh. Need to know whether the module is loaded without running oprofile commands... +// private static final String[] _OPROFILE_CPU_TYPE_FILES = { +// "/dev/oprofile/cpu_type", //$NON-NLS-1$ +// "/proc/sys/dev/oprofile/cpu_type" //$NON-NLS-1$ +// }; + + // Oprofile information + private static OpInfo _info; + + + // Make sure that oprofile is ready to go + //jinu removed at 20090603 + /* + static { + initializeOprofileModule(); + } + */ + + /** + * Initialize the oprofile module + * + * This function will check if the kernel module is + * loaded. If it is not, it will attempt to load it + * (which will cause the system to prompt the user for + * root access). + */ + static private void initializeOprofileModule() throws OpcontrolException{ + // Check if kernel module is loaded, if not, try to load it + + //jinu removed at 20090628 + //if (!isKernelModuleLoaded()) + _initializeOprofile(); + + //it still may not have loaded, if not, critical error + if (!isKernelModuleLoaded()) { + //jinu modified at 20090628 + /* + OprofileCorePlugin.showErrorDialog("oprofileInit", null); //$NON-NLS-1$ + throw new ExceptionInInitializerError(OprofileProperties.getString("fatal.kernelModuleNotLoaded")); //$NON-NLS-1$ + */ + String error = "The OProfile kernel module could not be loaded"; + String reason = "An error occurred initializing OProfile for use with the plugin. Please check Oprofile to be installed successfully"; + OprofileComm.showErrorDialog(error, reason , null); //$NON-NLS-1$ + } else { + _initializeOprofileCore(); + } + } + + // This requires more inside knowledge about Oprofile than one would like, + // but it is the only way of knowing whether the module is loaded (and we can + // succesfully call into the oprofile wrapper library without causing it to print out + // a lot of warnings). + //jinu modified at 20090619 + /* + private static boolean isKernelModuleLoaded() { + for (int i = 0; i < _OPROFILE_CPU_TYPE_FILES.length; ++i) { + File f = new File(_OPROFILE_CPU_TYPE_FILES[i]); + if (f.exists()) + return true; + } + + return false; + } + */ + private static boolean isKernelModuleLoaded() { + String[] result = new String[1]; + try { + IRunnableWithProgress opxml = OpcontrolDataProvider.checkKernelModule(result); + opxml.run(null); + } catch (InvocationTargetException e) { + String error = "The OProfile kernel module could not be loaded"; + String reason = "An error occurred initializing OProfile for use with the plugin. Please check OProfile to be installed successfully"; + OprofileComm.showErrorDialog(error, reason , e); //$NON-NLS-1$ + } catch (InterruptedException e) { + String error = "The OProfile kernel module could not be loaded"; + String reason = "An error occurred initializing OProfile for use with the plugin. Please check OProfile to be installed successfully"; + OprofileComm.showErrorDialog(error, reason , e); //$NON-NLS-1$ + } + + setCpuType(result[0]); + return !(result[0] == null); + } + + //jinu modified at 20090619 + // initialize oprofile module by calling `opcontrol --init` + /* + private static void _initializeOprofile() { + try { + OprofileCorePlugin.getDefault().getOpcontrolProvider().initModule(); + } catch (OpcontrolException e) { + OprofileCorePlugin.showErrorDialog("opcontrolProvider", e); //$NON-NLS-1$ + } + } + */ + private static void _initializeOprofile() throws OpcontrolException{ + OprofileCorePlugin.getDefault().getOpcontrolProvider().initModule(); + } + + // Initializes static data for oprofile. + private static void _initializeOprofileCore () { + //jinu modified at 20090622 + //_info = OpInfo.getInfo(); + _info = OprofileComm.getEventInfo(); + } + + + /** + * Queries oprofile for the number of counters on the current CPU. + * Used only in launch config tabs. + * @return the number of counters + */ + public static int getNumberOfCounters() { + //jinu modified at 20090622 + //return _info.getNrCounters(); + return getOpInfo().getNrCounters(); + } + + /** + * Returns the CPU speed of the current configuration. + * @return the cpu speed in MHz + */ + public static double getCpuFrequency() { + //jinu modified at 20090622 + //return _info.getCPUSpeed(); + return getOpInfo().getCPUSpeed(); + } + + /** + * Finds the event with the given name + * @param name the event's name (i.e., CPU_CLK_UNHALTED) + * @return the event or null if not found + */ + public static OpEvent findEvent(String name) { + //jinu modified at 20090622 + //return _info.findEvent(name); + return getOpInfo().findEvent(name); + } + + /** + * Get all the events that may be collected on the given counter. + * @param num the counter number + * @return an array of all valid events -- NEVER RETURNS NULL! + */ + public static OpEvent[] getEvents(int num) { + //jinu modified at 20090622 + //return _info.getEvents(num); + return getOpInfo().getEvents(num); + } + + /** + * Returns the default location of the oprofile samples directory. + * @return the default samples directory + */ + public static String getDefaultSamplesDirectory() { + //jinu modified at 20090622 + //return _info.getDefault(OpInfo.DEFAULT_SAMPLE_DIR); + return getOpInfo().getDefault(OpInfo.DEFAULT_SAMPLE_DIR); + } + + /** + * Returns the oprofile daemon log file. + * @return the log file (absolute pathname) + */ + public static String getLogFile() { + //jinu modified at 20090622 + //return _info.getDefault(OpInfo.DEFAULT_LOG_FILE); + return getOpInfo().getDefault(OpInfo.DEFAULT_LOG_FILE); + } + + /** + * Returns whether or not oprofile is in timer mode. + * @return true if oprofile is in timer mode, false otherwise + */ + public static boolean getTimerMode() { + //jinu modified at 20090622 + //return _info.getTimerMode(); + return getOpInfo().getTimerMode(); + } + + /** + * Checks the requested counter, event, and unit mask for vailidity. + * @param ctr the counter + * @param event the event number + * @param um the unit mask + * @return whether the requested event is valid + */ + public static Boolean checkEvent(int ctr, int event, int um) { + int[] validResult = new int[1]; + try { + IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().checkEvents(ctr, event, um, validResult); + opxml.run(null); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (OpxmlException e) { + OprofileCorePlugin.showErrorDialog("opxmlProvider", e); //$NON-NLS-1$ + return null; + } + + return (validResult[0] == CheckEventsProcessor.EVENT_OK); + } + + + + /** + * Returns a list of all the events collected on the system, as well as + * the sessions under each of them. + * @returns a list of all collected events + */ + public static OpModelEvent[] getEvents() { + OpModelEvent[] events = null; + + ArrayList sessionList = new ArrayList(); + try { + IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().sessions(sessionList); + opxml.run(null); + events = new OpModelEvent[sessionList.size()]; + sessionList.toArray(events); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (OpxmlException e) { + OprofileCorePlugin.showErrorDialog("opxmlProvider", e); //$NON-NLS-1$ + } + return events; + } + + + /** + * Return a list of all the Samples in the given session. + * @param session the session for which to get samples + * @param shell the composite shell to use for the progress dialog + */ + public static OpModelImage getModelData(String eventName, String sessionName) { + OpModelImage image = new OpModelImage(); + + final IRunnableWithProgress opxml; + try { + opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().modelData(eventName, sessionName, image); + opxml.run(null); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (OpxmlException e) { + OprofileCorePlugin.showErrorDialog("opxmlProvider", e); //$NON-NLS-1$ + return null; + } + + return image; + } + + + + + + + //jinu added at 20090604 ----------------------------- + public static void initialize(){ + if(_info != null) + _info = null; + } + + public static OpInfo getOpInfo(){ + try { + if(_info==null||isValid(_info)) + initializeOprofileModule(); + } catch (OpcontrolException e) { + e.printStackTrace(); + } + + return _info; + } + + private static boolean isValid(OpInfo info){ + return info.getNrCounters()==0 ^ info.getTimerMode(); + } + + private static String _cpuType; + public static String getCpuType() { + return _cpuType; + } + public static void setCpuType(String cpuType) { + _cpuType = cpuType; + } + //------------------------------------ + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OprofileCorePlugin.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OprofileCorePlugin.java new file mode 100644 index 0000000..bea8799 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OprofileCorePlugin.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.linuxtools.oprofile.core.linux.LinuxOpcontrolProvider; +import org.eclipse.linuxtools.oprofile.core.linux.LinuxOpxmlProvider; +import org.eclipse.swt.widgets.Display; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class OprofileCorePlugin extends Plugin { + private static final String PLUGIN_ID = "org.eclipse.linuxtools.oprofile.core"; //$NON-NLS-1$ +// private static final String OPXMLPROVIDER_XPT_NAME = "OpxmlProvider"; //$NON-NLS-1$ + + //The shared instance. + private static OprofileCorePlugin plugin; + private IOpxmlProvider _opxmlProvider; +// private OpcontrolDataProvider _opcontrolDataProvider; + + /** + * The constructor. + */ + public OprofileCorePlugin() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static OprofileCorePlugin getDefault() { + return plugin; + } + + /** + * Returns the unique id of this plugin. Should match plugin.xml! + */ + public static String getId() { + return PLUGIN_ID; + } + + /** + * Returns the OpxmlProvider registered with the plugin or throws an exception + * @return the OpxmlProvider + * @throws OpxmlException + */ + public IOpxmlProvider getOpxmlProvider() throws OpxmlException { + //jinu modified at 20090526 + /* + Exception except = null; + + if (_opxmlProvider == null) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extension = registry.getExtensionPoint(PLUGIN_ID, OPXMLPROVIDER_XPT_NAME); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (IExtension e : extensions) { + IConfigurationElement[] configElements = e.getConfigurationElements(); + if (configElements.length != 0) { + try { + _opxmlProvider = (IOpxmlProvider) configElements[0].createExecutableExtension("class"); //$NON-NLS-1$ + if (_opxmlProvider != null) + break; + } catch (CoreException ce) { + except = ce; + } + } + } + } + } + + // If there was a problem finding opxml, throw an exception + if (_opxmlProvider == null) { + throw new OpxmlException(createErrorStatus("opxmlProvider", except)); //$NON-NLS-1$ + } else { + return _opxmlProvider; + } + */ + if(_opxmlProvider==null) + _opxmlProvider = new LinuxOpxmlProvider(); + + return _opxmlProvider; + } + + + /*public OpcontrolDataProvider getOpcontrolDataProvider() throws OpcontrolException { + if(_opcontrolDataProvider==null) + _opcontrolDataProvider = new OpcontrolDataProvider(); + + return _opcontrolDataProvider; + }*/ + + /** + * Returns the registered opcontrol provider or throws an exception + * @return the OpcontrolProvider registered with the plugin + * @throws OpcontrolException + */ + public IOpcontrolProvider getOpcontrolProvider() throws OpcontrolException { + //jinu modified at 20090526 + /* + Exception except = null; + + if (_opcontrol == null) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extension = registry.getExtensionPoint(PLUGIN_ID, "OpcontrolProvider"); //$NON-NLS-1$ + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + IConfigurationElement[] configElements = extensions[0].getConfigurationElements(); + if (configElements.length != 0) { + try { + _opcontrol = (IOpcontrolProvider) configElements[0].createExecutableExtension("class"); //$NON-NLS-1$ + } catch (CoreException ce) { + except = ce; + } + } + } + } + + // If there was a problem finding opcontrol, throw an exception + if (_opcontrol == null) { + String msg = getResourceString("opcontrolProvider.error.missing"); //$NON-NLS-1$ + Status status = new Status(IStatus.ERROR, getId(), IStatus.OK, msg, except); + throw new OpcontrolException(status); + } + + return _opcontrol; + */ + + return new LinuxOpcontrolProvider(); + } + + public static IStatus createErrorStatus(String errorClassString, Exception e) { + String statusMessage = OprofileProperties.getString(errorClassString + ".error.statusMessage"); //$NON-NLS-1$ + + if (e == null) { + return new Status(IStatus.ERROR, getId(), IStatus.OK, statusMessage, null); + } else { + return new Status(IStatus.ERROR, getId(), IStatus.OK, statusMessage, e); + } + } + + public static void showErrorDialog(String errorClassString, CoreException ex) { + final IStatus status; + final String dialogTitle = OprofileProperties.getString(errorClassString + ".error.dialog.title"); //$NON-NLS-1$ + final String errorMessage = OprofileProperties.getString(errorClassString + ".error.dialog.message"); //$NON-NLS-1$ + + if (ex == null) { + status = createErrorStatus(errorClassString, null); + } else { + status = ex.getStatus(); + } + + //needs to be run in the ui thread otherwise swt throws invalid thread access + Display.getDefault().syncExec(new Runnable() { + public void run() { + ErrorDialog.openError(null, dialogTitle, errorMessage, status); + } + }); + + } + + + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OprofileProperties.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OprofileProperties.java new file mode 100644 index 0000000..f1bf26e --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OprofileProperties.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class OprofileProperties { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.oprofile.core.oprofile"; //$NON-NLS-1$ + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private OprofileProperties() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OpxmlException.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OpxmlException.java new file mode 100644 index 0000000..21b40e0 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/OpxmlException.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; + +/** + * An exception thrown by any of the IOpxmlProvider functions + */ +public class OpxmlException extends CoreException { + + /** + * + */ + private static final long serialVersionUID = 2788304536155025911L; + + /** + * Constructor + * @param status IStatus for the exception + */ + public OpxmlException(IStatus status) { + super(status); + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpEvent.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpEvent.java new file mode 100644 index 0000000..9204f02 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpEvent.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2004, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.daemon; + +/** + * A class which represents an Oprofile event + */ +public class OpEvent { + // The Oprofile event name, i.e., "CPU_CLK_UNHALTED" + private String _name; + + // The Oprofile event number + private int _number; + + // A description of the event + private String _description; + + // Unit masks for this event type + private OpUnitMask _unitMask; + + // Minimum count + private int _minCount; + + /** + * Sets the unit mask for this event. + * Only called from XML parsers. + * @param mask the new unit mask + */ + public void _setUnitMask(OpUnitMask mask) { + _unitMask = mask; + } + + /** + * Sets the name of this event. + * Only called from XML parsers. + * @param text the name + */ + public void _setText(String text) { + _name = text; + } + + /** + * Sets the description of this oprofile event. + * Only called from XML parsers. + * @param text the description + */ + public void _setTextDescription(String text) { + _description = text; + } + + /** + * Sets the minimum count for this event. + * Only called from XML parsers. + * @param min the minimum count + */ + public void _setMinCount(int min) { + _minCount = min; + } + + /** + * Sets oprofile's event number for this event. + * Only called from XML parsers. + * @param num the number + */ + public void _setNumber(int num) { + _number = num; + } + + /** + * Returns the unit mask corresponding to this event. + * @return the unit mask + */ + public OpUnitMask getUnitMask() { + return _unitMask; + } + + /** + * Returns the name of this oprofile event. + * @return the name + */ + public String getText() { + return _name; + } + + /** + * Returns the description of this oprofile event. + * @return the description + */ + public String getTextDescription() { + return _description; + } + + /** + * Returns the minimum count allowed for this event. + * @return the minimum count + */ + public int getMinCount() { + return _minCount; + } + + /** + * Returns oprofile's event number for this event. + * @return the event number + */ + public int getNumber() { + return _number; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java new file mode 100644 index 0000000..4d926eb --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java @@ -0,0 +1,214 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.daemon; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; + +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.OpxmlException; +import org.eclipse.linuxtools.oprofile.core.opxml.info.DefaultsProcessor; + + +/** + * A class to hold generic information about Oprofile. + */ +public class OpInfo { + // Oprofile defaults + public static final String DEFAULT_SAMPLE_DIR = DefaultsProcessor.SAMPLE_DIR; + public static final String DEFAULT_LOCK_FILE = DefaultsProcessor.LOCK_FILE; + public static final String DEFAULT_LOG_FILE = DefaultsProcessor.LOG_FILE; //use + public static final String DEFAULT_DUMP_STATUS = DefaultsProcessor.DUMP_STATUS; + + // A comparator class used when sorting events + // (sorting by event name) + private static class SortEventComparator implements Comparator { + public int compare(OpEvent o1, OpEvent o2) { + return o1.getText().compareTo(o2.getText()); + } + } + + // A comparator class used when searching events + // (searching by event name) + private static class SearchEventComparator implements Comparator { + public int compare(Object a, Object b) { + String astr, bstr; + if (a instanceof String) { + astr = (String) a; + bstr = ((OpEvent) b).getText(); + } else { + astr = ((OpEvent) a).getText(); + bstr = (String) b; + } + return astr.compareTo(bstr); + } + } + + // The number of counters supported by this configuration + private int _nrCounters; + + // A HashMap of Oprofile defaults + private HashMap _defaults; + + // The permanent list of events indexed by counter + private OpEvent[][] _eventList; + + // The CPU frequency of this CPU in MHz + private double _cpuSpeed; + + // Whether or not oprofile is running in timer mode + private boolean _timerMode; + + /** + * Return all of Oprofile's generic information. + * @return a class containing the information + */ + public static OpInfo getInfo() { + // Run opmxl and get the static information + OpInfo info = new OpInfo(); + + try { + IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().info(info); + opxml.run(null); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (OpxmlException e) { + OprofileCorePlugin.showErrorDialog("opxmlProvider", e); //$NON-NLS-1$ + } + + return info; + } + + /** + * Sets the number of counters allowed by Oprofile. This method is called + * after this object is contstructed, while opxml is run (the first tag output + * is num-counters). + * Only called from XML parsers. + * @param ctrs the number of counters + */ + public void _setNrCounters(int ctrs) { + _nrCounters = ctrs; + + // Allocate room for event lists for the counters + _eventList = new OpEvent[_nrCounters][]; + } + + /** + * Set the CPU frequency (in MHz). + * Only called from the XML parsers. + * @param freq the frequency + */ + public void _setCPUSpeed(double freq) { + _cpuSpeed = freq; + } + + /** + * Sets the defaults associated with this configuration of Oprofile. + * Only called from XML parsers. + * @param map the HashMap containing the defaults + */ + public void _setDefaults(HashMap map) { + _defaults = map; + } + + /** + * Adds the events of the counter counterNum into the list of all events. + * Note they are sorted here. + * Only called from XML parsers. + * @param counterNum the counter with the events + * @param events an array of OpEvent events belonging to this counter + */ + public void _setEvents(int counterNum, OpEvent[] events) { + if (counterNum < _eventList.length) { + _eventList[counterNum] = events; + Arrays.sort(_eventList[counterNum], new SortEventComparator()); + } + } + + /** + * Sets whether or not oprofile is operating in timer mode. + * Only called from XML parsers. + * @param timerMode true if oprofile is in timer mode, false if not + */ + public void _setTimerMode(boolean timerMode) { + _timerMode = timerMode; + } + + /** + * Returns the number of counters allowed by Oprofile + * @return the number of counters + */ + public int getNrCounters() { + return _nrCounters; + } + + /** + * Returns the CPU's speed in MHz + * @return the speed + */ + public double getCPUSpeed() { + return _cpuSpeed; + } + + /** + * Returns the requested default. Valid defaults are DEFAULT_DUMP_STATUS, + * DEFAULT_LOCK_FILE, DEFAULT_LOG_FILE, and + * DEFAULT_SAMPLE_DIR. + * @param what which default to return + * @return the requested default or null if not known + */ + public String getDefault(String what) { + return (String) _defaults.get(what); + } + + /** + * Returns an array of events valid for the given counter number. + * @param num the counter number + * @return an array of valid events + */ + public OpEvent[] getEvents(int num) { + if (num >= 0 && num < _eventList.length) + return _eventList[num]; + + return new OpEvent[0]; + } + + /** + * Returns whether or not oprofile is operating in timer mode. + * @return a boolean, true if in timer mode, false if not + */ + public boolean getTimerMode() { + return _timerMode; + } + + /** + * Searches the for the event with the given name + * @param name the name of the event (e.g., CPU_CLK_UNHALTED) + * @return the event or null if not found + */ + public OpEvent findEvent(String name) { + // Search through all counters + for (int counter = 0; counter < getNrCounters(); ++counter) { + int idx = Arrays.binarySearch(getEvents(counter), name, new SearchEventComparator()); + if (idx >= 0) + return _eventList[counter][idx]; + } + + return null; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpUnitMask.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpUnitMask.java new file mode 100644 index 0000000..050cf0f --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpUnitMask.java @@ -0,0 +1,244 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.daemon; + +/** + * A class representing the unit mask that may be associated with oprofile + * events. Note that since this class was originally written, oprofile unit + * masks have changed -- a single unit mask may affect several bits at once. + * Hence, instead of a certain bit being flipped, the specific bits to be changed + * are determined by the particular mask's index + */ +public class OpUnitMask { + /** + * A class which describes an individual unit mask value. Used in XML parsing. + */ + public static class MaskInfo { + /** + * The integer value of the mask. + */ + public int value; + + /** + * A description of the mask. + */ + public String description; + }; + + public static final int SET_DEFAULT_MASK = -1; + + /** + * Invalid mask type. + */ + public static final int INVALID = -1; + + /** + * The mask is mandatory. It must be used. + */ + public static final int MANDATORY = 1; + + /** + * The mask is exclusive. Only one of its mask values may be used. + */ + public static final int EXCLUSIVE = 2; + + /** + * The mask is a bitmask. Any combination of its values may be used. + */ + public static final int BITMASK = 3; + + + // The current value of this unitmask + private int _mask; + + // The default mask provided by the oprofile library + private int _defaultMask; + + // The type of this unitmask + private int _maskType; + + // Descriptions of the bits of this mask + private String[] _maskOptionDescriptions = new String[0]; + + // mask values -- now bit masks have distinct values (eg: an all of the + // above) + private int[] _maskOptionValues; + + /** + * Set the descriptions and values for this unitmask's mask options. + * Only used from the XML parsers. + * @param masks a list of all the mask options + */ + public void _setMaskDescriptions(MaskInfo[] masks) { + _maskOptionDescriptions = new String[masks.length]; + _maskOptionValues = new int[masks.length]; + + for (int i = 0; i < masks.length; ++i) { + _maskOptionDescriptions[i] = masks[i].description; + _maskOptionValues[i] = masks[i].value; + } + } + + /** + * Sets the default value for this unitmask, and initializes + * the current unitmask value to this default. + * Only used from the XML parsers. + * @param theDefault the default value + */ + public void _setDefault(int theDefault) { + _defaultMask = theDefault; + setDefaultMaskValue(); + } + + /** + * Sets the unitmask type. + * Only used from the XML parsers. + * @param type the type + */ + public void _setType(int type) { + _maskType = type; + } + + /** + * Returns the integer value of this unitmask, suitable for passing to oprofile. + * @return the integer value + */ + public int getMaskValue() { + return _mask; + } + + /** + * Tests whether a particular mask is set in the unitmask value, based on the + * value of the mask option at the given index. + * + * @param index the index of the mask option to check + * @return whether the given mask option's value is set + */ + public boolean isMaskSetFromIndex(int index) { + boolean result = false; + + if (index >= 0 && index < _maskOptionValues.length) { + switch (_maskType) { + case EXCLUSIVE: + result = (_mask == _maskOptionValues[index]); + break; + + case BITMASK: + result = ((_mask & _maskOptionValues[index]) != 0); + break; + + default: + result = false; + } + } + + return result; + } + + /** + * Sets the absolute unitmask value. + * + * @param newValue the new value of this unitmask + */ + public void setMaskValue(int newValue) { + if (newValue == SET_DEFAULT_MASK) { + _mask = _defaultMask; + } else { + _mask = newValue; + } + } + + /** + * Sets the bits of the given mask option's value in the unitmask value. + * @param index the index of the mask option to set + */ + public void setMaskFromIndex(int index) { + //mandatory masks only use the default value + if (index >= 0 && index < _maskOptionValues.length) { + if (_maskType == BITMASK) + _mask |= _maskOptionValues[index]; + else if (_maskType == EXCLUSIVE) { + _mask = _maskOptionValues[index]; + } + } + } + + /** + * Returns the value of the mask based on the unitmask index. + * @param index the index of the mask option + * @return the mask option's value + */ + public int getMaskFromIndex(int index) { + //mandatory masks only use the default value + if (_maskType == BITMASK) { + if (index >= 0 && index < _maskOptionValues.length) { + return _maskOptionValues[index]; + } + } else if (_maskType == EXCLUSIVE) { + if (index >= 0 && index < _maskOptionValues.length) { + return _maskOptionValues[index]; + } + } else if (_maskType == MANDATORY) { + return _defaultMask; + } + + //type invalid or unknown, or out of bounds + return -1; + } + + /** + * Unset the bits of the given mask option's value in the unitmask value. + * @param index the index of the mask option to set + */ + public void unSetMaskFromIndex(int index) { + if (index >= 0 && index < _maskOptionValues.length && _maskType == BITMASK) { + _mask = _mask & ~_maskOptionValues[index]; + } + } + + /** + * Sets the current unitmask value to the default mask value. + */ + public void setDefaultMaskValue() { + _mask = _defaultMask; + } + + /** + * Returns a description of the requested mask option. + * @param num the mask option index + * @return the description + */ + public String getText(int num) { + if (num >= 0 && num < _maskOptionDescriptions.length) + return _maskOptionDescriptions[num]; + + return null; + } + + /** + * Returns the number of mask options in this unitmask. + * @return the number of mask options + */ + public int getNumMasks() { + return _maskOptionDescriptions.length; + } + + /** + * Returns the mask type for this unit mask. + * @return BITMASK, EXCLUSIVE, or + * MANDATORY + */ + public int getType() { + return _maskType; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OprofileDaemonEvent.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OprofileDaemonEvent.java new file mode 100644 index 0000000..34ae43e --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OprofileDaemonEvent.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.daemon; + +import org.eclipse.linuxtools.oprofile.core.Oprofile; + +/** + * This class represents an event used to configure the OProfile + * daemon. + */ +public class OprofileDaemonEvent { + public static final int COUNT_UNINITIALIZED = 0; + public static final int COUNT_INVALID = -1; + + // The event to collect on this counter + private OpEvent _event; + + // Profile kernel? + private boolean _profileKernel; + + // Profile userspace? + private boolean _profileUser; + + // Reset counter value + private int _count; + + public OprofileDaemonEvent() { + _profileKernel = true; + _profileUser = true; + _count = COUNT_UNINITIALIZED; + _event = null; + } + + /** + * Set the event to collect + * @param event the OProfile event + */ + public void setEvent(OpEvent event) { + _event = event; + } + + /** + * Get the event to collect + * @returns the OProfile event + */ + public OpEvent getEvent() { + return _event; + } + + /** + * Set whether to profile the kernel + * @param profileKernel whether to enable kernel profiling + */ + public void setProfileKernel(boolean profileKernel) { + _profileKernel = profileKernel; + } + + /** + * Get whether to profile the kernel + * @return whether to profile the kernel + */ + public boolean getProfileKernel() { + return _profileKernel; + } + + /** + * Set whether to profile userspace + * @param profileUser whether to profile userspace + */ + public void setProfileUser(boolean profileUser) { + _profileUser = profileUser; + } + + /** + * Get whether to profile userspace + * @return whether to profile userspace + */ + public boolean getProfileUser() { + return _profileUser; + } + + /** + * Set the reset count + * @param count the new count + */ + public void setResetCount(int count) { + _count = count; + } + + /** + * Get the reset count + * @return the reset count + */ + public int getResetCount() { + // FIXME: This isn't quite in the right place... + if (_count == COUNT_UNINITIALIZED) { + // This is what Oprofile does in oprof_start.cpp: + double speed = Oprofile.getCpuFrequency(); + if (speed == 0.0) { + _count = _event.getMinCount() * 30; + } else { + _count = (int) speed * 20; + } + } + + return _count; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OprofileDaemonOptions.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OprofileDaemonOptions.java new file mode 100644 index 0000000..358ea27 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OprofileDaemonOptions.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.daemon; + + +/** + * This class represents the global launch options for the + * OProfile daemon. + */ +public class OprofileDaemonOptions { + // Kernel image file + private String _kernelImageFile; + + // Enable verbose logging? + private boolean _verboseLogging; + + // How to separate profiles (mask) + private int _separateProfiles; + + // the image to profile + private String _binaryImage; + + //how many calls down to profile + private int _callgraphDepth; + + /** + * Sample separation options. Determines how oprofiled will group + * samples for binaries which isn't the main binary being profiled. + * + * Currently only properly support: + * -none: ignore all other binaries + * -library: include shared library samples + * -kernel: include kernel module samples (which implicitly includes library) + * + * the others probably wouldn't show nicely in the view + */ + public static final int SEPARATE_NONE = 0; + public static final int SEPARATE_LIBRARY = 1; + public static final int SEPARATE_KERNEL = 2; + public static final int SEPARATE_THREAD = 4; + public static final int SEPARATE_CPU = 8; + + public OprofileDaemonOptions() { + //defaults +// _kernelImageFile = Oprofile.getKernelImageFile(); + _kernelImageFile = ""; //$NON-NLS-1$ + _verboseLogging = false; + + //jinu modified at 20090526 +// _separateProfiles = SEPARATE_NONE; + _separateProfiles = SEPARATE_LIBRARY; + _binaryImage = ""; //$NON-NLS-1$ + _callgraphDepth = 0; + } + + /** + * Get the kernel image file + * @return the kernel image file + */ + public String getKernelImageFile() { + return _kernelImageFile; + } + + /** + * Set the kernel image file + * @param image the kernel image + */ + public void setKernelImageFile(String image) { + _kernelImageFile = image; + } + + /** + * Get daemon verbose logging + * @return whether verbose logging is enabled + */ + public boolean getVerboseLogging() { + return _verboseLogging; + } + + /** + * Set daemon verbose logging + * @param logging whether to enable verbose logging + */ + public void setVerboseLogging(boolean logging) { + _verboseLogging = logging; + } + + /** + * Get daemon profile separation mask + * @return mask of options + */ + public int getSeparateProfilesMask() { + return _separateProfiles; + } + + /** + * Set daemon profile separation mask + * @param mask the new separation mask + */ + public void setSeparateProfilesMask(int mask) { + _separateProfiles = mask; + } + + /** + * Get the path to the binary image being profiled. + * @return full path to the binary + */ + public String getBinaryImage() { + return _binaryImage; + } + + /** + * Sets the path of the binary image to profile. + * @param _image full path to the binary + */ + public void setBinaryImage(String _image) { + this._binaryImage = _image; + } + + /** + * Get the call depth value. + * @return integer amount of calls down to profile + */ + public int getCallgraphDepth() { + return _callgraphDepth; + } + + /** + * Sets the call depth value. + * @param depth integer amount of calls down to profile + */ + public void setCallgraphDepth(int depth) { + this._callgraphDepth = depth; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java new file mode 100644 index 0000000..a59516b --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java @@ -0,0 +1,425 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.linux; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.IOpcontrolProvider; +import org.eclipse.linuxtools.oprofile.core.OpcontrolException; +import org.eclipse.linuxtools.oprofile.core.Oprofile; +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonOptions; + +import org.tizen.common.connection.ConnectionPlugin; +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileComm; +import org.tizen.oprofile.core.OprofileCommonConstants; + +/** + * A class which encapsulates running opcontrol. + */ +public class LinuxOpcontrolProvider implements IOpcontrolProvider { + // Location of opcontrol security wrapper + // private static final String _OPCONTROL_REL_PATH = "natives/linux/scripts/opcontrol"; //$NON-NLS-1$ + private final String OPCONTROL_PROGRAM; + + // Initialize the Oprofile kernel module and oprofilefs + private static final String _OPD_INIT_MODULE = "--init"; //$NON-NLS-1$ + + // Setup daemon collection arguments + private static final String _OPD_SETUP = "--setup"; //$NON-NLS-1$ + private static final String _OPD_SETUP_SEPARATE = "--separate="; //$NON-NLS-1$ + private static final String _OPD_SETUP_SEPARATE_SEPARATOR = ","; //$NON-NLS-1$ + // private static final String _OPD_SETUP_SEPARATE_NONE = "none"; //$NON-NLS-1$ + private static final String _OPD_SETUP_SEPARATE_LIBRARY = "library"; //$NON-NLS-1$ + private static final String _OPD_SETUP_SEPARATE_KERNEL = "kernel"; //$NON-NLS-1$ + private static final String _OPD_SETUP_SEPARATE_THREAD = "thread"; //$NON-NLS-1$ + private static final String _OPD_SETUP_SEPARATE_CPU = "cpu"; //$NON-NLS-1$ + + private static final String _OPD_SETUP_EVENT = "--event="; //$NON-NLS-1$ + private static final String _OPD_SETUP_EVENT_SEPARATOR = ":"; //$NON-NLS-1$ + private static final String _OPD_SETUP_EVENT_TRUE = "1"; //$NON-NLS-1$ + private static final String _OPD_SETUP_EVENT_FALSE = "0"; //$NON-NLS-1$ + private static final String _OPD_SETUP_EVENT_DEFAULT = "default"; //$NON-NLS-1$ + + private static final String _OPD_SETUP_IMAGE = "--image="; //$NON-NLS-1$ + + private static final String _OPD_CALLGRAPH_DEPTH = "--callgraph="; //$NON-NLS-1$ + + // Kernel image file options + private static final String _OPD_KERNEL_NONE = "--no-vmlinux"; //$NON-NLS-1$ + private static final String _OPD_KERNEL_FILE = "--vmlinux="; //$NON-NLS-1$ + + // Logging verbosity + // private static final String _OPD_VERBOSE_LOGGING = "--verbose="; + // //$NON-NSL-1$ + // private static final String _OPD_VERBOSE_ALL = "all"; //$NON-NLS-1$ + // private static final String _OPD_VERBOSE_SFILE = "sfile"; //$NON-NLS-1$ + // private static final String _OPD_VERBOSE_ARCS = "arcs"; //$NON-NLS-1$ + // private static final String _OPD_VERBOSE_SAMPLES = "samples"; //$NON-NLS-1$ + // private static final String _OPD_VERBOSE_MODULE = "module"; //$NON-NLS-1$ + // private static final String _OPD_VERBOSE_MISC = "misc"; //$NON-NLS-1$ + + // Start the daemon process without starting data collection + private static final String _OPD_START_DAEMON = "--start-daemon"; //$NON-NLS-1$ + + // Start collecting profiling data + private static final String _OPD_START_COLLECTION = "--start"; //$NON-NLS-1$ + + // Flush the collected profiling data to disk + private static final String _OPD_DUMP = "--dump"; //$NON-NLS-1$ + + // Stop data collection + private static final String _OPD_STOP_COLLECTION = "--stop"; //$NON-NLS-1$ + + // Stop data collection and stop daemon + private static final String _OPD_SHUTDOWN = "--shutdown"; //$NON-NLS-1$ + + // Clear out data from current session + private static final String _OPD_RESET = "--reset"; //$NON-NLS-1$ + + // Save data from the current session + private static final String _OPD_SAVE_SESSION = "--save="; //$NON-NLS-1$ + + // Unload the oprofile kernel module and oprofilefs + private static final String _OPD_DEINIT_MODULE = "--deinit"; //$NON-NLS-1$ + + // Logging verbosity. Specified with setupDaemon. + // --verbosity=all generates WAY too much stuff in the log + private String _verbosity = ""; //$NON-NLS-1$ + + public LinuxOpcontrolProvider() throws OpcontrolException { + // jinu modified at 20090526 + // OPCONTROL_PROGRAM = _findOpcontrol(); + OPCONTROL_PROGRAM = OprofileCommonConstants.COMMAND_OPCONTROL; + } + + /** + * Unload the kernel module and oprofilefs + * + * @throws OpcontrolException + */ + public void deinitModule() throws OpcontrolException { + _runOpcontrol(_OPD_DEINIT_MODULE); + } + + /** + * Dump collected profiling data + * + * @throws OpcontrolException + */ + public void dumpSamples() throws OpcontrolException { + _runOpcontrol(_OPD_DUMP); + } + + /** + * Loads the kernel module and oprofilefs + * + * @throws OpcontrolException + */ + public void initModule() throws OpcontrolException { + _runOpcontrol(_OPD_INIT_MODULE); + } + + /** + * Clears out data from current session + * + * @throws OpcontrolException + */ + public void reset() throws OpcontrolException { + _runOpcontrol(_OPD_RESET); + } + + /** + * Saves the current ("default") session + * + * @param name + * the name to which to save the session + * @throws OpcontrolException + */ + public void saveSession(String name) throws OpcontrolException { + ArrayList cmd = new ArrayList(); + cmd.add(_OPD_SAVE_SESSION + name); + _runOpcontrol(cmd); + } + + /** + * Give setup aruments + * + * @param args + * list of parameters for daemon + * @throws OpcontrolException + */ + public void setupDaemon(OprofileDaemonOptions options, + OprofileDaemonEvent[] events) throws OpcontrolException { + // Convert options & events to arguments for opcontrol + ArrayList args = new ArrayList(); + args.add(_OPD_SETUP); + _optionsToArguments(args, options); + if (!Oprofile.getTimerMode()) { + if (events == null || events.length == 0) { + args.add(_OPD_SETUP_EVENT + _OPD_SETUP_EVENT_DEFAULT); + } else { + for (int i = 0; i < events.length; ++i) { + _eventToArguments(args, events[i]); + } + } + } + _runOpcontrol(args); + } + + // jinu added at 20090602 + public void setupDaemon(OprofileDaemonOptions options, + OprofileDaemonEvent[] events, String defaultEvent) + throws OpcontrolException { + // Convert options & events to arguments for opcontrol + ArrayList args = new ArrayList(); + args.add(_OPD_SETUP); + _optionsToArguments(args, options); + if (!Oprofile.getTimerMode()) { + if (events == null || events.length == 0) { + // jinu modified at 20090602 + // args.add(_OPD_SETUP_EVENT + _OPD_SETUP_EVENT_DEFAULT); + if(null != defaultEvent) + args.add(defaultEvent); + } else { + for (int i = 0; i < events.length; ++i) { + _eventToArguments(args, events[i]); + } + } + } + _runOpcontrol(args); + } + + /** + * Stop data collection and remove daemon + * + * @throws OpcontrolException + */ + public void shutdownDaemon() throws OpcontrolException { + _runOpcontrol(_OPD_SHUTDOWN); + } + + /** + * Start data collection (will start daemon if necessary) + * + * @throws OpcontrolException + */ + public void startCollection() throws OpcontrolException { + _runOpcontrol(_OPD_START_COLLECTION); + } + + /** + * Start daemon without starting profiling + * + * @throws OpcontrolException + */ + public void startDaemon() throws OpcontrolException { + _runOpcontrol(_OPD_START_DAEMON); + } + + /** + * Stop data collection + * + * @throws OpcontrolException + */ + public void stopCollection() throws OpcontrolException { + _runOpcontrol(_OPD_STOP_COLLECTION); + } + + // Convenience function + private void _runOpcontrol(String cmd) throws OpcontrolException { + ArrayList list = new ArrayList(); + list.add(cmd); + _runOpcontrol(list); + } + + // Will add opcontrol program to beginning of args + // args: list of opcontrol arguments (not including opcontrol program + // itself) + private void _runOpcontrol(ArrayList args) + throws OpcontrolException { + args.add(0, OPCONTROL_PROGRAM); + // Verbosity hack. If --start or --start-daemon, add verbosity, if set + String cmd = (String) args.get(1); + if (_verbosity.length() > 0 + && (cmd.equals(_OPD_START_COLLECTION) || cmd + .equals(_OPD_START_DAEMON))) { + args.add(_verbosity); + } + + String[] cmdArray = new String[args.size()]; + args.toArray(cmdArray); + + // jinu modified at 20090526 + runCommand(cmdArray); + /* + * Process p = null; try { p = Runtime.getRuntime().exec(cmdArray); } + * catch (IOException ioe) { if (p != null) { p.destroy(); p = null; } + * + * throw new + * OpcontrolException(OprofileCorePlugin.createErrorStatus("opcontrolRun" + * , ioe)); //$NON-NLS-1$ } + * + * if (p != null) { BufferedReader stdout = new BufferedReader(new + * InputStreamReader(p.getErrorStream())); String output = "", s; + * //$NON-NLS-1$ try { while ((s = stdout.readLine()) != null) { output + * += s; } + * + * int ret = p.waitFor(); if (ret != 0) { System.out.println(output); + * throw new OpcontrolException(OprofileCorePlugin.createErrorStatus( + * "opcontrolNonZeroExitCode", null)); //$NON-NLS-1$ } } catch + * (IOException ioe) { ioe.printStackTrace(); } catch + * (InterruptedException e) { e.printStackTrace(); } } + */ + } + + // private static String _findOpcontrol() throws OpcontrolException { + // URL url = + // FileLocator.find(Platform.getBundle(OprofileCorePlugin.getId()), new + // Path(_OPCONTROL_REL_PATH), null); + // + // if (url != null) { + // try { + // return FileLocator.toFileURL(url).getPath(); + // } catch (IOException ignore) { } + // } else { + // throw new OpcontrolException(OprofileCorePlugin.createErrorStatus("opcontrolProvider", null)); //$NON-NLS-1$ + // } + // + // return null; + // } + + // Convert the event into arguments for opcontrol + private void _eventToArguments(ArrayList args, + OprofileDaemonEvent event) { + // Event spec: "EVENT:count:mask:profileKernel:profileUser" + String spec = new String(_OPD_SETUP_EVENT); + spec += event.getEvent().getText(); + spec += _OPD_SETUP_EVENT_SEPARATOR; + spec += event.getResetCount(); + spec += _OPD_SETUP_EVENT_SEPARATOR; + spec += event.getEvent().getUnitMask().getMaskValue(); + spec += _OPD_SETUP_EVENT_SEPARATOR; + spec += (event.getProfileKernel() ? _OPD_SETUP_EVENT_TRUE + : _OPD_SETUP_EVENT_FALSE); + spec += _OPD_SETUP_EVENT_SEPARATOR; + spec += (event.getProfileUser() ? _OPD_SETUP_EVENT_TRUE + : _OPD_SETUP_EVENT_FALSE); + args.add(spec); + } + + // Convert the options into arguments for opcontrol + private void _optionsToArguments(ArrayList args, + OprofileDaemonOptions options) { + // Add separate flags + int mask = options.getSeparateProfilesMask(); + + String separate = new String(_OPD_SETUP_SEPARATE); + + if (mask == OprofileDaemonOptions.SEPARATE_NONE) { + separate += _OPD_SETUP_SEPARATE_LIBRARY + + _OPD_SETUP_SEPARATE_SEPARATOR + + _OPD_SETUP_SEPARATE_KERNEL; + // separate += _OPD_SETUP_SEPARATE_NONE; + } else { + // note that opcontrol will nicely ignore the trailing comma + if ((mask & OprofileDaemonOptions.SEPARATE_LIBRARY) != 0) + separate += _OPD_SETUP_SEPARATE_LIBRARY + + _OPD_SETUP_SEPARATE_SEPARATOR; + if ((mask & OprofileDaemonOptions.SEPARATE_KERNEL) != 0) + separate += _OPD_SETUP_SEPARATE_KERNEL + + _OPD_SETUP_SEPARATE_SEPARATOR; + if ((mask & OprofileDaemonOptions.SEPARATE_THREAD) != 0) + separate += _OPD_SETUP_SEPARATE_THREAD + + _OPD_SETUP_SEPARATE_SEPARATOR; + if ((mask & OprofileDaemonOptions.SEPARATE_CPU) != 0) + separate += _OPD_SETUP_SEPARATE_CPU + + _OPD_SETUP_SEPARATE_SEPARATOR; + } + args.add(separate); + + // Add kernel image + if (options.getKernelImageFile() == null + || options.getKernelImageFile().length() == 0) { + args.add(_OPD_KERNEL_NONE); + } else { + args.add(_OPD_KERNEL_FILE + options.getKernelImageFile()); + } + + // image filter -- always non-null + args.add(_OPD_SETUP_IMAGE + options.getBinaryImage()); + + // callgraph depth + args.add(_OPD_CALLGRAPH_DEPTH + options.getCallgraphDepth()); + } + + // jinu added at 20090528 + public void removeDaemonSetting() throws OpcontrolException { + final String[] _OPD_REMOVE_SETTING = { "rm", "-rf", + "/root/.oprofile/daemonrc" }; + runCommand(_OPD_REMOVE_SETTING); + } + + // jinu added at 20090528 + private void runCommand(String[] comm) throws OpcontrolException { + + String str = OprofileComm.getCommandString(comm); +// String result=null; +// try { +// result = session.run(str); +// session.run(str, null); + if(str.contains(_OPD_START_COLLECTION)){ + str = str + " && echo start_ok"; + } + CommandManager.runShell(str); +/* + } catch (Exception e) { + String devType = null; + if(null == ConnectionPlugin.getDefault().getCurrentDevice()){ + devType = ""; + } + else if (CommandManager.isEmulator()) { + devType = "Emulator"; + } else { + devType = "RealDevice"; + } + throw new OpcontrolException(OprofileCorePlugin.createErrorStatus( + "opcontrolRun (" + devType + ")", e)); //$NON-NLS-1$ + } +*/ + // ----------------------------------- + + // jinu removed at 20090616 + /* + * Process p = null; try { p = Runtime.getRuntime().exec(comm); } catch + * (IOException ioe) { if (p != null) { p.destroy(); p = null; } + * + * throw new + * OpcontrolException(OprofileCorePlugin.createErrorStatus("opcontrolRun" + * , ioe)); //$NON-NLS-1$ } + * + * if (p != null) { BufferedReader stdout = new BufferedReader(new + * InputStreamReader(p.getErrorStream())); String output = "", s; + * //$NON-NLS-1$ try { while ((s = stdout.readLine()) != null) { output + * += s; } + * + * int ret = p.waitFor(); if (ret != 0) { System.out.println(output); + * throw new OpcontrolException(OprofileCorePlugin.createErrorStatus( + * "opcontrolNonZeroExitCode", null)); //$NON-NLS-1$ } } catch + * (IOException ioe) { ioe.printStackTrace(); } catch + * (InterruptedException e) { e.printStackTrace(); } } + */ + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpxmlProvider.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpxmlProvider.java new file mode 100644 index 0000000..2478c80 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpxmlProvider.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.linux; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.linuxtools.oprofile.core.IOpxmlProvider; +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.OpxmlException; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.opxml.OpxmlConstants; +import org.eclipse.linuxtools.oprofile.core.opxml.modeldata.ModelDataProcessor; +import org.eclipse.linuxtools.oprofile.core.opxml.sessions.SessionsProcessor; + +import org.tizen.oprofile.core.OprofileCommonConstants; + +/** + * A class which implements the IOpxmlProvider interface for running opxml. + */ +public class LinuxOpxmlProvider implements IOpxmlProvider { + private String _pathToOpxml; + + public LinuxOpxmlProvider() throws OpxmlException { + _pathToOpxml = _getOpxmlPath(); + + if (_pathToOpxml == null) { + throw new OpxmlException(OprofileCorePlugin.createErrorStatus("opxmlProvider", null)); //$NON-NLS-1$ + } + } + + //jinu modified at 20090526 + //public abstract String _getOpxmlPath(); + public String _getOpxmlPath(){ + String opxmlPath = OprofileCommonConstants.COMMAND_OPXML; + return opxmlPath; + } + + public IRunnableWithProgress info(final OpInfo info) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + OpxmlRunner runner = new OpxmlRunner(_pathToOpxml); + String[] args = new String[] { + OpxmlConstants.OPXML_INFO + }; + runner.run(args, info); + } + }; + + return runnable; + } + + public IRunnableWithProgress modelData(final String eventName, final String sessionName, final OpModelImage image) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + OpxmlRunner runner = new OpxmlRunner(_pathToOpxml); + + String[] args = new String[] { + OpxmlConstants.OPXML_MODELDATA, + eventName, + sessionName + }; + + ModelDataProcessor.CallData data = new ModelDataProcessor.CallData(image); + runner.run(args, data); + } + }; + + return runnable; + } + + public IRunnableWithProgress checkEvents(final int ctr, final int event, final int um, final int[] eventValid) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) { + OpxmlRunner runner = new OpxmlRunner(_pathToOpxml); + String[] args = new String[] { + OpxmlConstants.CHECKEVENTS_TAG, + Integer.toString(ctr), + Integer.toString(event), + Integer.toString(um) + }; + + runner.run(args, eventValid); + } + }; + return runnable; + } + + public IRunnableWithProgress sessions(final ArrayList sessionList) { + + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) { + OpxmlRunner runner = new OpxmlRunner(_pathToOpxml); + String[] args = new String[] { + OpxmlConstants.OPXML_SESSIONS, + }; + + SessionsProcessor.SessionInfo sinfo = new SessionsProcessor.SessionInfo(sessionList); + runner.run(args, sinfo); + } + }; + + return runnable; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java new file mode 100644 index 0000000..1331f08 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.linux; + +import java.io.IOException; +import java.io.StringReader; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; + +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.OpxmlException; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileComm; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchPlugin; + +/** + * This class will run opxml. + * + * opxml is a small program which acts as a textual interface between Oprofile and + * BFD and the oprofile plugins. + */ +public class OpxmlRunner { + private OprofileSAXHandler _handler; + private String _pathToOpxml; + + public OpxmlRunner(String pathToOpxml) { + //assume that the path given is valid + _pathToOpxml = pathToOpxml; + } + + /** + * Returns the current XMLProcessor handling parsing of opxml output. + * @return the processor + */ + public XMLProcessor getProcessor() { + return _handler.getProcessor(); + } + + /** + * Runs opxml with the given arguments. + * @param args the arguments to pass to opxml + * @param callData any callData to pass to the processor + * @return boolean indicating the success/failure of opxml + * @throws OpxmlException + */ + public boolean run(String[] args, Object callData) { + XMLReader reader = null; + _handler = OprofileSAXHandler.getInstance(callData); + + // Create XMLReader + SAXParserFactory factory = SAXParserFactory.newInstance(); + try { + reader = factory.newSAXParser().getXMLReader(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + return false; + } catch (SAXException e) { + e.printStackTrace(); + return false; + } + + // Set content/error handlers + reader.setContentHandler(_handler); + reader.setErrorHandler(_handler); + + // Setup args + String[] cmdArray = new String[args.length + 1]; + cmdArray[0] = _pathToOpxml; + System.arraycopy(args, 0, cmdArray, 1, args.length); + + + // Run opxml + try { + //jinu added at 20090604 -------------------------- + if(ProfileLaunchPlugin.checkTarget() == 0) return false; + //ISession session =OprofileComm.getSession(); + + String command = OprofileComm.getCommandString(cmdArray)+" | sed 's/^[^<]*//' | sed 's/&//'"; + //String str = session.run(command, null); + String str = CommandManager.runCommandReturningResult(command); + + reader.parse(new InputSource(new StringReader(str))); + + //jinu removed at 20090616 + /* + // before procedure + Process p = Runtime.getRuntime().exec(cmdArray); + + BufferedReader bi = new BufferedReader(new InputStreamReader(p.getInputStream())); + reader.parse(new InputSource(bi)); + + if (p.waitFor() != 0) { + //System.out.println("error running opxml"); + return false; + } + */ + + return true; + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { +// System.out.println("IOException: " + e.getMessage()); + e.printStackTrace(); + OprofileCorePlugin.showErrorDialog("opxmlIOException", null); //$NON-NLS-1$ + //jinu added at 20090604 + } catch (Exception e) { + e.printStackTrace(); + OprofileCorePlugin.showErrorDialog("opxmlIOException", null); //$NON-NLS-1$ + } + + return false; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelEvent.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelEvent.java new file mode 100644 index 0000000..bd4fab7 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelEvent.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.model; + +/** + * A class which represents the event collected in a given session. + */ +public class OpModelEvent { + private String _eventName; + private OpModelSession[] _sessions; + private String _printTabs = ""; //for nice output //$NON-NLS-1$ + + public OpModelEvent(String name) { + _eventName = name; + } + + public OpModelSession[] getSessions() { + return _sessions; + } + + public void _setSessions(OpModelSession[] sessions) { + _sessions = sessions; + } + + public String getName() { + return _eventName; + } + + //populate all sessions + public void refreshModel() { + if (_sessions != null) { + for (int i = 0; i < _sessions.length; i++) { + _sessions[i].refreshModel(); + } + } + } + + public String toString(String tabs) { + _printTabs = tabs; + String s = toString(); + _printTabs = ""; //$NON-NLS-1$ + return s; + } + + @Override + public String toString() { + String s = _eventName + "\n"; //$NON-NLS-1$ + if (_sessions != null) { + for (int i = 0; i < _sessions.length; i++) { + s += _printTabs + "Session: "; //$NON-NLS-1$ + s += _sessions[i].toString(_printTabs + "\t"); //$NON-NLS-1$ + } + } + return s; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelImage.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelImage.java new file mode 100644 index 0000000..42ee8e0 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelImage.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + + +/** + * A class which represents an image (executables, + * libraries, modules) profile by OProfile. + */ +public class OpModelImage { + public static final int IMAGE_PARSE_ERROR = -1; + + //The count of all samples from this image + private int _count; + + //the count for all dependent images -- needed? + private int _depcount; + + //The name of this image (the full path, where applicable) + private String _name; + + //The symbols profiled in this image + private OpModelSymbol[] _symbols; + + //Any dependent images on this image (usually shared libs, kernel modules) + private OpModelImage[] _dependents; + + private String _printTabs = ""; //for nice output //$NON-NLS-1$ + + public OpModelImage() { + _name = ""; //$NON-NLS-1$ + _count = 0; + _depcount = 0; + _symbols = null; + _dependents = null; + } + + public int getCount() { + return _count; + } + + public int getDepCount() { + return _depcount; + } + + public String getName() { + return _name; + } + + //jinu added at 20090622-------------------- + private ArrayList _symbolList = new ArrayList(); + private ArrayList _dependentList = new ArrayList(); + public void _addSymbol(OpModelSymbol symbol){ + _symbolList.add(symbol); + } + public void _addDependent(OpModelImage image){ + _dependentList.add(image); + } + + private static class SortSymbolComparator implements Comparator { + public int compare(OpModelSymbol o1, OpModelSymbol o2) { + int cnt1 = o1.getCount(); + int cnt2 = o2.getCount(); + + return cnt1 { + public int compare(OpModelImage o1, OpModelImage o2) { + int cnt1 = o1.getCount(); + int cnt2 = o2.getCount(); + + return cnt1 - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.model; + +import org.tizen.oprofile.core.OprofileComm; + +/** + * A root node for the data model. Only one instance exists at any time, + * although the contents will change. On instantiation the events and + * sessions are gathered. + * + * Note that this data model does not map 1:1 to the oprofile data model. + * This model is for use in profiling one application compiled with debug + * info, from within eclipse. + */ + +public class OpModelRoot { + //jinu removed at 20090704 + //single instance + //private static OpModelRoot _modelRoot = new OpModelRoot(); + + private OpModelEvent[] _events; +// private String _printTabs = "\t"; //for nice output + + //jinu removed at 20090704 + /* + protected OpModelRoot() { +// refreshModel(); + _events = null; +// _modelRoot = this; + } + */ + public OpModelRoot() { + _events = null; + } + + //jinu removed at 20090618 + /* + public static OpModelRoot getDefault() { + return _modelRoot; + } + */ + + //jinu added at 20090628 -------------------------- + public void reset() { + _events = new OpModelEvent[0]; + } + + //jinu modified at 20090620 + /*public void refreshModel() { + //TODO-performance/interactivity: some persistence for events/sessions + // that dont change from run to run (non default sessions) + + _events = getNewEvents(); + if (_events != null) { + for (int i = 0; i < _events.length; i++) { + if (_events[i] != null) + _events[i].refreshModel(); + } + } + }*/ + + protected OpModelEvent[] getNewEvents() { + //launch `opxml sessions`, gather up events & the sessions under them + //jinu modified at 20090618 + //return Oprofile.getEvents(); + return OprofileComm.getEventList(); + } + + public OpModelEvent[] getEvents() { + return _events; + } + + + + @Override + public String toString() { + String s = ""; //$NON-NLS-1$ + if (_events != null) { + for (int i = 0; i < _events.length; i++) { + if (_events[i] != null) { + s += "Event: "; //$NON-NLS-1$ + s += _events[i].toString("\t"); //$NON-NLS-1$ + } + } + } + return s; + } + + //jinu added at 20090620 + public void _setEvents(OpModelEvent[] _events) { + this._events = _events; + } + + //jinu added at 20090704---------------------- + private String xmlStr; + public void setXML(String xmlStr) { + this.xmlStr = xmlStr; + } + + public String getXML() { + return xmlStr; + } + //-------------------------------- + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSample.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSample.java new file mode 100644 index 0000000..a705c09 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSample.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.model; + +/** + * Represents an OProfile sample. + */ +public class OpModelSample { + private int _count; + private int _line; + + public OpModelSample() { + _count = 0; + _line = 0; + } + + public void _setCount(int _count) { + this._count = _count; + } + + public void _setLine(int _line) { + this._line = _line; + } + + public int getCount() { + return _count; + } + + public int getLine() { + return _line; + } + + @Override + public String toString() { + String s = "Line #: " + _line + ", Count: " + _count + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return s; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSession.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSession.java new file mode 100644 index 0000000..1d2e66a --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSession.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 Red Hat, Inc. + * 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: + * Kent Sebastian - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.model; + +import org.eclipse.linuxtools.oprofile.core.Oprofile; + + +/** + * This class represents oprofile sessions. Sessions contain an image + * of the profiled binary. + */ +public class OpModelSession { + private static final String DEFAULT_SESSION_STRING = "current"; //$NON-NLS-1$ + + private OpModelEvent _parentEvent; + private OpModelImage _image; + private String _name; + private String _printTabs = ""; //for nice output //$NON-NLS-1$ + + public OpModelSession(OpModelEvent event, String name) { + _parentEvent = event; + _name = name; + _image = null; + } + + public OpModelImage getImage() { + return _image; + } + + public OpModelEvent getEvent() { + return _parentEvent; + } + + public String getName() { + return _name; + } + + public int getCount() { + if (_image == null) { + return 0; + } else { + return _image.getCount(); + } + } + + public boolean isDefaultSession() { + return _name.equals(DEFAULT_SESSION_STRING); + } + + public void refreshModel() { + //populate this session with samples + _image = getNewImage(); + } + + protected OpModelImage getNewImage() { + return Oprofile.getModelData(_parentEvent.getName(), _name); + } + + public String toString(String tabs) { + _printTabs = tabs; + String s = toString(); + _printTabs = ""; //$NON-NLS-1$ + return s; + } + + @Override + public String toString() { + String s = _name + "\n"; //$NON-NLS-1$ + if (_image != null) { + s += _printTabs + "Image: "; //$NON-NLS-1$ + s += _image.toString(_printTabs + "\t"); //$NON-NLS-1$ + } + return s; + + } + + public void _setImage(OpModelImage image){ + this._image = image; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSymbol.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSymbol.java new file mode 100644 index 0000000..db3c32d --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/model/OpModelSymbol.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 Red Hat, Inc. + * 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: + * Kent Sebastian - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + + +/** + * This class represents a debugging symbol, the symbol output + * from opxml. If a symbol exists, it must have samples (which are + * OpModelSamples), although those samples may or may not have + * complete debug info. + */ +public class OpModelSymbol { + private String _name; + private String _file; + private int _count; + private OpModelSample[] _samples; + private String _printTabs = ""; //for nice output //$NON-NLS-1$ + + public OpModelSymbol() { + _name = ""; //$NON-NLS-1$ + _file = ""; //$NON-NLS-1$ + _count = 0; + _samples = null; + } + + public void _setName(String _name) { + this._name = _name; + } + + public void _setFile(String _file) { + this._file = _file; + } + + public void _setCount(int _count) { + this._count = _count; + } + + public void _setSamples(OpModelSample[] _samples) { + this._samples = _samples; + } + + public String getName() { + return _name; + } + + public String getFile() { + return _file; + } + + public int getCount() { + return _count; + } + + //jinu added at 20090623------------------ + private ArrayList _sampleList = new ArrayList(); + public void _addSample(OpModelSample sample){ + _sampleList.add(sample); + } + + private static class SortSampleComparator implements Comparator { + public int compare(OpModelSample o1, OpModelSample o2) { + int cnt1 = o1.getCount(); + int cnt2 = o2.getCount(); + + return cnt1 - Initial implementation +# Kent Sebastian +###################################################################### +unknown-kernel=unknown +getSamples.caption=Reading samples for session \"{0}\"... +getSamples.caption.default-session=Reading samples for session \"Default\"... + +oprofileInit.error.statusMessage=An error occurred initializing OProfile for use with the plugin. Try loading the kernel module via OProfile itself with the command `opcontrol --init` (must be run as root). +oprofileInit.error.dialog.title=Error initializing OProfile +oprofileInit.error.dialog.message=FATAL: The OProfile kernel module could not be loaded. + +opcontrolRun.error.statusMessage=Error during run of opcontrol +opcontrolNonZeroExitCode.error.statusMessage=Exit code of opcontrol indicates failure + +opcontrolProvider.error.statusMessage=Could not find an OpcontrolProvider, or no opcontrol binary exists.\n\nPlease ensure you have run the install script as the root user. The install script will be in the org.eclipse.linuxtools.oprofile.core plugin, which may be located in one of a few places. You can locate it with the following command (type in a terminal):\n\nfind ~/.eclipse -name 'org.eclipse.linuxtools.oprofile.core*'\n\nIf that doesn't return results, try looking for it in your Eclipse installation:\n\nfind -name 'org.eclipse.linuxtools.oprofile.core*'\n\nWhen you have found the location of the plugin, change to the following directory and run, as root, the install script contained therein:\n\ncd /natives/linux/scripts\nsh -x install.sh\n\nYou may need to set the script as executable before running this command; do this with:\n\nchmod u+x install.sh + +opcontrolProvider.error.dialog.title=Error running opcontrol +opcontrolProvider.error.dialog.message=FATAL: An error occurred running opcontrol. + +opxmlParse.error.statusMessage=An unexpected error occurred with parsing opxml's output. Please file a bug at http://bugs.eclipse.org/bugs. +opxmlParse.error.dialog.title=Error with opxml +opxmlParse.error.dialog.message=An error occurred with opxml. + +opxmlIOException.error.statusMessage=The opxml binary can not be read or executed. Either your user does not have sufficient permissions, or the install script was not run.\n\nPlease ensure you have run the install script as the root user. The install script will be in the org.eclipse.linuxtools.oprofile.core plugin, which may be located in one of a few places. You can locate it with the following command (type in a terminal):\n\nfind ~/.eclipse -name 'org.eclipse.linuxtools.oprofile.core*'\n\nIf that doesn't return results, try looking for it in your Eclipse installation:\n\nfind -name 'org.eclipse.linuxtools.oprofile.core*'\n\nWhen you have found the location of the plugin, change to the following directory and run, as root, the install script contained therein:\n\ncd /natives/linux/scripts\nsh -x install.sh\n\nYou may need to set the script as executable before running this command; do this with:\n\nchmod u+x install.sh +opxmlIOException.error.dialog.title=Error with opxml +opxmlIOException.error.dialog.message=FATAL: An error occurred with opxml. + +opxmlProvider.error.statusMessage=Could not find an OpxmlProvider, or no opxml binary exists. Please fix the issue before continuing. +opxmlProvider.error.dialog.title=Error with opxml +opxmlProvider.error.dialog.message=FATAL: An error occurred with opxml. + +fatal.kernelModuleNotLoaded=OProfile kernel module not loaded or no opcontrol. Please fix the issue and restart Eclipse. + +ui.annotate.no.sessions.error.statusMessage=There are no sessions to annotate. Please profile a binary. +ui.annotate.no.sessions.error.dialog.title=Annotation Error +ui.annotate.no.sessions.error.dialog.message=Error annotating diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/OprofileSAXHandler.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/OprofileSAXHandler.java new file mode 100644 index 0000000..954d061 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/OprofileSAXHandler.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml; + +import java.util.HashMap; +import java.util.Stack; + +import org.eclipse.linuxtools.oprofile.core.opxml.checkevent.CheckEventsProcessor; +import org.eclipse.linuxtools.oprofile.core.opxml.info.OpInfoProcessor; +import org.eclipse.linuxtools.oprofile.core.opxml.modeldata.ModelDataProcessor; +import org.eclipse.linuxtools.oprofile.core.opxml.sessions.SessionsProcessor; +import org.xml.sax.Attributes; +import org.xml.sax.helpers.DefaultHandler; + +/** + * The SAX handler class that is used to parse the output of opxml. + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class OprofileSAXHandler extends DefaultHandler { + // The only allowed instance of this class + private static OprofileSAXHandler _instance = null; + + // A Map of all the XML processors for opxml + private static HashMap> _processors = new HashMap>(); + + // The current processor being used to parse the document + private XMLProcessor _processor = null; + private Object _callData; + + /* A stack of XML processors. This allows processors to invoke sub-processors + for handling nested tags more efficiently. */ + private Stack _processorStack = new Stack(); + + // A convenience class for specifying XMLProcessors + private static class ProcessorItem { + public String tagName; + public Class handlerClass; + public ProcessorItem(String name, Class cls) { + tagName = name; + handlerClass = cls; + } + } + + // The list of all "root" XML tags and their handler classes + private static final ProcessorItem[] _handlerList = { + new ProcessorItem(OpxmlConstants.INFO_TAG, OpInfoProcessor.class), + new ProcessorItem(OpxmlConstants.CHECKEVENTS_TAG, CheckEventsProcessor.class), + new ProcessorItem(OpxmlConstants.MODELDATA_TAG, ModelDataProcessor.class), + new ProcessorItem(OpxmlConstants.SESSIONS_TAG, SessionsProcessor.class) + }; + + /** + * Returns an instance of the handler. This must be used to access the parser! + * @return a handler instance + */ + public static OprofileSAXHandler getInstance(Object callData) { + if (_instance == null) { + _instance = new OprofileSAXHandler(); + + // Initialize processor map + for (int i = 0; i < _handlerList.length; ++i) { + _processors.put(_handlerList[i].tagName, _handlerList[i].handlerClass); + } + } + + // Set calldata into handler + _instance.setCallData (callData); + return _instance; + } + + /** + * Sets the calldata for the processor. + * @param callData the calldata to pass to the processor + */ + public void setCallData(Object callData) + { + _callData = callData; + } + + /** + * Returns the processor for a given request type. + * @param type the name of the processor + * @return the requested processor or null + */ + public static XMLProcessor getProcessor(String type) { + XMLProcessor processor = null; + + Class handlerClass = (Class) _processors.get(type); + if (handlerClass != null) { + try { + processor = (XMLProcessor) handlerClass.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + return processor; + } + + /** + * @see org.xml.sax.ContentHandler#startDocument() + */ + public void startDocument() { + // Reset processor + _processor = null; + } + + /** + * @see org.xml.sax.ContentHandler#endDocument() + */ + public void endDocument() { + } + + /** + * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes) + */ + public void startElement(String uri, String lName, String qName, Attributes attrs) { + if (_processor == null) { + // Get processor for this event type + _processor = getProcessor(qName); + _processor.reset(_callData); + } + + // If we already have a processor, so let it deal with this new element. + // Allow the processor to deal with it's own tag as well: this way it can + // grab attributes from it. + _processor.startElement(qName, attrs, _callData); + } + + /** + * @see org.xml.sax.ContentHandler#endElement(String, String, String) + */ + public void endElement(String uri, String name, String qName) { + _processor.endElement(qName, _callData); + } + + /** + * @see org.xml.sax.ContentHandler#characters(char[], int, int) + */ + public void characters(char ch[], int start, int length) { + // Ignore characters which are only whitespace + String str = new String(ch, start, length).trim(); + if (str.length() > 0 && _processor != null) + _processor.characters(new String(ch, start, length), _callData); + } + + /** + * Returns the processor used to parse the document. + * @return the XMLProcessor + */ + public XMLProcessor getProcessor() { + return _processor; + } + + /** + * Pushes the current XMLProcessor onto the stack and installs the given + * processor as the document's parser/handler. + * @param proc the processor to continue parsing the document + */ + public void push(XMLProcessor proc) { + _processorStack.add(_processor); + _processor = proc; + _processor.reset(_callData); + } + + /** + * Removes the current XMLProcessor and installs the previous processor. + * NOTE: This assumes that endElement caused the pop, so it calls endElement in + * the parent processor. + * @param tag the XML tag to pass to the parent processor + */ + public void pop(String tag) { + _processor = (XMLProcessor) _processorStack.pop(); + _processor.endElement(tag, _callData); + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/OpxmlConstants.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/OpxmlConstants.java new file mode 100644 index 0000000..3a0f62a --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/OpxmlConstants.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - change samples to model-data + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml; + +/** + * A class of constants for communications with the opxml wrapper + * program. + * @see org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler + */ +public class OpxmlConstants { + /** + * Request static oprofile information (num counters, defaults, event lists) + */ + public static final String OPXML_INFO = "info"; //$NON-NLS-1$ + public static final String INFO_TAG = OPXML_INFO; + + /** + * Request model data for a session + */ + public static final String OPXML_MODELDATA = "model-data"; //$NON-NLS-1$ + public static final String MODELDATA_TAG = OPXML_MODELDATA; + + /** + * Request event validity check + */ + public static final String OPXML_CHECKEVENTS = "check-events"; //$NON-NLS-1$ + public static final String CHECKEVENTS_TAG = OPXML_CHECKEVENTS; + + /** + * Request session list + */ + public static final String OPXML_SESSIONS = "sessions"; //$NON-NLS-1$ + public static final String SESSIONS_TAG = OPXML_SESSIONS; +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/XMLProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/XMLProcessor.java new file mode 100644 index 0000000..11a4a5d --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/XMLProcessor.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml; + +import org.xml.sax.Attributes; + +/** + * A class which (minimally) parses XML documents. This class provides only basic + * support for collecting information from XML documents. It is intended to be subclassed, + * providing only common functionality for all parser classes. + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class XMLProcessor { + // The characters in the current tag + protected String _characters; + + /** + * This method is called whenever the SAXHandler is about to invoke the + * processor for the first time on a given document. + * @param callData call data for the processor (usually the result is stored here) + */ + public void reset(Object callData) { + }; + + //jinu added at 20090620 + public void release(Object callData) { + }; + + /** + * This method is called whenever a new tag is seen in the document. By default, + * this process will clear the characters collected for the tag. Processors will typically + * call this baseclass method to setup for collecting new character information for a + * tag. + * @param name the name of the tag + * @param attrs the tag's attributes + * @param callData call data for the processor (usually the result is stored here) + */ + public void startElement(String name, Attributes attrs, Object callData) { + _characters = new String(); + } + + /** + * This method is called whenever the closing tag for an element is seen in the + * document. + * @param name the element which is ending + * @param callData call data for the processor (usually the result is stored here) + */ + public void endElement(String name, Object callData) { + } + + /** + * This method is called whenever characters are seen in the document that are not in + * a markup tag. + * @param chars the characters read + * @param callData call data for the processor (usually the result is stored here) + */ + public void characters(String chars, Object callData) { + _characters = chars; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/checkevent/CheckEventsProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/checkevent/CheckEventsProcessor.java new file mode 100644 index 0000000..79c8a58 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/checkevent/CheckEventsProcessor.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2004, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.checkevent; + +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; + +/** + * XML handler class for opxml's "check-events". + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class CheckEventsProcessor extends XMLProcessor { + public static final int INVALID_UNKNOWN = 0; //unexpected error + public static final int EVENT_OK = 1; //valid + public static final int INVALID_EVENT = 2; //invalid event number + public static final int INVALID_UMASK = 3; //invalid unit mask value + public static final int INVALID_COUNTER = 4; //invalid event for given counter number + + private static final String _RESULT_TAG = "result"; //$NON-NLS-1$ + private static final String _CHECK_EVENTS_TAG ="check-events"; //$NON-NLS-1$ + + private static final String _EVENT_OK = "ok"; //$NON-NLS-1$ + private static final String _INVALID_EVENT = "invalid-event"; //$NON-NLS-1$ + private static final String _INVALID_UMASK = "invalid-um"; //$NON-NLS-1$ + private static final String _INVALID_COUNTER = "invalid-counter"; //$NON-NLS-1$ + + private int _result; + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#reset() + */ + public void reset(Object callData) { + _result = INVALID_UNKNOWN; + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(_RESULT_TAG)) { + if (_characters.equals(_EVENT_OK)) { + _result = EVENT_OK; + } else if (_characters.equals(_INVALID_EVENT)) { + _result = INVALID_EVENT; + } else if (_characters.equals(_INVALID_UMASK)) { + _result = INVALID_UMASK; + } else if (_characters.equals(_INVALID_COUNTER)) { + _result = INVALID_COUNTER; + } + } else if (name.equals(_CHECK_EVENTS_TAG)) { + int[] result = (int[]) callData; + result[0] = _result; + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/DefaultsProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/DefaultsProcessor.java new file mode 100644 index 0000000..817d842 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/DefaultsProcessor.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.info; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; + +/** + * XML handler class for opxml's "defaults". + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class DefaultsProcessor extends XMLProcessor { + // XML tags reconize by this processor (public) + public static final String SAMPLE_DIR = "sample-dir"; //$NON-NLS-1$ + public static final String LOCK_FILE = "lock-file"; //$NON-NLS-1$ + public static final String LOG_FILE = "log-file"; //$NON-NLS-1$ + public static final String DUMP_STATUS = "dump-status"; //$NON-NLS-1$ + protected HashMap _map = new HashMap(); + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#reset() + */ + public void reset(Object callData) { + _map.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor#endElement(java.lang.String, java.lang.Object) + */ + public void endElement(String name, Object callData) { + if (name.equals(OpInfoProcessor.DEFAULTS_TAG)) { + OpInfo info = (OpInfo) callData; + info._setDefaults(_map); + OprofileSAXHandler.getInstance(callData).pop(name); + } else { + _map.put(name, _characters); + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/EventListProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/EventListProcessor.java new file mode 100644 index 0000000..72f5e77 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/EventListProcessor.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * Copyright (c) 2004,2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.info; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.daemon.OpEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OpUnitMask; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.Attributes; + + +/** + * XML handler class for opxml's "event-list". + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class EventListProcessor extends XMLProcessor { + // The current event being constructed + private OpEvent _currentEvent; + private int _counter; + private ArrayList _currentEventList; + + // An XML processor for reading the unit mask information for an event + private UnitMaskProcessor _umProcessor; + + // XML elements recognized by this processor + private static final String _EVENT_TAG = "event"; //$NON-NLS-1$ + private static final String _UNIT_MASK_TAG = "unit-mask"; //$NON-NLS-1$ + private static final String _NAME_TAG = "name"; //$NON-NLS-1$ + private static final String _VALUE_TAG = "value"; //$NON-NLS-1$ + private static final String _DESCRIPTION_TAG = "description"; //$NON-NLS-1$ + private static final String _MASK_TAG = "mask"; //$NON-NLS-1$ + private static final String _MINIMUM_COUNT_TAG = "minimum"; //$NON-NLS-1$ + private static final String _ATTR_EVENT_LIST_COUNTER = "counter"; //$NON-NLS-1$ + + // This is a special processor which is used to deal with a single mask value + private class MaskProcessor extends XMLProcessor { + private OpUnitMask.MaskInfo _info; + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#reset() + */ + public void reset(Object callData) { + _info = new OpUnitMask.MaskInfo(); + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(_VALUE_TAG)) { + // Set mask's value + _info.value = Integer.parseInt(_characters); + } else if (name.equals(_DESCRIPTION_TAG)) { + _info.description = _characters; + } else if (name.equals(_MASK_TAG)) { + // Pop and pass mask tag to previous processor (UnitMaskProcessor) + OprofileSAXHandler.getInstance(callData).pop(_MASK_TAG); + } + } + + /** + * Returns the information that has been collected about a mask. + * @return the mask information + */ + public OpUnitMask.MaskInfo getResult() { + return _info; + } + } + + // This is a special processor to handle unit mask information + private class UnitMaskProcessor extends XMLProcessor { + // An ArrayList to hold all the valid masks for a unit mask. + private ArrayList _masks; + + // The unit mask being constructed + private OpUnitMask _unitMask; + + // An XML processor for each individual mask value. + private MaskProcessor _maskProcessor; + + // XML elements recognized by this processor + private static final String _MASK_TYPE_TAG = "type"; //$NON-NLS-1$ + private static final String _MASK_DEFAULT_TAG = "default"; //$NON-NLS-1$ + private static final String _MASK_TYPE_BITMASK = "bitmask"; //$NON-NLS-1$ + private static final String _MASK_TYPE_MANDATORY = "mandatory"; //$NON-NLS-1$ + private static final String _MASK_TYPE_EXCLUSIVE = "exclusive"; //$NON-NLS-1$ + + /** + * Constructor for UnitMaskProcessor. Initializes internal state. + */ + public UnitMaskProcessor() { + super(); + _maskProcessor = new MaskProcessor(); + _masks = new ArrayList(); + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#reset() + */ + public void reset(Object callData) { + _unitMask = new OpUnitMask(); + _masks.clear(); + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#startElement(String, Attributes) + */ + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(_MASK_TAG)) { + // Tell SAX handler to use the mask processor + OprofileSAXHandler.getInstance(callData).push(_maskProcessor); + } else { + super.startElement(name, attrs, callData); + } + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(_MASK_TYPE_TAG)) { + // Set the mask type + _unitMask._setType(_getTypeFromString(_characters)); + } else if (name.equals(_MASK_DEFAULT_TAG)) { + // Set the default mask + _unitMask._setDefault(Integer.parseInt(_characters)); + } else if (name.equals(_MASK_TAG)) { + // Add this mask description to the list of all masks + _masks.add(_maskProcessor.getResult()); + } else if (name.equals(_UNIT_MASK_TAG)) { + // All done. Add the known masks to the unit mask + OpUnitMask.MaskInfo[] descs = new OpUnitMask.MaskInfo[_masks.size()]; + _masks.toArray(descs); + _unitMask._setMaskDescriptions(descs); + + // Pop this processor and pass _UNIT_MASK_TAG to previoius processor + OprofileSAXHandler.getInstance(callData).pop(_UNIT_MASK_TAG); + } + } + + /** + * Returns the constructed unit mask. + * @return the unit mask + */ + public OpUnitMask getResult() { + return _unitMask; + } + + // Converts a string representing a mask type into an integer + private int _getTypeFromString(String string) { + if (string.equals(_MASK_TYPE_MANDATORY)) { + return OpUnitMask.MANDATORY; + } else if (string.equals(_MASK_TYPE_BITMASK)) { + return OpUnitMask.BITMASK; + } else if (string.equals(_MASK_TYPE_EXCLUSIVE)) { + return OpUnitMask.EXCLUSIVE; + } + + return -1; + } + }; + + /** + * Constructor for EventListProcessor. Initializes internal state. + */ + public EventListProcessor() { + super(); + _umProcessor = new UnitMaskProcessor(); + } + + @Override + public void reset(Object callData) { + _currentEventList = new ArrayList(); + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#startElement(String, Attributes) + */ + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(_EVENT_TAG)) { + // new event + _currentEvent = new OpEvent(); + } else if (name.equals(_UNIT_MASK_TAG)) { + // Tell the SAX handler to use the unit mask processor + OprofileSAXHandler.getInstance(callData).push(_umProcessor); + } else if (name.equals(OpInfoProcessor.EVENT_LIST_TAG)) { + // Our start tag: grab the counter number from the attributes + _counter = Integer.parseInt(attrs.getValue(_ATTR_EVENT_LIST_COUNTER)); + } else { + super.startElement(name, attrs, callData); + } + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(_EVENT_TAG)) { + // Finished constructing an event. Add it to the list. + _currentEventList.add(_currentEvent); + } else if (name.equals(_UNIT_MASK_TAG)) { + // Set the event's unit mask + _currentEvent._setUnitMask(_umProcessor.getResult()); + } else if (name.equals(_NAME_TAG)) { + // Set event's name + _currentEvent._setText(_characters); + } else if (name.equals(_VALUE_TAG)) { + // Set event's value + _currentEvent._setNumber(Integer.parseInt(_characters)); + } else if (name.equals(_DESCRIPTION_TAG)) { + // Set event's description + _currentEvent._setTextDescription(_characters); + } else if (name.equals(_MINIMUM_COUNT_TAG)) { + // Set event's minimum count + _currentEvent._setMinCount(Integer.parseInt(_characters)); + } else if (name.equals(OpInfoProcessor.EVENT_LIST_TAG)) { + OprofileSAXHandler.getInstance(callData).pop(name); + } + } + + public int getCounterNum() { + return _counter; + } + + public OpEvent[] getEvents() { + OpEvent[] events = new OpEvent[_currentEventList.size()]; + _currentEventList.toArray(events); + return events; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/OpInfoProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/OpInfoProcessor.java new file mode 100644 index 0000000..c64b3af --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/OpInfoProcessor.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2004,2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.info; + +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.Attributes; + + +/** + * Opxml processor for the "info" command. + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class OpInfoProcessor extends XMLProcessor { + // Other XMLProcessors used by this processor + private DefaultsProcessor _defaultsProc; + private EventListProcessor _eventListProc; + + // XML tags processed by this processor + public static final String NUM_COUNTERS_TAG = "num-counters"; //$NON-NLS-1$ + public static final String DEFAULTS_TAG = "defaults"; //$NON-NLS-1$ + public static final String EVENT_LIST_TAG = "event-list"; //$NON-NLS-1$ + public static final String CPU_FREQUENCY_TAG = "cpu-frequency"; //$NON-NLS-1$ + public static final String TIMER_MODE = "timer-mode"; //$NON-NLS-1$ + + public OpInfoProcessor() { + _defaultsProc = new DefaultsProcessor(); + _eventListProc = new EventListProcessor(); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor#startElement(java.lang.String, org.xml.sax.Attributes, java.lang.Object) + */ + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(DEFAULTS_TAG)) { + OprofileSAXHandler.getInstance(callData).push(_defaultsProc); + } else if (name.equals(EVENT_LIST_TAG)) { + OprofileSAXHandler.getInstance(callData).push(_eventListProc); + _eventListProc.startElement(name, attrs, callData); + } else { + super.startElement(name, attrs, callData); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor#endElement(java.lang.String, java.lang.Object) + */ + public void endElement(String name, Object callData) { + if (name.equals(CPU_FREQUENCY_TAG)) { + double speed = Double.parseDouble(_characters); + OpInfo info = (OpInfo) callData; + info._setCPUSpeed(speed); + } else if (name.equals(TIMER_MODE)) { + boolean timerMode = Boolean.parseBoolean(_characters); + OpInfo info = (OpInfo) callData; + info._setTimerMode(timerMode); + } else if (name.equals(NUM_COUNTERS_TAG)) { + int numCounters = 0; + try { + numCounters = Integer.parseInt(_characters); + } catch (NumberFormatException nfe) { + nfe.printStackTrace(); + } + OpInfo info = (OpInfo) callData; + info._setNrCounters(numCounters); + } else if (name.equals(EVENT_LIST_TAG)) { + OpInfo info = (OpInfo) callData; + info._setEvents(_eventListProc.getCounterNum(), _eventListProc.getEvents()); + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/DependentProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/DependentProcessor.java new file mode 100644 index 0000000..1c40e22 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/DependentProcessor.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2008 Red Hat, Inc. + * 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: + * Kent Sebastian - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.modeldata; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.Attributes; + + +/** + * XML handler class for dependent images ( tags under ) + */ +public class DependentProcessor extends XMLProcessor { + //XML tags parsed by this processor + private static final String IMAGE_TAG = "image"; //$NON-NLS-1$ + private static final String SYMBOLS_TAG = "symbols"; //$NON-NLS-1$ + private static final String DEPENDENT_TAG = "dependent"; //$NON-NLS-1$ + + //attribute tags + private static final String ATTR_IMAGENAME = "name"; //$NON-NLS-1$ + private static final String ATTR_COUNT = "count"; //$NON-NLS-1$ + + //the current image being constructed + private OpModelImage _image; + //a list of all the dependent images + private ArrayList _imageList; + + //processor used for symbols of an image + private SymbolsProcessor _symbolsProcessor = new SymbolsProcessor(); + + public void reset(Object callData) { + _image = new OpModelImage(); + _imageList = new ArrayList(); + } + + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(IMAGE_TAG)) { + _image._setName(attrs.getValue(ATTR_IMAGENAME)); + _image._setCount(Integer.parseInt(attrs.getValue(ATTR_COUNT))); + } else if (name.equals(SYMBOLS_TAG)) { + OprofileSAXHandler.getInstance(callData).push(_symbolsProcessor); + } + } + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(IMAGE_TAG)) { + _imageList.add(_image); + _image = new OpModelImage(); + } else if (name.equals(SYMBOLS_TAG)) { + _image._setSymbols(_symbolsProcessor.getSymbols()); + } else if (name.equals(DEPENDENT_TAG)) { + OprofileSAXHandler.getInstance(callData).pop(DEPENDENT_TAG); + } + } + + public OpModelImage[] getImages() { + OpModelImage[] images = new OpModelImage[_imageList.size()]; + _imageList.toArray(images); + return images; + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/ModelDataProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/ModelDataProcessor.java new file mode 100644 index 0000000..06a0011 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/ModelDataProcessor.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.core.opxml.modeldata; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.Attributes; + + +/** + * A processor for `opxml samples`. + */ +public class ModelDataProcessor extends XMLProcessor { + //The resulting image compiled by the processor to be used by the caller. + public static class CallData { + public OpModelImage image; + public CallData(OpModelImage im) { image = im; } + } + + //XML tags parsed by this processor + private static final String IMAGE_TAG = "image"; //$NON-NLS-1$ + private static final String SYMBOLS_TAG = "symbols"; //$NON-NLS-1$ + private static final String DEPENDENT_TAG = "dependent"; //$NON-NLS-1$ + + //attribute tags + private static final String ATTR_IMAGENAME = "name"; //$NON-NLS-1$ + private static final String ATTR_COUNT = "count"; //$NON-NLS-1$ + private static final String ATTR_DEPCOUNT = "count"; //$NON-NLS-1$ + + //the current image being constructed + private OpModelImage _image; + private int img_seen; //for ensuring image singleton-ness + + //processors used for symbols and dependent images + private SymbolsProcessor _symbolsProcessor = new SymbolsProcessor(); + private DependentProcessor _dependentProcessor = new DependentProcessor(); + + + public void reset(Object callData) { + _image = ((CallData) callData).image; + img_seen = 0; + } + + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(IMAGE_TAG)) { + if (img_seen == 0) { + _image._setName(attrs.getValue(ATTR_IMAGENAME)); + _image._setCount(Integer.parseInt(attrs.getValue(ATTR_COUNT))); + } + + img_seen++; + } else if (name.equals(SYMBOLS_TAG)) { + OprofileSAXHandler.getInstance(callData).push(_symbolsProcessor); + } else if (name.equals(DEPENDENT_TAG)) { + _image._setDepCount(Integer.parseInt(attrs.getValue(ATTR_DEPCOUNT))); + OprofileSAXHandler.getInstance(callData).push(_dependentProcessor); + } else { + super.startElement(name, attrs, callData); + } + } + + public void endElement(String name, Object callData) { + if (name.equals(IMAGE_TAG)) { + if (img_seen > 1) { + //should only ever be one image, otherwise oprofile was run + // outside of eclipse and the ui would not handle it properly + _image._setCount(OpModelImage.IMAGE_PARSE_ERROR); + _image._setDepCount(0); + _image._setDependents(null); + _image._setSymbols(null); + _image._setName(""); //$NON-NLS-1$ + } + } else if (name.equals(SYMBOLS_TAG)){ + _image._setSymbols(_symbolsProcessor.getSymbols()); + } else if (name.equals(DEPENDENT_TAG)){ + _image._setDependents(_dependentProcessor.getImages()); + } else { + super.endElement(name, callData); + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/SamplesProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/SamplesProcessor.java new file mode 100644 index 0000000..a2bf5a4 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/SamplesProcessor.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2008 Red Hat, Inc. + * 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: + * Kent Sebastian - initial API and implementation + * - Note: the original SetupParser class was removed, this is a new + * implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.modeldata; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelSample; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; + + +/** + * XML handler class for tags (individual samples). + */ +public class SamplesProcessor extends XMLProcessor { + //XML tags parsed by this processor + private static final String SAMPLE_TAG = "sample"; //$NON-NLS-1$ + private static final String COUNT_TAG = "count"; //$NON-NLS-1$ + private static final String LINE_TAG = "line"; //$NON-NLS-1$ + private static final String SYMBOL_TAG = "symbol"; //$NON-NLS-1$ + + //the current sample being constructed + private OpModelSample _sample; + //a list of all samples (for this symbol) + private ArrayList _sampleList; + + public void reset(Object callData) { + _sample = new OpModelSample(); + _sampleList = new ArrayList(); + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(COUNT_TAG)) { + _sample._setCount(Integer.parseInt(_characters)); + } else if (name.equals(LINE_TAG)) { + _sample._setLine(Integer.parseInt(_characters)); + } else if (name.equals(SAMPLE_TAG)) { + _sampleList.add(_sample); + _sample = new OpModelSample(); + } else if (name.equals(SYMBOL_TAG)) { + OprofileSAXHandler.getInstance(callData).pop(SYMBOL_TAG); + } + } + + public OpModelSample[] getSamples() { + OpModelSample[] samples = new OpModelSample[_sampleList.size()]; + _sampleList.toArray(samples); + return samples; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/SymbolsProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/SymbolsProcessor.java new file mode 100644 index 0000000..43d5f2c --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/modeldata/SymbolsProcessor.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2008 Red Hat, Inc. + * 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: + * Kent Sebastian - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.modeldata; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.eclipse.linuxtools.oprofile.core.opxml.OprofileSAXHandler; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.Attributes; + +/** + * A processor for the tag from `opxml samples ..` + */ +public class SymbolsProcessor extends XMLProcessor { + //XML tags parsed by this processor + private static final String SYMBOLS_TAG = "symbols"; //$NON-NLS-1$ + private static final String SYMBOL_TAG = "symbol"; //$NON-NLS-1$ + private static final String SAMPLE_TAG = "sample"; //$NON-NLS-1$ + + //attribute tags + private static final String ATTR_NAME = "name"; //$NON-NLS-1$ + private static final String ATTR_FILE = "file"; //$NON-NLS-1$ + private static final String ATTR_COUNT = "count"; //$NON-NLS-1$ + + //the current symbol being constructed + private OpModelSymbol _symbol; + //all the symbols in this tag, to be returned to the calling ModelDataProcessor + private ArrayList _symbols; + + //the processor used for individual samples + private SamplesProcessor _samplesProcessor = new SamplesProcessor(); + + + public void reset(Object callData) { + _symbol = new OpModelSymbol(); + _symbols = new ArrayList(); + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#startElement(String, Attributes) + */ + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(SYMBOL_TAG)) { + _symbol._setName(attrs.getValue(ATTR_NAME)); + _symbol._setCount(Integer.parseInt(attrs.getValue(ATTR_COUNT))); + _symbol._setFile(attrs.getValue(ATTR_FILE)); + } else if (name.equals(SAMPLE_TAG)) { + OprofileSAXHandler.getInstance(callData).push(_samplesProcessor); + } + } + + /** + * @see org.eclipse.linuxtools.oprofile.core.XMLProcessor#endElement(String) + */ + public void endElement(String name, Object callData) { + if (name.equals(SYMBOL_TAG)) { + _symbol._setSamples(_samplesProcessor.getSamples()); + _symbols.add(_symbol); + _symbol = new OpModelSymbol(); + } else if (name.equals(SYMBOLS_TAG)) { + OprofileSAXHandler.getInstance(callData).pop(SYMBOLS_TAG); + } + } + + //return all parsed samples + public OpModelSymbol[] getSymbols() { + OpModelSymbol [] symbols = new OpModelSymbol[_symbols.size()]; + _symbols.toArray(symbols); + return symbols; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/sessions/SessionsProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/sessions/SessionsProcessor.java new file mode 100644 index 0000000..7c3fcc8 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/sessions/SessionsProcessor.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.core.opxml.sessions; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSession; +import org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor; +import org.xml.sax.Attributes; + + +/** + * A processor for sessions. + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class SessionsProcessor extends XMLProcessor { + public static class SessionInfo { + // A list of SessionEvents + public ArrayList list; + + public SessionInfo(ArrayList _list){ + list = _list; + } + }; + + // XML tags recognized by this processor + public static final String SESSION_TAG = "session"; //$NON-NLS-1$ + private static final String _SESSION_NAME_ATTR = "name"; //$NON-NLS-1$ + public static final String SAMPLE_COUNT_TAG = "count"; //$NON-NLS-1$ + public static final String EVENT_TAG = "event"; //$NON-NLS-1$ + private static final String _EVENT_NAME_ATTR = "name"; //$NON-NLS-1$ + + // The current session being constructed + private OpModelSession _currentSession; + + // The current event being constructed + private OpModelEvent _currentEvent; + + // A list of all sessions + private ArrayList _sessionList; + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor#startElement(java.lang.String, org.xml.sax.Attributes, java.lang.Object) + */ + public void startElement(String name, Attributes attrs, Object callData) { + if (name.equals(SESSION_TAG)) { + String sessionName = attrs.getValue(_SESSION_NAME_ATTR); + _currentSession = new OpModelSession(_currentEvent, sessionName); + } else if (name.equals(EVENT_TAG)) { + String eventName = attrs.getValue(_EVENT_NAME_ATTR); + _currentEvent = new OpModelEvent(eventName); + _sessionList = new ArrayList(); + } else { + super.startElement(name, attrs, callData); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.oprofile.core.opxml.XMLProcessor#endElement(java.lang.String, java.lang.Object) + */ + public void endElement(String name, Object callData) { + if (name.equals(SESSION_TAG)) { + // Got end of session -- save in session list + _sessionList.add(_currentSession); + _currentSession = null; + } else if (name.equals(EVENT_TAG)) { + // Got end of event -- save session list into current OpModelEvent and + // save current event into call data + OpModelSession[] s = new OpModelSession[_sessionList.size()]; + _sessionList.toArray(s); + _currentEvent._setSessions(s); + SessionInfo info = (SessionInfo) callData; + info.list.add(_currentEvent); + _currentEvent = null; + _sessionList = null; + } else { + super.endElement(name, callData); + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/CommandManager.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/CommandManager.java new file mode 100644 index 0000000..9580934 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/CommandManager.java @@ -0,0 +1,228 @@ +package org.tizen.oprofile.core; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +import org.tizen.common.connection.ConnectionPlugin; +import org.tizen.oprofile.core.CommonReceiver; +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.MultiLineReceiver; +import org.tizen.sdblib.SdbCommandRejectedException; +import org.tizen.sdblib.SdbShellProcess; +import org.tizen.sdblib.ShellCommandUnresponsiveException; +import org.tizen.sdblib.SyncService; +import org.tizen.sdblib.SyncService.SyncResult; +import org.tizen.sdblib.TimeoutException; + +class CommonReceiver extends MultiLineReceiver { + + private String[] output = null; + + public String[] getOutput() { + return output; + } + + @Override + public void processNewLines(String[] lines) { + output = lines; + } + +} + +class OneStringReceiver extends MultiLineReceiver { + + private String output = ""; + + public String getOutput() { + return output; + } + + @Override + public void processNewLines(String[] lines) { + // output = lines; + StringBuilder out = new StringBuilder(""); + for (int i = 0; i < lines.length; i++) { + if (lines[i].equals("")) + continue; + out.append(lines[i]); + out.append("\r\n"); + } + output = output + out.toString(); + } + +} + +public class CommandManager { + +// private static String getRealTargetPath(String path) { +//// if (ConnectionPlugin.getDefault().getCurrentDevice().isEmulator()) { +//// return path; +//// } +// if (path.contains("/usr/bin")) { +// path = path +// .replace("/usr/bin", "/home/developer/sdk_tools/oprofile/usr/bin"); +// } +// return path; +// } + + public static SdbShellProcess runApplication(String command){ + IDevice device = ConnectionPlugin.getDefault().getCurrentDevice(); + SdbShellProcess sdbShellProc = null; + + //command = getRealTargetPath(command); + + try { + sdbShellProc = device.executeShellCommand(command); + } catch (IOException e) { + e.printStackTrace(); + } + return sdbShellProc; + } + + public static void runShell(String command) { + IDevice device = ConnectionPlugin.getDefault().getCurrentDevice(); + SdbShellProcess sdbShellProc = null; + BufferedReader br = null; + + //command = getRealTargetPath(command); + + try { + sdbShellProc = device.executeShellCommand(command); + br = new BufferedReader(new InputStreamReader( + sdbShellProc.getInputStream())); + + } catch (IOException e1) { + e1.printStackTrace(); + } + + try { + String message; + while (null != (message = br.readLine())) { + if (message.equals("start_ok")) { + break; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String runCommandReturningResult(String command) { + IDevice device = ConnectionPlugin.getDefault().getCurrentDevice(); + OneStringReceiver oneStringReceiver = new OneStringReceiver(); + + //command = getRealTargetPath(command); + + try { + device.executeShellCommand(command, oneStringReceiver); + } catch (TimeoutException e) { + e.printStackTrace(); + } catch (SdbCommandRejectedException e) { + e.printStackTrace(); + } catch (ShellCommandUnresponsiveException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return oneStringReceiver.getOutput(); + } + + public static String[] runCommandReturningResultArray(String command) { + IDevice device = ConnectionPlugin.getDefault().getCurrentDevice(); + CommonReceiver commonReceiver = new CommonReceiver(); + + //command = getRealTargetPath(command); + + try { + device.executeShellCommand(command, commonReceiver); + } catch (TimeoutException e) { + e.printStackTrace(); + } catch (SdbCommandRejectedException e) { + e.printStackTrace(); + } catch (ShellCommandUnresponsiveException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return commonReceiver.getOutput(); + } + + public static void runCommand(String command) { + + //command = getRealTargetPath(command); + + try { + ConnectionPlugin.getDefault().getCurrentDevice() + .executeShellCommand(command); + } catch (SdbCommandRejectedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static boolean pull(String src, String dest) { + SyncService syncService = null; + try { + syncService = ConnectionPlugin.getDefault().getCurrentDevice() + .getSyncService(); + } catch (TimeoutException e) { + e.printStackTrace(); + } catch (SdbCommandRejectedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + SyncResult result = syncService.pullFile(src, dest, + SyncService.getNullProgressMonitor()); + if (SyncService.RESULT_OK == result.getCode()) { + return true; + } else { + return false; + } + } + + public static boolean push(String src, String dest) { + SyncService syncService = null; + try { + syncService = ConnectionPlugin.getDefault().getCurrentDevice() + .getSyncService(); + } catch (TimeoutException e) { + e.printStackTrace(); + } catch (SdbCommandRejectedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + SyncResult result = syncService.pushFile(src, dest, + SyncService.getNullProgressMonitor()); + if (SyncService.RESULT_OK == result.getCode()) { + return true; + } else { + return false; + } + } + + public static boolean isPathExist(String path) { + String[] result = runCommandReturningResultArray(path); + if (null != result && result[0].equals("No such file or directory")) { + return false; + } + return true; + } + + public static boolean isEmulator() { + return ConnectionPlugin.getDefault().getCurrentDevice().isEmulator(); + } + + public static boolean isRunSeccessfuly(String[] result) { + if (null != result && result.length > 0 + && !result[result.length - 1].contains("0")) { + return false; + } else { + return true; + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/OprofileComm.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/OprofileComm.java new file mode 100644 index 0000000..562603f --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/OprofileComm.java @@ -0,0 +1,157 @@ +/* + * OprofileComm + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + + +package org.tizen.oprofile.core; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelRoot; +import org.eclipse.swt.widgets.Display; + +import org.tizen.oprofile.core.provider.OpcontrolDataProvider; + +public abstract class OprofileComm { + + public static Boolean checkEvent(String event, int count, int unitmask) { + int[] result = new int[1]; + try { + IRunnableWithProgress opxml = OpcontrolDataProvider.checkEvent(event, count, unitmask, result); + opxml.run(null); + } catch (InvocationTargetException e) { + String error = "An error has occured during check event setting for OProfile"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error, reason , e); //$NON-NLS-1$ + } catch (InterruptedException e) { + String error = "An error has occured during check event setting for OProfile"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error, reason , e); //$NON-NLS-1$ + } + + return (result[0] == 0); + } + + public static OpModelEvent[] getEventList() { + OpModelEvent[] events = null; + + ArrayList eventList = new ArrayList(); + try { + IRunnableWithProgress runner = OpcontrolDataProvider.getEventList(eventList); + runner.run(null); + events = new OpModelEvent[eventList.size()]; + eventList.toArray(events); + } catch (InvocationTargetException e) { + String error = "An error has occured during get detailed information of supported event for OProfile"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error ,reason, e); //$NON-NLS-1$ + } catch (InterruptedException e) { + String error = "An error has occured during get detailed information of supported event for OProfile"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error ,reason, e); //$NON-NLS-1$ + } + return events; + } + + public static OpModelRoot getModelData() { + OpModelRoot model = new OpModelRoot(); + try { + IRunnableWithProgress runner = OpcontrolDataProvider.getModelData(model); + runner.run(null); + } catch (InvocationTargetException e) { + String error = "An error has occured during get reported data in current session"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error, reason, e); //$NON-NLS-1$ + return null; + } catch (InterruptedException e) { + String error = "An error has occured during get reported data in current session"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error, reason, e); //$NON-NLS-1$ + return null; + } + + return model; + } + + public static OpInfo getEventInfo() { + OpInfo info = new OpInfo(); + + try { + IRunnableWithProgress runner = OpcontrolDataProvider.getEventInfo(info); + runner.run(null); + + } catch (InvocationTargetException e) { + String error = "An error has occured during get event list in current session"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error , reason, e); //$NON-NLS-1$ + } catch (InterruptedException e) { + String error = "An error has occured during get event list in current session"; + String reason = "An unexpected error occurred with parsing data. This might be caused by closed connection to target"; + showErrorDialog(error , reason, e); //$NON-NLS-1$ + } + return info; + } + + public static void showErrorDialog(final String errorMessage, final String reasonMessage, final Exception ex) { + + final String dialogTitle = "Oprofile Error"; + final IStatus status = new Status(IStatus.ERROR, OprofileCorePlugin.getId(), IStatus.OK, reasonMessage, ex); + + Display.getDefault().syncExec(new Runnable() { + public void run() { + ErrorDialog.openError(null, dialogTitle, errorMessage, status); + } + }); + + } + + + public static String getCommandString(String[] comm){ + StringBuffer sb = new StringBuffer(); + for(int i=0;i + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core; + +import org.tizen.common.TizenPlatformConstants; + +public abstract class OprofileCommonConstants { + + private static final String COMMAND_PATH = TizenPlatformConstants.TOOLS_TARGET_PATH + "/oprofile/usr/bin/"; + + public static final String COMMAND_OPCONTROL = COMMAND_PATH+"opcontrol"; + + public static final String COMMAND_OPREPORT = "LD_LIBRARY_PATH=" + COMMAND_PATH + " " + COMMAND_PATH + "opreport"; + + public static final String COMMAND_OPHELP = COMMAND_PATH+"ophelp"; + + public static final String COMMAND_OPXML = COMMAND_PATH+"opxml"; + + public static final String LOG_PATH = "/var/lib/oprofile/samples/"; + + public static final String LOG_DAEMON = LOG_PATH+"oprofiled.log"; + + public static final String DEV_CPU_TYPE = "/dev/oprofile/cpu_type"; +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/checkevent/CheckEventsProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/checkevent/CheckEventsProcessor.java new file mode 100644 index 0000000..32c93ab --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/checkevent/CheckEventsProcessor.java @@ -0,0 +1,51 @@ +/* + * CheckEventsProcessor + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.checkevent; + +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileCommonConstants; + + +public class CheckEventsProcessor { + + private final String COMMAND_CHECK_EVENT = OprofileCommonConstants.COMMAND_OPHELP + + " -e"; + + public void parse(String event, int count, int unitmask, int[] result) + throws InterruptedException { + String[] resultStr = null; + + resultStr = CommandManager + .runCommandReturningResultArray(COMMAND_CHECK_EVENT + " " + + event + ":" + count + ":" + unitmask); + + if (resultStr != null && resultStr.length > 0 + && resultStr[0].trim().length() > 0) { + try { + result[0] = Integer.parseInt(resultStr[0].trim()); + } catch (NumberFormatException e) { + result[0] = -1; + } + } + + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/checkkernel/CheckKernelProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/checkkernel/CheckKernelProcessor.java new file mode 100644 index 0000000..05f9d85 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/checkkernel/CheckKernelProcessor.java @@ -0,0 +1,45 @@ +/* + * CheckKernel Processor + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.checkkernel; + + +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileCommonConstants; + +public class CheckKernelProcessor { + + private final String COMMAND_CHECK_KERNEL = "cat " + + OprofileCommonConstants.DEV_CPU_TYPE + " 2> /dev/null; echo"; + + public void parse(String[] result) throws InterruptedException { + String[] resultStr = null; + + resultStr = CommandManager + .runCommandReturningResultArray(COMMAND_CHECK_KERNEL); + + if (resultStr != null && resultStr.length > 0 + && resultStr[0].trim().length() > 0) { + result[0] = resultStr[0].trim(); + } + + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/eventinfo/EventListProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/eventinfo/EventListProcessor.java new file mode 100644 index 0000000..4e3c5ee --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/eventinfo/EventListProcessor.java @@ -0,0 +1,208 @@ +/* + * EventListProcessor + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.eventinfo; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.daemon.OpEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.daemon.OpUnitMask; +import org.eclipse.linuxtools.oprofile.core.daemon.OpUnitMask.MaskInfo; + +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileCommonConstants; + +public class EventListProcessor { + private OpInfo info; + private ArrayList[] eventList; + + public EventListProcessor(OpInfo info) throws InterruptedException { + this.info = info; + initializeEventList(); + } + + private void initializeEventList() { + eventList = new ArrayList[info.getNrCounters()]; + for (int i = 0; i < eventList.length; i++) { + eventList[i] = new ArrayList(); + } + } + + private static final String COMMAND_EVENT_LIST = OprofileCommonConstants.COMMAND_OPCONTROL + + " -l 2> /dev/null"; + private static final String EVENT_PATTERN = "^[A-Z1-9]+.*\\(counter: \\d+.*\\)$"; + //private static final String EVENT_DETAIL_PATTERN = "^\\s+.*\\(min count: \\d+\\).*"; + private static final String EVENT_DETAIL_PATTERN = ".*\\(min count: \\d+\\).*"; + private static final String UNIT_MASK_PATTERN = "Unit masks \\(default: 0x..\\)$"; + private static final String MASK_INFO_PATTERN = "0x..: .*"; + + public void parse() throws InterruptedException { + String resultStr = null; + + resultStr = CommandManager.runCommandReturningResult(COMMAND_EVENT_LIST); + + if (resultStr == null || resultStr.trim().length() == 0) + return; + + String eventStr[] = resultStr.split("\r?\n"); + OpEvent event = null; + OpUnitMask unitMask = null; + ArrayList maskList = null; + + boolean isDummy = true; + boolean isContinued = false; + String str = null; + String prevStr = null; + + for (int i = 0; i < eventStr.length; i++) { + + if (isContinued && !isDummy) { + str = prevStr + " " + eventStr[i].replaceFirst("^\\s*", ""); + } else { + str = eventStr[i]; + } + + isContinued = false; + + if (str.matches(EVENT_PATTERN)) { + setOpUnitMaskList(unitMask, maskList); + + event = new OpEvent(); + unitMask = new OpUnitMask(); + setOpEventUnitMask(event, unitMask); + setOpEventName(event, str); + setOpEventCounter(event, str); + + isDummy = false; + } else if (str.matches(EVENT_DETAIL_PATTERN)) { + setOpEventDescription(event, str); + setOpEventMinCount(event, str); + } else if (str.matches(UNIT_MASK_PATTERN)) { + setOpUnitMaskDefault(unitMask, str); + maskList = new ArrayList(); + } else if (str.matches(MASK_INFO_PATTERN)) { + addMaskInfo(maskList, str); + } else { + isContinued = true; + prevStr = eventStr[i]; + } + + } + + setOpInfoEventList(); + } + + private void setOpUnitMaskList(OpUnitMask unitMask, + ArrayList maskList) { + if (unitMask == null || (unitMask != null && maskList == null)) + return; + + unitMask._setMaskDescriptions(maskList.toArray(new MaskInfo[maskList + .size()])); + + boolean hasSameValue = false; + for (int i = 0; i < maskList.size(); i++) { + MaskInfo info = maskList.get(i); + if (info.value == unitMask.getMaskValue()) { + hasSameValue = true; + break; + } + } + + unitMask._setType(hasSameValue ? OpUnitMask.EXCLUSIVE + : OpUnitMask.BITMASK); + } + + private void addMaskInfo(ArrayList maskList, String str) { + int idx = str.indexOf(":"); + + String desc = str.substring(idx + 1, str.length()).trim(); + int val = Integer.parseInt(str.substring(2, idx).trim(), 16); + + MaskInfo maskInfo = new MaskInfo(); + maskInfo.description = desc; + maskInfo.value = val; + + maskList.add(maskInfo); + } + + private void setOpInfoEventList() { + for (int i = 0; i < eventList.length; i++) { + info._setEvents(i, + eventList[i].toArray(new OpEvent[eventList[i].size()])); + } + } + + private void setOpEventUnitMask(OpEvent event, OpUnitMask unitMask) { + event._setUnitMask(unitMask); + unitMask._setType(OpUnitMask.MANDATORY); + } + + private void setOpUnitMaskDefault(OpUnitMask unitMask, String str) { + String defaultUnitMask = str.substring(str.lastIndexOf("0x") + 2, + str.lastIndexOf(")")); + unitMask._setDefault(Integer.parseInt(defaultUnitMask, 16)); + } + + private void setOpEventMinCount(OpEvent event, String str) { + String minCount = str.substring(str.lastIndexOf(":") + 1, + str.lastIndexOf(")")); + event._setMinCount(Integer.parseInt(minCount.trim())); + } + + private void setOpEventDescription(OpEvent event, String str) { + String eventDescription = str.substring(0, str.lastIndexOf("(")); + event._setTextDescription(eventDescription.trim()); + } + + private void setOpEventCounter(OpEvent event, String str) { + String counters = str.substring(str.lastIndexOf(":") + 1, + str.lastIndexOf(")")); + if (counters == null) + return; + + if (counters.trim().equals("all")) { + for (int i = 0; i < eventList.length; i++) { + eventList[i].add(event); + } + } else { + String[] counter = counters.trim().split(","); + for (int i = 0; i < counter.length; i++) { + eventList[Integer.parseInt(counter[i].trim())].add(event); + } + } + } + + private void setOpEventName(OpEvent event, String str) { + String eventName = str.substring(0, str.indexOf(":")); + event._setText(eventName.trim()); + } + + public static void main(String[] args) { + String str = " 500) "; + String convStr = str.replaceFirst("^\\s*", ""); + + System.out.println("[" + str + "]"); + System.out.println("[" + convStr + "]"); + + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/eventinfo/OpInfoProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/eventinfo/OpInfoProcessor.java new file mode 100644 index 0000000..c4a0f62 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/eventinfo/OpInfoProcessor.java @@ -0,0 +1,69 @@ +/* + * OpInfoProcessor + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.eventinfo; + +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; + +import org.tizen.oprofile.core.CommandManager; + +public class OpInfoProcessor { + private OpInfo info; + + public OpInfoProcessor(OpInfo info) throws InterruptedException { + this.info = info; + } + + private final String COMMAND_COUNTER_NO = "ls -d /dev/oprofile/[0-9] -c1 2> /dev/null"; + + public void parse() throws InterruptedException { + String[] resultStr = null; + + resultStr = CommandManager.runCommandReturningResultArray(COMMAND_COUNTER_NO); + + if (resultStr != null && resultStr.length >1) { + // System.out.println("######## opcontrol -l : "+resultStr); + //int cnt = resultStr.split("\r?\n").length; + int cnt = resultStr.length; + info._setNrCounters(cnt); + info._setTimerMode(false); + } else { + // System.out.println("######## opcontrol -l : no data"); + info._setNrCounters(0); + info._setTimerMode(true); + } + + // FIXME:jinu removed at 20090620 + // this logic isn't exactly matched with real result + /* + * command = "grep \"cpu MHz\" /proc/cpuinfo"; + * + * try { resultStr = session.run(command); } catch (Exception e) { throw + * new InterruptedException(); } + * + * if(resultStr!=null&&resultStr.trim().length()>0){ String speed = + * resultStr.split(lineSeparator)[0].split(":")[1].trim(); + * info._setCPUSpeed(Double.parseDouble(speed)); }else{ + * info._setCPUSpeed(0); } + */ + + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/ModelDataProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/ModelDataProcessor.java new file mode 100644 index 0000000..345e8c3 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/ModelDataProcessor.java @@ -0,0 +1,84 @@ +/* + * ModelDataProcessor + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata; + +import java.io.IOException; +import java.io.StringReader; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelRoot; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileCommonConstants; +import org.tizen.oprofile.core.processor.modeldata.handler.OprofileSAXHandler; +import org.tizen.sdblib.SdbPreferences; + + +public class ModelDataProcessor{ + private OpModelRoot root; + + public ModelDataProcessor(OpModelRoot root) throws InterruptedException{ + this.root = root; + } + +// private final String DEFAULT_SESSION_NAME = "current"; + private final String COMMAND_SESSION_EVENT =OprofileCommonConstants.COMMAND_OPREPORT+" -gdlfX 2> /dev/null" +" | sed 's/^\\s /dev/null" +" | sed 's/^[^<]*//' | sed 's/&//'"; + + public void parse() throws InterruptedException, SAXException, IOException, ParserConfigurationException{ + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + + OprofileSAXHandler handler = new OprofileSAXHandler(root); + + String resultStr= null; + + //resultStr = session.run(COMMAND_SESSION_EVENT, null); + int orgtimeout = SdbPreferences.getTimeOut(); + SdbPreferences.setTimeOut(60000); + resultStr = CommandManager.runCommandReturningResult(COMMAND_SESSION_EVENT); + SdbPreferences.setTimeOut(orgtimeout); + + + if(resultStr==null||resultStr.trim().length() ==0){ +// root.reset(); + return; + }else{ + root.setXML(resultStr); + } + + try { + saxParser.parse(new InputSource(new StringReader(resultStr)),handler); + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/handler/OprofileSAXHandler.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/handler/OprofileSAXHandler.java new file mode 100644 index 0000000..d7dfc43 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/handler/OprofileSAXHandler.java @@ -0,0 +1,133 @@ +/* + * OprofileSAXHandler + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.handler; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelRoot; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import org.tizen.oprofile.core.processor.modeldata.parser.BinaryParser; +import org.tizen.oprofile.core.processor.modeldata.parser.ClassesParser; +import org.tizen.oprofile.core.processor.modeldata.parser.DetailTableParser; +import org.tizen.oprofile.core.processor.modeldata.parser.SetupParser; +import org.tizen.oprofile.core.processor.modeldata.parser.SymbolTableParser; + +public class OprofileSAXHandler extends DefaultHandler { + + + private String _valueStr; + private XMLParser _subParser = null; + + // setup - eventsetup | timersetup + private String SETUP_TAG = "setup"; + // classes - class + private String CLASSES_TAG = "classes"; + // binary - count | symbol | module + // module - count | symbol + // symbol - count + private String BINARY_TAG = "binary"; + private String BINARY_NAME_ATTR = "name"; + // symboltable - symboldata + private String SYMBOLTABLE_TAG = "symboltable"; + // detailtable - symboldetails - detaildata - count + private String DETAILTABLE_TAG = "detailtable"; + + private OpModelRoot _model; + private HashMap _imageMap; + private HashMap _symbolMap; + + public OprofileSAXHandler(OpModelRoot model){ + this._model = model; + } + + public void startDocument() { + _subParser = null; + _imageMap = new HashMap(); + _symbolMap = new HashMap(); + } + + public void startElement(String uri, String localName, String name, + Attributes attrs) throws SAXException { + +// System.out.print("<"+name); +// for(int i=0;i"); + + if(_subParser!=null) + _subParser.startElement(name, attrs, null); + + if (name.equals(SETUP_TAG)) { + _subParser = new SetupParser(_imageMap); + }else if(name.equals(CLASSES_TAG)) { + _subParser = new ClassesParser(_imageMap); + }else if (name.equals(BINARY_TAG)) { + String binaryName = attrs.getValue(BINARY_NAME_ATTR); + _subParser = new BinaryParser(binaryName,_imageMap, _symbolMap); + }else if (name.equals(SYMBOLTABLE_TAG)) { + _subParser = new SymbolTableParser(_imageMap,_symbolMap); + }else if (name.equals(DETAILTABLE_TAG)) { + _subParser = new DetailTableParser(_symbolMap); + } + + } + + public void characters(char[] buf, int start, int length) + throws SAXException { + _valueStr = new String(buf, start, length); + +// System.out.print(_valueStr); + + if(_subParser!=null) + _subParser.characters(_valueStr.trim(), null); + } + + public void endElement(String uri, String localName, String name) + throws SAXException { + +// System.out.println(""); + + if (name.equals(SETUP_TAG)) { + _subParser.release(_model); + _subParser = null; + }else if(name.equals(CLASSES_TAG)) { + _subParser = null; + }else if (name.equals(BINARY_TAG)) { + _subParser.release(null); + _subParser = null; + }else if (name.equals(SYMBOLTABLE_TAG)) { + _subParser = null; + }else if (name.equals(DETAILTABLE_TAG)) { + _subParser = null; + } + + if(_subParser!=null) + _subParser.endElement(name, null); + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/handler/XMLParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/handler/XMLParser.java new file mode 100644 index 0000000..2a615a4 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/handler/XMLParser.java @@ -0,0 +1,78 @@ +/* + * XMLParser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.handler; + +import org.xml.sax.Attributes; + +/** + * A class which (minimally) parses XML documents. This class provides only basic + * support for collecting information from XML documents. It is intended to be subclassed, + * providing only common functionality for all parser classes. + * @see org.eclipse.linuxtools.oprofile.core.opxml.OpxmlRunner + */ +public class XMLParser { + // The characters in the current tag + protected String _characters; + + /** + * This method is called whenever the SAXHandler is about to invoke the + * processor for the first time on a given document. + * @param callData call data for the processor (usually the result is stored here) + */ + public void reset(Object callData) { + }; + + //jinu added at 20090620 + public void release(Object callData) { + }; + + /** + * This method is called whenever a new tag is seen in the document. By default, + * this process will clear the characters collected for the tag. Processors will typically + * call this baseclass method to setup for collecting new character information for a + * tag. + * @param name the name of the tag + * @param attrs the tag's attributes + * @param callData call data for the processor (usually the result is stored here) + */ + public void startElement(String name, Attributes attrs, Object callData) { + _characters = new String(); + } + + /** + * This method is called whenever the closing tag for an element is seen in the + * document. + * @param name the element which is ending + * @param callData call data for the processor (usually the result is stored here) + */ + public void endElement(String name, Object callData) { + } + + /** + * This method is called whenever characters are seen in the document that are not in + * a markup tag. + * @param chars the characters read + * @param callData call data for the processor (usually the result is stored here) + */ + public void characters(String chars, Object callData) { + _characters = chars; + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/BinaryParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/BinaryParser.java new file mode 100644 index 0000000..66cd444 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/BinaryParser.java @@ -0,0 +1,145 @@ +/* + * Binary Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + +public class BinaryParser extends XMLParser { +// private static BinaryParser parser; + + private XMLParser _subParser; + private Attributes _attrs; + private String _valueStr; + private int _level; + + private static final String COUNT_TAG = "count"; + private static final String SYMBOL_TAG = "symbol"; + private static final String SYMBOL_IDREF_ATTR = "idref"; + private static final String MODULE_TAG = "module"; + private static final String MODULE_NAME_ATTR = "name"; + + private String _binaryName; + private HashMap _imageMap; + private HashMap _symbolMap; + + public BinaryParser(String binaryName, + HashMap imageMap, + HashMap symbolMap){ + + this._level = 0; + this._binaryName = binaryName; + this._imageMap = imageMap; + this._symbolMap = symbolMap; + } + + + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + + if(_subParser!=null) + _subParser.startElement(name, attrs, callData); + + if (_level<=1 && name.equals(COUNT_TAG)) { + _level = 1; + }else if (_level<=2 && name.equals(SYMBOL_TAG)) { + _level = 2; + String symbolIdRef = attrs.getValue(SYMBOL_IDREF_ATTR); + _subParser = new SymbolParser(symbolIdRef, _imageMap, _symbolMap); + }else if (_level<=3 && name.equals(MODULE_TAG)) { + _level = 3; + String moduleName = attrs.getValue(MODULE_NAME_ATTR); + _subParser = new ModuleParser(moduleName, _imageMap, _symbolMap); + } + } + + public void characters(String str, Object callData) { + set_valueStr(str); + if(_subParser!=null) + _subParser.characters(str, callData); + } + + public void endElement(String name, Object callData) { + + if (_level<=1 && name.equals(COUNT_TAG)) { + OpModelImage image = ParserUtil.getImage(_imageMap, ParserUtil.getImageKey(_attrs)); + image._setName(_binaryName); + }else if (_level<=2 && name.equals(SYMBOL_TAG)) { + _subParser = null; + }else if (_level<=3 && name.equals(MODULE_TAG)) { + _subParser = null; + } + + if(_subParser!=null) + _subParser.endElement(name, callData); + + + } + + public void release(Object callData) { + OpModelImage[] images = _imageMap.values().toArray(new OpModelImage[_imageMap.size()]); + + for(int i=0;i + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; + + +public class ClassesParser extends XMLParser { +// private static ClassesParser parser; + + private Attributes _attrs; + + private static final String CLASS_TAG = "class"; + private static final String CLASS_NAME_ATTR = "name"; + private static final String CLASS_EVENT_ATTR = "event"; + + private HashMap _imageMap; + + public ClassesParser(HashMap imageMap) { + + this._imageMap = imageMap; + } + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + } + + public void endElement(String name, Object callData) { + if (name.equals(CLASS_TAG)) { + changeImageId(_attrs.getValue(CLASS_EVENT_ATTR), _attrs.getValue(CLASS_NAME_ATTR)); + } + } + + private void changeImageId(String eventId, String imageId) { + OpModelImage image = _imageMap.get(eventId); + if(image!=null){ + _imageMap.remove(eventId); + _imageMap.put(imageId, image); + } + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/DetailDataParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/DetailDataParser.java new file mode 100644 index 0000000..1adb7c0 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/DetailDataParser.java @@ -0,0 +1,97 @@ +/* + * Detail Data Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelSample; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + + +public class DetailDataParser extends XMLParser { +// private static DetailDataParser parser; + + private Attributes _attrs; + private String _valueStr; + + private static final String COUNT_TAG = "count"; + + private String _symbolId; + private int _sampleLine; + private HashMap _symbolMap; + + public DetailDataParser(String symbolId, int sampleLine, + HashMap symbolMap){ + + this._symbolId = symbolId; + this._sampleLine = sampleLine; + this._symbolMap = symbolMap; + } + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + } + + public void characters(String str, Object callData) { + _valueStr = str; + } + + public void endElement(String name, Object callData) { + if (name.equals(COUNT_TAG)) { + + int count = Integer.parseInt(_valueStr); + + String imageId = ParserUtil.getImageKey(_attrs); + OpModelSymbol symbol = _symbolMap.get(ParserUtil.getSymbolKey(imageId,_symbolId)); + + OpModelSample sample = getSample(symbol, _sampleLine); + if(sample==null){ + sample = new OpModelSample(); + sample._setCount(count); + sample._setLine(_sampleLine); + + symbol._addSample(sample); + }else{ + sample._setCount(sample.getCount()+count); + } + + } + } + + private OpModelSample getSample(OpModelSymbol symbol, int sampleLine) { + OpModelSample[] samples = symbol.getSamples(); + + for(int i=0;i + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; + + + +public class DetailTableParser extends XMLParser { +// private static DetailTableParser parser; + + private XMLParser _subParser; + private Attributes _attrs; + private String _valueStr; + + private static final String SYMBOL_DETAILS_TAG = "symboldetails"; + private static final String SYMBOL_DETAILS_ID_ATTR = "id"; + + private HashMap _symbolMap; + + public DetailTableParser(HashMap symbolMap){ + + this._symbolMap = symbolMap; + } + + public void startElement(String name, Attributes attrs, Object callData) { + set_attrs(attrs); + + if(_subParser!=null) + _subParser.startElement(name, attrs, callData); + + if (name.equals(SYMBOL_DETAILS_TAG)) { + String symbolId = attrs.getValue(SYMBOL_DETAILS_ID_ATTR); + _subParser = new SymbolDetailsParser(symbolId, _symbolMap); + } + } + + public void characters(String str, Object callData) { + set_valueStr(str); + if(_subParser!=null) + _subParser.characters(str, callData); + } + + public void endElement(String name, Object callData) { + + if (name.equals(SYMBOL_DETAILS_TAG)) { + _subParser = null; + } + + if(_subParser!=null) + _subParser.endElement(name, callData); + } + + public void set_attrs(Attributes _attrs) { + this._attrs = _attrs; + } + + public Attributes get_attrs() { + return _attrs; + } + + public void set_valueStr(String _valueStr) { + this._valueStr = _valueStr; + } + + public String get_valueStr() { + return _valueStr; + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/ModuleParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/ModuleParser.java new file mode 100644 index 0000000..cadba05 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/ModuleParser.java @@ -0,0 +1,104 @@ +/* + * Module Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + + + +public class ModuleParser extends XMLParser { +// private static ModuleParser parser; + + private XMLParser _subParser; + private Attributes _attrs; + private String _valueStr; + private int _level; + + private static final String COUNT_TAG = "count"; + private static final String SYMBOL_TAG = "symbol"; + private static final String SYMBOL_IDREF_ATTR = "idref"; + + private String _moduleName; + private HashMap _imageMap; + private HashMap _symbolMap; + private HashMap _dependentMap = new HashMap(); + + public ModuleParser(String moduleName, + HashMap imageMap, + HashMap symbolMap){ + + this._level = 0; + this._moduleName = moduleName; + this._imageMap = imageMap; + this._symbolMap = symbolMap; + } + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + + if(_subParser!=null) + _subParser.startElement(name, attrs, callData); + + if (_level<=1 && name.equals(COUNT_TAG)) { + _level = 1; + }else if (_level<=2 && name.equals(SYMBOL_TAG)) { + _level = 2; + String symbolIdRef = attrs.getValue(SYMBOL_IDREF_ATTR); + _subParser = new ModuleSymbolParser(symbolIdRef, _dependentMap, _symbolMap); + } + } + + public void characters(String str, Object callData) { + _valueStr = str; + if(_subParser!=null) + _subParser.characters(str, callData); + } + + public void endElement(String name, Object callData) { + + if (_level<=1 && name.equals(COUNT_TAG)) { + OpModelImage dependent = new OpModelImage(); + dependent._setCount(Integer.parseInt(_valueStr)); + dependent._setName(_moduleName); + + String imageId = ParserUtil.getImageKey(_attrs); + + OpModelImage image = ParserUtil.getImage(_imageMap, imageId); + image._addDependent(dependent); + + _dependentMap.put(imageId, dependent); + }else if (_level<=2 && name.equals(SYMBOL_TAG)) { + _subParser = null; + } + + if(_subParser!=null) + _subParser.endElement(name, null); + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/ModuleSymbolParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/ModuleSymbolParser.java new file mode 100644 index 0000000..faa9f80 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/ModuleSymbolParser.java @@ -0,0 +1,77 @@ +/* + * Module Symbol Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + + +public class ModuleSymbolParser extends XMLParser { +// private static ModuleSymbolParser parser; + + private Attributes _attrs; + private String _valueStr; + + private static final String COUNT_TAG = "count"; + + private String _idRef; + private HashMap _dependentMap; + private HashMap _symbolMap; + + public ModuleSymbolParser(String idRef, + HashMap dependentMap, + HashMap symbolMap) { + + this._idRef = idRef; + this._dependentMap = dependentMap; + this._symbolMap = symbolMap; + } + + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + } + + public void characters(String str, Object callData) { + _valueStr = str; + } + + public void endElement(String name, Object callData) { + if (name.equals(COUNT_TAG)) { + OpModelSymbol symbol = new OpModelSymbol(); + symbol._setCount(Integer.parseInt(_valueStr)); + + String imageId = ParserUtil.getImageKey(_attrs); + OpModelImage dependent = ParserUtil.getImage(_dependentMap, imageId); + dependent._addSymbol(symbol); + + _symbolMap.put(ParserUtil.getSymbolKey(imageId,_idRef), symbol); + } + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SetupParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SetupParser.java new file mode 100644 index 0000000..6c841ae --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SetupParser.java @@ -0,0 +1,99 @@ +/* + * Setup Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelRoot; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSession; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + +public class SetupParser extends XMLParser { +// private static SetupParser parser; + + private Attributes _attrs; + + private static final String EVENTSETUP_TAG = "eventsetup"; + private static final String EVENTSETUP_EVENTNAME_ATTR = "eventname"; + private static final String EVENTSETUP_ID_ATTR = "id"; + private static final String TIMERSETUP_TAG = "timersetup"; + + private final String DEFAULT_SESSION_NAME = "current"; + private final String TIMER_EVENT_NAME = "TIMER"; + + private ArrayList _eventList = new ArrayList(); + private HashMap _imageMap; + + public SetupParser(HashMap imageMap) { + this._imageMap = imageMap; + } + + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + } + + public void endElement(String name, Object callData) { + String eventName = _attrs.getValue(EVENTSETUP_EVENTNAME_ATTR); + String eventId = _attrs.getValue(EVENTSETUP_ID_ATTR)==null?ParserUtil.DEFAULT_EVENT_ID:_attrs.getValue(EVENTSETUP_ID_ATTR); + + if (name.equals(EVENTSETUP_TAG)) { + addEvent(eventId, eventName); + } else if (name.equals(TIMERSETUP_TAG)) { + addEvent(eventId, TIMER_EVENT_NAME); + } + } + + private void addEvent(String eventId, String eventName) { + OpModelEvent event = new OpModelEvent(eventName); + OpModelImage image = new OpModelImage(); + + OpModelSession[] sessions = new OpModelSession[1]; + sessions[0] = new OpModelSession(event, DEFAULT_SESSION_NAME); + sessions[0]._setImage(image); + + event._setSessions(sessions); + + _eventList.add(event); + _imageMap.put(eventId,image); + } + + public void release(Object data) { + changeImageId(); + + OpModelRoot model = (OpModelRoot) data; + model._setEvents(_eventList.toArray(new OpModelEvent[_eventList.size()])); + } + + private void changeImageId() { + if(_imageMap.size()==1){ + OpModelImage[] image = _imageMap.values().toArray(new OpModelImage[1]); + _imageMap.remove(image[0]); + _imageMap.put(ParserUtil.DEFAULT_EVENT_ID,image[0]); + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolDetailsParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolDetailsParser.java new file mode 100644 index 0000000..989d02c --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolDetailsParser.java @@ -0,0 +1,102 @@ +/* + * Symbol Details Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; + + + +public class SymbolDetailsParser extends XMLParser { +// private static SymbolDetailsParser parser; + + private XMLParser _subParser; + private Attributes _attrs; + private String _valueStr; + + private static final String DETAIL_DATA_TAG = "detaildata"; + private static final String DETAIL_DATA_LINE_ATTR = "line"; + + private String _symbolId; + private HashMap _symbolMap; + + public SymbolDetailsParser(String symboldId, + HashMap symbolMap){ + + this._symbolId = symboldId; + this._symbolMap = symbolMap; + } + + public void startElement(String name, Attributes attrs, Object callData) { + set_attrs(attrs); + + if(_subParser!=null) + _subParser.startElement(name, attrs, callData); + + + if (name.equals(DETAIL_DATA_TAG)) { + String sampleLine = attrs.getValue(DETAIL_DATA_LINE_ATTR); + int line = sampleLine==null?0:Integer.parseInt(sampleLine); + _subParser = new DetailDataParser(_symbolId,line, _symbolMap); + } + + } + + public void characters(String str, Object callData) { + set_valueStr(str); + if(_subParser!=null) + _subParser.characters(str, callData); + + } + + public void endElement(String name, Object callData) { + + if (name.equals(DETAIL_DATA_TAG)) + _subParser = null; + + + if(_subParser!=null) + _subParser.endElement(name, callData); + + } + + public void set_attrs(Attributes _attrs) { + this._attrs = _attrs; + } + + public Attributes get_attrs() { + return _attrs; + } + + public void set_valueStr(String _valueStr) { + this._valueStr = _valueStr; + } + + public String get_valueStr() { + return _valueStr; + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolParser.java new file mode 100644 index 0000000..c899e97 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolParser.java @@ -0,0 +1,77 @@ +/* + * Symbol Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + + +public class SymbolParser extends XMLParser { +// private static SymbolParser parser; + + private Attributes _attrs; + private String _valueStr; + + private static final String COUNT_TAG = "count"; + + private String _idRef; + private HashMap _imageMap; + private HashMap _symbolMap; + + public SymbolParser(String idRef, + HashMap imageMap, + HashMap symbolMap) { + + this._idRef = idRef; + this._imageMap = imageMap; + this._symbolMap = symbolMap; + } + + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + } + + public void characters(String str, Object callData) { + _valueStr = str; + } + + public void endElement(String name, Object callData) { + if (name.equals(COUNT_TAG)) { + OpModelSymbol symbol = new OpModelSymbol(); + symbol._setCount(Integer.parseInt(_valueStr)); + + String imageId = ParserUtil.getImageKey(_attrs); + OpModelImage image = ParserUtil.getImage(_imageMap, imageId); + image._addSymbol(symbol); + + _symbolMap.put(ParserUtil.getSymbolKey(imageId,_idRef), symbol); + } + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolTableParser.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolTableParser.java new file mode 100644 index 0000000..5eaa14b --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/parser/SymbolTableParser.java @@ -0,0 +1,82 @@ +/* + * Symbol Table Parser + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.parser; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSymbol; +import org.xml.sax.Attributes; + +import org.tizen.oprofile.core.processor.modeldata.handler.XMLParser; +import org.tizen.oprofile.core.processor.modeldata.util.ParserUtil; + + +public class SymbolTableParser extends XMLParser { +// private static SymbolTableParser parser; + + private Attributes _attrs; + + private static final String SYMBOLDATA_TAG = "symboldata"; + private static final String SYMBOLDATA_ID_ATTR = "id"; + private static final String SYMBOLDATA_NAME_ATTR = "name"; + private static final String SYMBOLDATA_FILE_ATTR = "file"; + private static final String SYMBOLDATA_LINE_ATTR = "line"; + + private String[] _imageIds; + private HashMap _symbolMap; + + public SymbolTableParser(HashMap imageMap, + HashMap symbolMap) { + + this._imageIds = imageMap.keySet().toArray(new String[imageMap.size()]); + this._symbolMap = symbolMap; + } + + + public void startElement(String name, Attributes attrs, Object callData) { + _attrs = attrs; + } + + public void endElement(String name, Object callData) { + if (name.equals(SYMBOLDATA_TAG)) { + String symbolId = _attrs.getValue(SYMBOLDATA_ID_ATTR); + String symbolName = _attrs.getValue(SYMBOLDATA_NAME_ATTR); + String symbolFile = _attrs.getValue(SYMBOLDATA_FILE_ATTR); + String symbolLine = _attrs.getValue(SYMBOLDATA_LINE_ATTR); + + setSymbolDetail(symbolId, symbolName, symbolFile, symbolLine); + } + } + + + private void setSymbolDetail(String symbolId, String symbolName, String symbolFile, String symbolLine) { + for(String imageId : _imageIds){ + OpModelSymbol symbol = _symbolMap.get(ParserUtil.getSymbolKey(imageId,symbolId)); + if(symbol!=null){ + if(symbolFile!=null) + symbol._setFile(symbolFile); + symbol._setName(symbolName); + } + } + } + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/util/ParserUtil.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/util/ParserUtil.java new file mode 100644 index 0000000..4063b2b --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/modeldata/util/ParserUtil.java @@ -0,0 +1,52 @@ +/* + * Parser Util + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.modeldata.util; + +import java.util.HashMap; + +import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; +import org.xml.sax.Attributes; + +public abstract class ParserUtil { + + private static final String COUNT_CLASS_ATTR = "class"; + public static final String DEFAULT_EVENT_ID = ""; + + public static String getImageKey(Attributes attrs) { + String key = attrs.getValue(COUNT_CLASS_ATTR); + return key==null?DEFAULT_EVENT_ID:key; + } + + public static String getSymbolKey(String imageId, String symbolId) { + if(imageId==null||imageId.equals(DEFAULT_EVENT_ID)) + return symbolId; + else + return imageId+":"+symbolId; + } + + public static OpModelImage getImage(HashMap imageMap, String imageId) { + String key = imageId==null?DEFAULT_EVENT_ID:imageId; + return imageMap.get(key); + } + + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/sessions/SessionsProcessor.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/sessions/SessionsProcessor.java new file mode 100644 index 0000000..1839831 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/processor/sessions/SessionsProcessor.java @@ -0,0 +1,89 @@ +/* + * Sessions Processor + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.processor.sessions; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.oprofile.core.Oprofile; +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelSession; + +import org.tizen.oprofile.core.CommandManager; +import org.tizen.oprofile.core.OprofileCommonConstants; + + +public class SessionsProcessor{ + + public SessionsProcessor() throws InterruptedException{ + } + + private final String DEFAULT_SESSION_NAME = "current"; + private final String TIMER_EVENT = "TIMER"; + private final String COMMAND_SESSION_EVENT =OprofileCommonConstants.COMMAND_OPCONTROL+" --status 2> /dev/null | grep ^Event"; + + public void parse(ArrayList eventList) throws InterruptedException{ + if(Oprofile.getTimerMode()){ + addTimerEvent(eventList); + return; + } + + String[] resultStr= null; + + resultStr = CommandManager.runCommandReturningResultArray(COMMAND_SESSION_EVENT); + + if(resultStr==null||resultStr.length == 0 ) + return; + + + for(int i=0;i eventList) { + OpModelEvent event = new OpModelEvent(TIMER_EVENT); + + OpModelSession[] sessions = new OpModelSession[1]; + sessions[0] = new OpModelSession(event,DEFAULT_SESSION_NAME); + + event._setSessions(sessions); + + eventList.add(event); + } + + private void addEvent(ArrayList eventList, String str) { + String[] strs = str.split(":"); + + if(strs.length<6) + return; + + OpModelEvent event = new OpModelEvent(strs[1].trim()); + + OpModelSession[] sessions = new OpModelSession[1]; + sessions[0] = new OpModelSession(event,DEFAULT_SESSION_NAME); + + event._setSessions(sessions); + eventList.add(event); + } + + +} diff --git a/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/provider/OpcontrolDataProvider.java b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/provider/OpcontrolDataProvider.java new file mode 100644 index 0000000..9925475 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.core/src/org/tizen/oprofile/core/provider/OpcontrolDataProvider.java @@ -0,0 +1,129 @@ +/* + * Opcontrol Data Provider + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.core.provider; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; +import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; +import org.eclipse.linuxtools.oprofile.core.model.OpModelRoot; + +import org.tizen.oprofile.core.processor.checkevent.CheckEventsProcessor; +import org.tizen.oprofile.core.processor.checkkernel.CheckKernelProcessor; +import org.tizen.oprofile.core.processor.eventinfo.EventListProcessor; +import org.tizen.oprofile.core.processor.eventinfo.OpInfoProcessor; +import org.tizen.oprofile.core.processor.modeldata.ModelDataProcessor; +import org.tizen.oprofile.core.processor.sessions.SessionsProcessor; +import org.xml.sax.SAXException; + +public abstract class OpcontrolDataProvider{ + + + public static IRunnableWithProgress getEventInfo(final OpInfo info) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { +// if(!OprofileComm.checkTarget()) return; + + new OpInfoProcessor(info).parse(); + + if(!info.getTimerMode()){ + new EventListProcessor(info).parse(); + } + + } + }; + + return runnable; + } + + public static IRunnableWithProgress checkEvent(final String event, final int count, final int unitmask, final int[] result) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { +// if(!OprofileComm.checkTarget()) return; + + new CheckEventsProcessor().parse(event,count, unitmask,result); + + } + }; + + return runnable; + } + + + public static IRunnableWithProgress getEventList(final ArrayList eventList) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { +// if(!OprofileComm.checkTarget()) return; + //ISession session = OprofileComm.getSession(); + + new SessionsProcessor().parse(eventList); + } + }; + + return runnable; + } + + public static IRunnableWithProgress getModelData(final OpModelRoot model) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { +// if(!OprofileComm.checkTarget()) return; + //ISession session = OprofileComm.getSession(); + + try { + new ModelDataProcessor(model).parse(); + } catch (InterruptedException e) { + throw new InterruptedException(); + } catch (SAXException e) { + throw new InterruptedException(); + } catch (IOException e) { + throw new InterruptedException(); + } catch (ParserConfigurationException e) { + throw new InterruptedException(); + } + } + }; + + return runnable; + } + + public static IRunnableWithProgress checkKernelModule(final String[] result) { + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { +// if(!OprofileComm.checkTarget()) return; + //ISession session = OprofileComm.getSession(); + + new CheckKernelProcessor().parse(result); + + } + }; + + return runnable; + } + + + +} diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/.classpath b/org.eclipse.linuxtools.oprofile.launch.exe/.classpath new file mode 100644 index 0000000..4c62a80 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/.project b/org.eclipse.linuxtools.oprofile.launch.exe/.project new file mode 100644 index 0000000..3f9c10a --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.oprofile.launch.exe + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/.settings/org.eclipse.core.resources.prefs b/org.eclipse.linuxtools.oprofile.launch.exe/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..fcc43a9 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Wed Dec 01 09:13:21 CET 2010 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.linuxtools.oprofile.launch.exe/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000..f02480a --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Tue Dec 14 16:36:28 CET 2010 +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.oprofile.launch.exe/META-INF/MANIFEST.MF new file mode 100644 index 0000000..85e7045 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/META-INF/MANIFEST.MF @@ -0,0 +1,37 @@ +Manifest-Version: 1.0 +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.0", + org.eclipse.ui;bundle-version="3.4.0", + org.eclipse.cdt.core;bundle-version="5.2.1", + org.eclipse.cdt.debug.core;bundle-version="5.0.1", + org.eclipse.cdt.launch;bundle-version="6.1.0", + org.eclipse.linuxtools.oprofile.core, + org.eclipse.linuxtools.oprofile.launch, + org.eclipse.debug.ui;bundle-version="3.4.2", + org.eclipse.linuxtools.profiling.launch, + org.tizen.common, + org.tizen.common.connection, + org.tizen.nativecommon +Bundle-Vendor: Eclipse Linux Tools +Bundle-Version: 1.3.18.qualifier +Bundle-Name: Tizen SDK Oprofile Exe Launch +Bundle-ManifestVersion: 2 +Import-Package: org.eclipse.cdt.debug.core, + org.eclipse.cdt.managedbuilder.core, + org.eclipse.debug.core, + org.eclipse.linuxtools.oprofile.core, + org.eclipse.linuxtools.oprofile.core.daemon, + org.eclipse.linuxtools.oprofile.ui, + org.eclipse.linuxtools.oprofile.ui.view, + org.eclipse.ui, + org.tizen.nativecommon.launch, + org.tizen.nativecommon.launch.ui, + org.tizen.sdblib +Bundle-SymbolicName: org.eclipse.linuxtools.oprofile.launch.exe;singleton:=true +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Activator: org.tizen.oprofile.launch.Activator +Export-Package: org.tizen.oprofile.launch + + + + + diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/NOTICE b/org.eclipse.linuxtools.oprofile.launch.exe/NOTICE new file mode 100644 index 0000000..ece0184 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/NOTICE @@ -0,0 +1,65 @@ +2010-01-25 Dawid Kozinski + * plugin.xml : add cnature property + +2010-02-03 SPRC SDK Team + * MANIFEST.MF : changed some package names + * plugin.xml : changed some package names + +2010-02-10 SPRC SDK Team + * MANIFEST.MF : remove Bundle-Localization, fix Bundle-Activator + +2010-07-14 HyungJong, Shin + * plugin.xml : delete daemon property + +2010-07-23 HyungJong, Shin + * NormalOprofileDeployer.java : application launching exception message shows several times.==> solved + +2010-11-05 sdk + * MANIFEST.MF : changed some package name + * plugin.xml : changed some package name + +2010-11-09 DongGi Jang + * MANIFEST.MF : changed launcher name + +2011-06-07 jaewon81.lim + * MANIFEST.MF : modify imported package name of freshide.common.ui + +2011-06-09 jaewon81.lim + * MANIFEST.MF : rearrange plugins dependency + +2011-07-13 jaewon81.lim + * MANIFEST.MF : modified import package name + +2011-08-22 joogwan.kim + * MANIFEST.MF : Change plug-in name + +2011-08-25 wonhyoung2.park + * MANIFEST.MF : plugin provider and name modified + +2011-09-28 wonhyoung2.park + * SLPOprofileLaunchDelegate.java : add oprofile build configuration selection routine + +2011-11-16 wonhyoung2.park + * MANIFEST.MF : Profiler sdb apply + +2011-11-22 taeyoung2.son + * MANIFEST.MF : Modify SDK naming from "SLP(or Samsung Linux Platform)" to "Tizen" + * plugin.xml : Modify SDK naming from "SLP(or Samsung Linux Platform)" to "Tizen" + +2011-11-29 wonhyoung2.park + * MANIFEST.MF : chagne slp to tizen + * plugin.xml : chagne slp to tizen + +2011-12-02 taeyoung2.son + * MANIFEST.MF : Delete dependency feature's version value. + +2011-12-03 wonhyoung2.park + * MANIFEST.MF : package instll routine chage + +2011-12-04 wonhyoung2.park + * MANIFEST.MF : change oprofile install + * plugin.xml : change oprofile install + +2011-12-12 wonhyoung2.park + * plugin.xml : profile menu only show in native perspective + diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/build.properties b/org.eclipse.linuxtools.oprofile.launch.exe/build.properties new file mode 100644 index 0000000..90406de --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/ +javacSource = 1.6 +javacTarget = 1.6 diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/icons/event_tab.gif b/org.eclipse.linuxtools.oprofile.launch.exe/icons/event_tab.gif new file mode 100644 index 0000000..c91f254 Binary files /dev/null and b/org.eclipse.linuxtools.oprofile.launch.exe/icons/event_tab.gif differ diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/icons/global_tab.gif b/org.eclipse.linuxtools.oprofile.launch.exe/icons/global_tab.gif new file mode 100644 index 0000000..ec6cca4 Binary files /dev/null and b/org.eclipse.linuxtools.oprofile.launch.exe/icons/global_tab.gif differ diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/icons/profile_run.png b/org.eclipse.linuxtools.oprofile.launch.exe/icons/profile_run.png new file mode 100644 index 0000000..4f8488f Binary files /dev/null and b/org.eclipse.linuxtools.oprofile.launch.exe/icons/profile_run.png differ diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/plugin.xml b/org.eclipse.linuxtools.oprofile.launch.exe/plugin.xml new file mode 100644 index 0000000..86eb610 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/plugin.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/Activator.java b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/Activator.java new file mode 100644 index 0000000..e7c6af8 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/Activator.java @@ -0,0 +1,67 @@ +/* + * Activator + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.launch; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin { + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/NormalOprofileLaunchShortcut.java b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/NormalOprofileLaunchShortcut.java new file mode 100644 index 0000000..91b94c8 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/NormalOprofileLaunchShortcut.java @@ -0,0 +1,93 @@ +/* + * Normal Oprofile Launch Shortcut + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.launch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchMessages; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchPlugin; +import org.eclipse.linuxtools.oprofile.launch.configuration.LaunchOptions; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchPlugin; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut; +import org.eclipse.ui.IEditorPart; + + +/** + * A class that takes care of the right-click -> profile with oprofile + * shortcut, where the ProfileLaunchShortcut has the logic to automatically + * find binaries and create a default launch if one doesn't exist. + */ +public class NormalOprofileLaunchShortcut extends ProfileLaunchShortcut { + + public void launch(IEditorPart editor, String mode) { + int targetResult = ProfileLaunchPlugin.checkTarget(); + if(targetResult == 0) + { + ProfileLaunchShortcut.showErrorDialog(OprofileLaunchMessages.getString("common.cannotrun"), + OprofileLaunchMessages.getString("common.notarget"), null); + } + else + { + super.launch(editor, mode); + } + } + + public void launch(ISelection selection, String mode) { + int targetResult = ProfileLaunchPlugin.checkTarget(); + if(targetResult == 0) + { + ProfileLaunchShortcut.showErrorDialog(OprofileLaunchMessages.getString("common.cannotrun"), + OprofileLaunchMessages.getString("common.notarget"), null); + } + else + { + super.launch(selection, mode); + } + } + + @Override + protected ILaunchConfigurationType getLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType(OprofileLaunchPlugin.ID_LAUNCH_PROFILE); + } + + /** + * Default settings for the OProfile-specific option tabs. + */ + @Override + protected void setDefaultProfileAttributes(ILaunchConfigurationWorkingCopy wc) throws CoreException { + //default global setup options + LaunchOptions options = new LaunchOptions(); + options.saveConfiguration(wc); + + //default event option + wc.setAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, true); + + // commented by greatim at 2011.06.01 for fresh ide + //jinu added at 20090618 +// wc.setAttribute(ISMLCDTLaunchConstants.ATTR_LAUNCH_MODE, "oprofile"); +// wc.setAttribute(ISMLCDTLaunchConstants.ATTR_SKIP_DOWNLOAD, false); + wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/TizenOprofileLaunchDelegate.java b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/TizenOprofileLaunchDelegate.java new file mode 100644 index 0000000..04b03a0 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/TizenOprofileLaunchDelegate.java @@ -0,0 +1,427 @@ +/* + * Tizen Oprofile Launch Delegate + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.launch; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +import org.eclipse.cdt.debug.core.CDebugUtils; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.linuxtools.oprofile.core.OpcontrolException; +import org.eclipse.linuxtools.oprofile.core.Oprofile; +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchPlugin; +import org.eclipse.linuxtools.oprofile.launch.configuration.LaunchOptions; +import org.eclipse.linuxtools.oprofile.launch.configuration.OprofileCounter; +import org.eclipse.linuxtools.oprofile.ui.OprofileUiPlugin; +import org.eclipse.linuxtools.oprofile.ui.view.OprofileView; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.tizen.common.TizenPlatformConstants; +import org.tizen.nativecommon.launch.IProjectLaunchCommand; +import org.tizen.nativecommon.launch.TizenLaunchCommand; +import org.tizen.nativecommon.launch.TizenLaunchDelegate; +import org.tizen.nativecommon.launch.TizenLaunchMessages; +import org.tizen.oprofile.core.CommandManager; +import org.tizen.sdblib.SdbShellProcess; +import org.tizen.nativecommon.Activator; +import org.tizen.nativecommon.ProjectUtil; + +public class TizenOprofileLaunchDelegate extends TizenLaunchDelegate { + + protected static final String MAKE_DIRECTORY_CMD = "mkdir -p "; + protected static final String CHANGE_DIRECTORY_CMD = "cd "; + + protected static final String PACKAGE_NAME = "oprofile"; + protected static final String PACKAGE_FILENAME_ARM = "oprofile_armel.deb"; + protected static final String BADA_EXT = ".exe"; + + protected static String appName = null; + + public static String getAppName() { + return appName; + } + + public static void setAppName(String appName) { + TizenOprofileLaunchDelegate.appName = appName; + } + + @Override + public void launch(ILaunchConfiguration config, String mode, + ILaunch launch, IProgressMonitor monitor) throws CoreException { + if (monitor == null) + monitor = new NullProgressMonitor(); + try { + + monitor.beginTask(TizenLaunchMessages.LAUNCH_APPLICATION, 30); + + activateProgressView(); + + verifyCProjectConfigurationSettings(config); + verifyDeviceReachability(ProjectUtil.getProject(config), + new SubProgressMonitor(monitor, 9)); + verifyBuildConfiguration(config, mode, new SubProgressMonitor( + monitor, 11)); + + setConsole(config); + tizenCommand = new TizenLaunchCommand(currentDevice, launchConsole); + // FIXME: ad-hoc code. + launchConsole.show(); + + Oprofile.getOpInfo(); + + // ISession session = getLaunchSession(config, new + // SubProgressMonitor(monitor, 1)); + + if (mode.equals(ILaunchManager.PROFILE_MODE)) { + deployApplication(config, new SubProgressMonitor(monitor, 9)); + monitor.worked(1); + + launchApplicationWithOprofile(launch, config, monitor); + } else { + newCoreException(TizenLaunchMessages.CANNOT_LAUNCH, null); + } + } finally { + monitor.done(); + } + } + + protected void launchApplicationWithOprofile(ILaunch launch, + ILaunchConfiguration config, IProgressMonitor monitor) + throws CoreException { + try { + // check oprofile tool + checkProfilingTool(monitor); + + IProjectLaunchCommand manifest = ProjectUtil.getProjectManifest(ProjectUtil.getProject(config)); + String remoteExePath = TizenPlatformConstants.APP_INSTALL_PATH + "/" + manifest.getPackageName() + "/bin/"; +// String cmd = "cd " + remoteExePath + CMD_RESULT_CHECK; +// // String resultRsp = session.run(cmd, null); +// String[] resultRsp = CommandManager +// .runCommandReturningResultArray(cmd); +// if (!CommandManager.isRunSeccessfuly(resultRsp)) +// newCoreException(TizenLaunchMessages.CANNOT_LAUNCH, +// new Exception("Cannot change to run-directory : " +// + ". (Return Code: " + resultRsp + ")")); + + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + IPath exeFile = CDebugUtils.verifyProgramPath(config); + remoteExePath += exeFile.toFile().getName(); + + // for bada application + // execute non-exe file instead of .exe file + if(remoteExePath.endsWith(BADA_EXT)) + { + remoteExePath = remoteExePath.substring(0, remoteExePath.length() - BADA_EXT.length()); + } + + String cmd = "ls " + remoteExePath + TizenPlatformConstants.CMD_SUFFIX; + // resultRsp = session.run(cmd, null); + String[] resultRsp = CommandManager.runCommandReturningResultArray(cmd); + if (!CommandManager.isRunSeccessfuly(resultRsp)) + newCoreException( + TizenLaunchMessages.CANNOT_LAUNCH, + new Exception( + "Executable does not exist on a valid path. You must install your application before running it.")); + + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + monitor.worked(2); + + preProcedure(config, launch, monitor, remoteExePath); + + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + String arguments = config + .getAttribute( + ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, + ""); + cmd = remoteExePath.trim(); + appName = remoteExePath; + if (arguments != null && !arguments.equals("")) + cmd += " " + arguments; + + // remoteShellProcess = session.launch(cmd, null); + // CommandManager.runShell(cmd); + runApplication(config, launch, cmd); + + if (monitor.isCanceled()) + throw new OperationCanceledException(); + + postProcedure(config, launch, monitor); + + if (monitor.isCanceled()) + throw new OperationCanceledException(); + } catch (CoreException e) { + newCoreException(e.getMessage(), e.getCause()); + } catch (OperationCanceledException e) { + newCoreException("Operation canceled by user.", null); + } catch (Exception e) { + newCoreException(TizenLaunchMessages.CANNOT_LAUNCH, e); + } finally { + monitor.done(); + } + } + + private void runApplication(ILaunchConfiguration config, ILaunch launch, + String command) { + SdbShellProcess oprofileProc = CommandManager.runApplication(command); + IPath exeFile = null; + try { + exeFile = CDebugUtils.verifyProgramPath(config); + DebugPlugin.newProcess(launch, oprofileProc, exeFile + .toFile().getName()); + BufferedReader br = new BufferedReader(new InputStreamReader( + oprofileProc.getInputStream())); + while (null != br.readLine()) { + ; + } + br.close(); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private void preProcedure(ILaunchConfiguration config, ILaunch launch, + IProgressMonitor monitor, String imagePath) throws CoreException { + // FIXME: this assumes that project names are always the directory names + // in the workspace. + // this assumption may be wrong, but a shallow lookup seems ok + // jinu removed at 20090603 + /* + * String workspacePath = + * ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); + * String imagePath = workspacePath + Path.SEPARATOR + + * config.getAttribute + * (ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "") + * //$NON-NLS-1$ + Path.SEPARATOR + + * config.getAttribute(ICDTLaunchConfigurationConstants + * .ATTR_PROGRAM_NAME, ""); //$NON-NLS-1$ + */ + + LaunchOptions options = new LaunchOptions(); // default options created + // in the constructor + options.loadConfiguration(config); + options.setBinaryImage(imagePath); + + // if daemonEvents null or zero size, the default event will be used + String defaultEvent = null; + OprofileDaemonEvent[] daemonEvents = null; + if (!config.getAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, + false)) { + // get the events to profile from the counters + OprofileCounter[] counters = OprofileCounter.getCounters(config); + ArrayList events = new ArrayList(); + + for (int i = 0; i < counters.length; ++i) { + if (counters[i].getEnabled()) + events.add(counters[i].getDaemonEvent()); + } + + daemonEvents = new OprofileDaemonEvent[events.size()]; + events.toArray(daemonEvents); + } + // jinu added at 20090602-------------------------------- + else { + String keyStr = config.getAttribute( + OprofileLaunchPlugin.ATTR_SELECTED_DEFAULT_SETTING, ""); + defaultEvent = DefaultSettingConstants.getSettingValue(keyStr); + } + // -------------------------------------- + + // set up and launch the oprofile daemon + try { + + // kill the daemon (it shouldn't be running already, but to be safe) + OprofileCorePlugin.getDefault().getOpcontrolProvider() + .shutdownDaemon(); + + // reset data from the (possibly) existing default session, + // otherwise multiple runs will combine samples and results + // won't make much sense + OprofileCorePlugin.getDefault().getOpcontrolProvider().reset(); + + // setup the events and other parameters + // jinu modified at 20090603 + // OprofileCorePlugin.getDefault().getOpcontrolProvider().setupDaemon(options.getOprofileDaemonOptions(), + // daemonEvents); + OprofileCorePlugin + .getDefault() + .getOpcontrolProvider() + .setupDaemon(options.getOprofileDaemonOptions(), + daemonEvents, defaultEvent); + + // start the daemon & collection of samples + // note: since the daemon is only profiling for the specific image + // we told + // it to, no matter to start the daemon before the binary itself is + // run + OprofileCorePlugin.getDefault().getOpcontrolProvider() + .startCollection(); + + } catch (OpcontrolException oe) { + OprofileCorePlugin.showErrorDialog("opcontrolProvider", oe); //$NON-NLS-1$ + return; + } + + } + + private void postProcedure(ILaunchConfiguration config, ILaunch launch, + IProgressMonitor monitor) throws CoreException { + // ILaunchManager lmgr = DebugPlugin.getDefault().getLaunchManager(); + // lmgr.addLaunchListener(new LaunchTerminationWatcher(launch)); + OprofileCorePlugin.getDefault().getOpcontrolProvider().dumpSamples(); + OprofileCorePlugin.getDefault().getOpcontrolProvider().shutdownDaemon(); + + // need to run this in the ui thread otherwise get SWT Exceptions + // based on concurrency issues + Display.getDefault().syncExec(new Runnable() { + public void run() { + OprofileView view = OprofileUiPlugin.getDefault() + .getOprofileView(); + if (view != null) { + view.refreshView(); + } else { + try { + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage() + .showView(OprofileUiPlugin.ID_OPROFILE_VIEW); + } catch (PartInitException e) { + e.printStackTrace(); + } + OprofileUiPlugin.getDefault().getOprofileView() + .refreshView(); + } + } + }); + } + + public static void checkProfilingTool(IProgressMonitor monitor) + throws CoreException { + // find oprofile + String oprofileCmd = TizenPlatformConstants.TOOLS_TARGET_PATH + "/oprofile/usr/bin/opcontrol"; + String cmd = "ls " + oprofileCmd + TizenPlatformConstants.CMD_SUFFIX; + // String resultRsp = session.run(cmd, null); + String[] resultRsp = CommandManager.runCommandReturningResultArray(cmd); + if (!CommandManager.isRunSeccessfuly(resultRsp)) { + // if (CommandManager.isEmulator()) { + Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, + TizenLaunchMessages.CANNOT_LAUNCH, + new Exception( + "No oprofile in this target (" + TizenPlatformConstants.TOOLS_TARGET_PATH + "/oprofile/usr/bin/opcontrol).")); + throw new CoreException(status); + // } else { + // transferProfilingToolPackage(monitor); + // installProfilingToolPackage(monitor); + // } + } + } + + class LaunchTerminationWatcher implements ILaunchesListener2 { + private ILaunch launch; + + public LaunchTerminationWatcher(ILaunch il) { + launch = il; + } + + public void launchesTerminated(ILaunch[] launches) { + try { + for (ILaunch l : launches) { + /** + * Dump samples from the daemon, shut down the daemon, + * activate the OProfile view (open it if it isn't already), + * refresh the view (which parses the data/ui model and + * displays it). + */ + if (l.equals(launch)) { + OprofileCorePlugin.getDefault().getOpcontrolProvider() + .dumpSamples(); + OprofileCorePlugin.getDefault().getOpcontrolProvider() + .shutdownDaemon(); + + // need to run this in the ui thread otherwise get SWT + // Exceptions + // based on concurrency issues + Display.getDefault().syncExec(new Runnable() { + public void run() { + OprofileView view = OprofileUiPlugin + .getDefault().getOprofileView(); + if (view != null) { + view.refreshView(); + } else { + try { + PlatformUI + .getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage() + .showView( + OprofileUiPlugin.ID_OPROFILE_VIEW); + } catch (PartInitException e) { + e.printStackTrace(); + } + OprofileUiPlugin.getDefault() + .getOprofileView().refreshView(); + } + } + }); + } + } + } catch (OpcontrolException oe) { + OprofileCorePlugin.showErrorDialog("opcontrolProvider", oe); //$NON-NLS-1$ + } + } + + public void launchesAdded(ILaunch[] launches) { /* dont care */ + } + + public void launchesChanged(ILaunch[] launches) { /* dont care */ + } + + public void launchesRemoved(ILaunch[] launches) { /* dont care */ + } + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/configuration/NormalOprofileLaunchConfigurationTabGroup.java b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/configuration/NormalOprofileLaunchConfigurationTabGroup.java new file mode 100644 index 0000000..68a1e4b --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch.exe/src/org/tizen/oprofile/launch/configuration/NormalOprofileLaunchConfigurationTabGroup.java @@ -0,0 +1,66 @@ +/* + * Normal Oprofile Launch Configuration Tab Group + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Wonhyoung Park + * Juyoung Kim + * + * 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: + * - S-Core Co., Ltd + * + */ + +package org.tizen.oprofile.launch.configuration; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.linuxtools.oprofile.launch.configuration.OprofileEventConfigTab; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup; +import org.tizen.nativecommon.launch.ui.TizenMainTab; +import org.tizen.oprofile.launch.TizenOprofileLaunchDelegate; + +public class NormalOprofileLaunchConfigurationTabGroup extends ProfileLaunchConfigurationTabGroup { + + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + ArrayList tabs = new ArrayList(); + tabs.add(new TizenMainTab()); +// tabs.add(new TizenArgumentsTab()); + tabs.addAll(Arrays.asList(getProfileTabs())); +// tabs.add(new TizenEnvironmentTab()); +// tabs.add(new SourceLookupTab()); + + setTabs(tabs.toArray(new AbstractLaunchConfigurationTab[tabs.size()])); + + } + @Override + public AbstractLaunchConfigurationTab[] getProfileTabs() { + //jinu modified at 20090602 + //return new AbstractLaunchConfigurationTab[] { new OprofileSetupTab(), new OprofileEventConfigTab() }; + + // added by greatim at 20110613 + try{ + IProgressMonitor monitor = new NullProgressMonitor(); + + TizenOprofileLaunchDelegate.checkProfilingTool(monitor); + } catch(CoreException e) { + e.printStackTrace(); + } + + return new AbstractLaunchConfigurationTab[] { new OprofileEventConfigTab() }; + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch/.classpath b/org.eclipse.linuxtools.oprofile.launch/.classpath new file mode 100644 index 0000000..4c62a80 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.oprofile.launch/.project b/org.eclipse.linuxtools.oprofile.launch/.project new file mode 100644 index 0000000..7e16bda --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.oprofile.launch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.oprofile.launch/.settings/org.eclipse.core.resources.prefs b/org.eclipse.linuxtools.oprofile.launch/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..bd9cda7 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Wed Dec 01 09:13:16 CET 2010 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.linuxtools.oprofile.launch/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.linuxtools.oprofile.launch/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000..30f3872 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Tue Dec 14 16:36:24 CET 2010 +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.linuxtools.oprofile.launch/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.oprofile.launch/META-INF/MANIFEST.MF new file mode 100644 index 0000000..39b7f4e --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/META-INF/MANIFEST.MF @@ -0,0 +1,38 @@ +Manifest-Version: 1.0 +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.0", + org.eclipse.ui;bundle-version="3.4.0", + org.eclipse.cdt.core, + org.eclipse.cdt.launch;bundle-version="5.0.1", + org.eclipse.cdt.debug.core;bundle-version="5.0.1", + org.eclipse.linuxtools.oprofile.core, + org.tizen.common, + org.tizen.common.connection +Bundle-Vendor: Eclipse Linux Tools +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.3.18.qualifier +Bundle-Localization: plugin +Bundle-Name: Tizen SDK Oprofile Launch +Bundle-Activator: org.eclipse.linuxtools.oprofile.launch.OprofileLaunc + hPlugin +Bundle-ManifestVersion: 2 +Import-Package: org.eclipse.cdt.debug.core, + org.eclipse.cdt.launch, + org.eclipse.cdt.utils.pty, + org.eclipse.cdt.utils.spawner, + org.eclipse.core.resources, + org.eclipse.debug.core, + org.eclipse.debug.ui, + org.eclipse.linuxtools.oprofile.core, + org.eclipse.linuxtools.oprofile.core.daemon, + org.eclipse.linuxtools.oprofile.ui, + org.eclipse.linuxtools.oprofile.ui.view, + org.eclipse.linuxtools.profiling.launch, + org.eclipse.ui, + org.tizen.sdblib +Bundle-SymbolicName: org.eclipse.linuxtools.oprofile.launch;singleton: + =true +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.tizen.oprofile.launch, + org.eclipse.linuxtools.oprofile.launch, + org.eclipse.linuxtools.oprofile.launch.configuration + diff --git a/org.eclipse.linuxtools.oprofile.launch/META-INF/eclipse.inf b/org.eclipse.linuxtools.oprofile.launch/META-INF/eclipse.inf new file mode 100644 index 0000000..92ffed2 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/META-INF/eclipse.inf @@ -0,0 +1,2 @@ +#Processed using Jarprocessor +pack200.conditioned = true diff --git a/org.eclipse.linuxtools.oprofile.launch/NOTICE b/org.eclipse.linuxtools.oprofile.launch/NOTICE new file mode 100644 index 0000000..c91b2a1 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/NOTICE @@ -0,0 +1,48 @@ +2010-02-03 SPRC SDK Team + * MANIFEST.MF : changed some package names + +2010-03-11 SPRC SDK Team + * OprofileEventConfigTab.java : add help string + +2010-11-05 sdk + * MANIFEST.MF : changed some package name + * plugin.xml : changed some package name + * OprofileEventConfigTab.java : changed some package name + * OprofileLaunchConfigurationDelegate.java : changed some package name + * OprofileLaunchShortcut.java : changed some package name + +2010-11-09 DongGi Jang + * MANIFEST.MF : changed launcher name + +2011-06-09 jaewon81.lim + * MANIFEST.MF : rearrange plugins dependency + +2011-06-13 jaewon81.lim + * OprofileEventConfigTab.java : some bug fix + +2011-07-13 jaewon81.lim + * MANIFEST.MF : modified import package name + +2011-08-22 joogwan.kim + * MANIFEST.MF : Change plug-in name + +2011-08-25 wonhyoung2.park + * MANIFEST.MF : plugin provider and name modified + +2011-11-16 wonhyoung2.park + * MANIFEST.MF : Profiler sdb apply + +2011-11-22 taeyoung2.son + * MANIFEST.MF : Modify SDK naming from "SLP(or Samsung Linux Platform)" to "Tizen" + +2011-11-29 wonhyoung2.park + * MANIFEST.MF : chagne slp to tizen + * plugin.xml : chagne slp to tizen + * OprofileEventConfigTab.java : chagne slp to tizen + * OprofileLaunchConfigurationDelegate.java : chagne slp to tizen + +2011-12-02 taeyoung2.son + * MANIFEST.MF : Delete dependency feature's version value. + +2011-12-03 wonhyoung2.park + * MANIFEST.MF : package instll routine chage diff --git a/org.eclipse.linuxtools.oprofile.launch/about.html b/org.eclipse.linuxtools.oprofile.launch/about.html new file mode 100644 index 0000000..bf06e8c --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/about.html @@ -0,0 +1,33 @@ + + + +About + + + +

About This Content

+ +

8th September, 2004

+

License

+

The Eclipse Software Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

Contributions

+ +

If this Content is licensed to you under the terms and conditions of the EPL, any Contributions, as defined in the EPL, uploaded, submitted, or otherwise +made available to the Eclipse Foundation, its members and/or the host of the Eclipse Foundation web site, by you that relate to such +Content are provided under the terms and conditions of the Terms of Use +for the Eclipse Foundation web site and can be made available to others under the terms of the licenses as set out in the +Terms of Use.

+ +

If this Content is licensed to you under license terms and conditions other than the EPL ("Other License"), any modifications, enhancements and/or +other code and/or documentation ("Modifications") uploaded, submitted, or otherwise made available to the Eclipse Foundation, its members and/or the +host of the Eclipse Foundation web site, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available +to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also +providing the Modifications under the terms and conditions of the Terms of Use +for the Eclipse Foundation web site and such Modifications can be made available to others under the terms of the licenses as set out in the +Terms of Use.

+ + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.oprofile.launch/build.properties b/org.eclipse.linuxtools.oprofile.launch/build.properties new file mode 100644 index 0000000..6b70fb2 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/build.properties @@ -0,0 +1,10 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + icons/,\ + about.html +javacSource = 1.6 +javacTarget = 1.6 diff --git a/org.eclipse.linuxtools.oprofile.launch/icons/event_tab.gif b/org.eclipse.linuxtools.oprofile.launch/icons/event_tab.gif new file mode 100644 index 0000000..c91f254 Binary files /dev/null and b/org.eclipse.linuxtools.oprofile.launch/icons/event_tab.gif differ diff --git a/org.eclipse.linuxtools.oprofile.launch/icons/global_tab.gif b/org.eclipse.linuxtools.oprofile.launch/icons/global_tab.gif new file mode 100644 index 0000000..ec6cca4 Binary files /dev/null and b/org.eclipse.linuxtools.oprofile.launch/icons/global_tab.gif differ diff --git a/org.eclipse.linuxtools.oprofile.launch/icons/profile_run.png b/org.eclipse.linuxtools.oprofile.launch/icons/profile_run.png new file mode 100644 index 0000000..4f8488f Binary files /dev/null and b/org.eclipse.linuxtools.oprofile.launch/icons/profile_run.png differ diff --git a/org.eclipse.linuxtools.oprofile.launch/plugin.properties b/org.eclipse.linuxtools.oprofile.launch/plugin.properties new file mode 100644 index 0000000..fd1976b --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/plugin.properties @@ -0,0 +1,20 @@ +#******************************************************************************* +# Copyright (c) 2008 Red Hat, Inc. +# 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: +# Red Hat, Inc. - initial API and implementation +#******************************************************************************* +pluginName=OProfile Launch Support +launchconfigurationtype.label=Profile With OProfile + +launchgroup.label = OProfile +launchgroup.titile = Select a run configuration to profile with OProfile + +launchmode.label = Profile +launchmode.launchaslabel = Profile As + +launchshortcuts.label = Profile With OProfile diff --git a/org.eclipse.linuxtools.oprofile.launch/plugin.xml b/org.eclipse.linuxtools.oprofile.launch/plugin.xml new file mode 100644 index 0000000..ea3089e --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/plugin.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/OprofileLaunchMessages.java b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/OprofileLaunchMessages.java new file mode 100644 index 0000000..869bd29 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/OprofileLaunchMessages.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.launch; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class OprofileLaunchMessages { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.oprofile.launch.oprofilelaunch"; //$NON-NLS-1$ + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private OprofileLaunchMessages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/OprofileLaunchPlugin.java b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/OprofileLaunchPlugin.java new file mode 100644 index 0000000..fd46c29 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/OprofileLaunchPlugin.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.launch; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.linuxtools.oprofile.launch.configuration.EventConfigCache; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + + +/** + * The main plugin class to be used in the desktop. + */ +public class OprofileLaunchPlugin extends AbstractUIPlugin { + //The shared instance. + private static OprofileLaunchPlugin plugin; + //shared cache instance for configuration + private static EventConfigCache _eventConfigCache = null; + + private static final String ID_PLUGIN = "org.eclipse.linuxtools.oprofile.launch"; //$NON-NLS-1$ + + // The launch type ID for profiling + public static final String ID_LAUNCH_PROFILE = ID_PLUGIN + ".oprofile"; //$NON-NLS-1$ + + + /* Launch Configuration attributes */ + + // Global options \\ + public static final String ATTR_KERNEL_IMAGE_FILE = ID_LAUNCH_PROFILE + ".KERNEL_IMAGE"; //$NON-NLS-1$ + public static final String ATTR_SEPARATE_SAMPLES = ID_LAUNCH_PROFILE + ".SEPARATE_SAMPLES"; //$NON-NLS-1$ + public static final String ATTR_USE_DEFAULT_EVENT = ID_LAUNCH_PROFILE + ".USE_DEFAULT_EVENT"; //$NON-NLS-1$ + + //jinu added at 20090602 + public static final String ATTR_SELECTED_DEFAULT_SETTING = ID_LAUNCH_PROFILE + ".SELECTED_DEFAULT_SETTING"; //$NON-NLS-1$ + + // Counter Attributes \\ + private static final String ATTR_COUNTER(int nr) { return ID_LAUNCH_PROFILE + ".COUNTER_" + nr; } //$NON-NLS-1$ + public static final String ATTR_COUNTER_ENABLED(int nr) { return ATTR_COUNTER(nr) + ".ENABLED"; } //$NON-NLS-1$ + public static final String ATTR_COUNTER_EVENT(int nr) { return ATTR_COUNTER(nr) + ".EVENT"; } //$NON-NLS-1$ + public static final String ATTR_COUNTER_PROFILE_KERNEL(int nr) { return ATTR_COUNTER(nr) + ".PROFILE_KERNEL"; } //$NON-NLS-1$ + public static final String ATTR_COUNTER_PROFILE_USER(int nr) { return ATTR_COUNTER(nr) + ".PROFILE_USER"; } //$NON-NLS-1$ + public static final String ATTR_COUNTER_COUNT(int nr) { return ATTR_COUNTER(nr) + ".COUNT"; } //$NON-NLS-1$ + public static final String ATTR_COUNTER_UNIT_MASK(int nr) { return ATTR_COUNTER(nr) + ".UNIT_MASK"; } //$NON-NLS-1$ + + + public static final String ICON_PATH = "icons/"; //$NON-NLS-1$ + public static final String ICON_EVENT_TAB = ICON_PATH + "event_tab.gif"; //$NON-NLS-1$ + public static final String ICON_GLOBAL_TAB = ICON_PATH + "global_tab.gif"; //$NON-NLS-1$ + + + /** + * The constructor. + */ + public OprofileLaunchPlugin() { + plugin = this; + } + + public void start(BundleContext context) throws Exception { + super.start(context); + } + + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + public static OprofileLaunchPlugin getDefault() { + return plugin; + } + + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + public static String getUniqueIdentifier() { + return ID_PLUGIN; + } + + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(ID_PLUGIN, path); + } + + public static IWorkbenchWindow getActiveWorkbenchWindow() { + return getDefault().getWorkbench().getActiveWorkbenchWindow(); + } + + public static Shell getActiveWorkbenchShell() { + IWorkbenchWindow window = getActiveWorkbenchWindow(); + if (window != null) { + return window.getShell(); + } + return null; + } + + public static EventConfigCache getCache() { + if (_eventConfigCache == null) { + _eventConfigCache = new EventConfigCache(); + } + + return _eventConfigCache; + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/EventConfigCache.java b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/EventConfigCache.java new file mode 100644 index 0000000..ea1d52c --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/EventConfigCache.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 Red Hat, Inc. + * 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: + * Kent Sebastian - initial API and implementation + * + *******************************************************************************/ +package org.eclipse.linuxtools.oprofile.launch.configuration; + +import java.util.HashMap; +import org.eclipse.linuxtools.oprofile.core.Oprofile; + +/** + * Cache class for event configuration. Currently only used to cache the results + * of an `opxml check-event ..` run, since the isValid() method in the EventConfigTab + * needlessly spawns opxml dozens of times with the same values. Note that multiple + * checks of the same value will necessarily return the same result (for a given + * processor) so there is no worry of an invalid cache entry. + */ +public class EventConfigCache { + //a cache entry for an event check, used as the hashmap key + class CheckEventEntry { + public Integer counterNum, eventNum, maskValue; + + public CheckEventEntry(int counterNum, int eventNum, int maskValue) { + this.counterNum = new Integer(counterNum); + this.eventNum = new Integer(eventNum); + this.maskValue = new Integer(maskValue); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CheckEventEntry) { + CheckEventEntry other = (CheckEventEntry)obj; + return (counterNum.equals(other.counterNum) && eventNum.equals(other.eventNum) && maskValue.equals(other.maskValue)); + } else { + return false; + } + } + + @Override + public int hashCode() { + int prime = 11, result = 3; + result = prime*result + counterNum.hashCode(); + result = prime*result + eventNum.hashCode(); + result = prime*result + maskValue.hashCode(); + return result; + } + } + + HashMap validEventCache; + + /** + * Default constructor, creates an empty cache. + */ + public EventConfigCache() { + validEventCache = new HashMap(); + } + + /** + * Method to be used to check the validity of an event. Will check + * the cache for the result of a previous check of the same values, + * or otherwise will spawn opxml to check properly. + * @param counter counter number + * @param event event number + * @param mask unit mask value + * @return true or false, depending if the event config is valid + */ + public boolean checkEvent(int counter, int event, int mask) { + CheckEventEntry e = new CheckEventEntry(counter, event, mask); + Boolean result = null; + + result = validEventCache.get(e); + + if (result == null) { + //not in the map, get its value and add it in + result = Oprofile.checkEvent(counter, event, mask); + + //possible to be null if there is no opxmlProvider + if (result != null) { + validEventCache.put(e, result); + } + } + + return (result == null ? false : result); + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/LaunchOptions.java b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/LaunchOptions.java new file mode 100644 index 0000000..11ceeb4 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/LaunchOptions.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.launch.configuration; + +import java.io.File; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonOptions; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchPlugin; + +/** + * This class wraps OProfile's global launch options for the + * Eclipse launcher facility. + */ +public class LaunchOptions { + + // The launch options for the daemon + private OprofileDaemonOptions _options; + + public LaunchOptions() { + _options = new OprofileDaemonOptions(); + } + + /** + * Determines whether the global oprofile options represented by this + * object are valid + * @return whether the options are valid + */ + public boolean isValid() { + // The only point of contention is whether the specified vmlinux *file* exists. + String fn = _options.getKernelImageFile(); + if (fn != null && fn.length() > 0) { + File file = new File(_options.getKernelImageFile()); + return (file.exists() && file.isFile()); + } + + return true; + } + + /** + * Saves the global options of this object into the specified launch + * configuration + * @param config the launch configuration + */ + public void saveConfiguration(ILaunchConfigurationWorkingCopy config) { + config.setAttribute(OprofileLaunchPlugin.ATTR_KERNEL_IMAGE_FILE, _options.getKernelImageFile()); + config.setAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, _options.getSeparateProfilesMask()); + } + + /** + * Loads this object with the global options in the given launch + * configuration + * @param config the launch configuration + */ + public void loadConfiguration(ILaunchConfiguration config) { + try { + _options.setKernelImageFile(config.getAttribute(OprofileLaunchPlugin.ATTR_KERNEL_IMAGE_FILE, "")); //$NON-NLS-1$ + _options.setSeparateProfilesMask(config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, OprofileDaemonOptions.SEPARATE_NONE)); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + /** + * Get the daemon launch options + * @return the OprofileDaemonOption + */ + public OprofileDaemonOptions getOprofileDaemonOptions() { + return _options; + } + + /** + * Method getKernelImageFile. + * @return the kernel image file + */ + public String getKernelImageFile() { + return _options.getKernelImageFile(); + } + + /** + * Sets the kernel image file + * @param image the kernel image file + */ + public void setKernelImageFile(String image) { + _options.setKernelImageFile(image); + } + + /** + * Method getSeparateSamples. + * @return whether and how to separate samples for each distinct application + */ + public int getSeparateSamples() { + return _options.getSeparateProfilesMask(); + } + + /** + * Sets whether/how to collect separate samples for each distinct application + * @param how one of SEPARATE_{NONE, LIBRARY, KERNEL, THREAD, CPU} + */ + public void setSeparateSamples(int how) { + _options.setSeparateProfilesMask(how); + } + + /** + * Returns the path of the binary to profile. + * @return the full path to the binary being profile + */ + public String getBinaryImage() { + return _options.getBinaryImage(); + } + + /** + * Sets the binary to profile in this launch. + * @param _image string of the full path to the binary + */ + public void setBinaryImage(String _image) { + _options.setBinaryImage(_image); + } + +} diff --git a/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/OprofileCounter.java b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/OprofileCounter.java new file mode 100644 index 0000000..40745ef --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/OprofileCounter.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (c) 2004,2008 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.launch.configuration; + +import java.text.MessageFormat; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.linuxtools.oprofile.core.Oprofile; +import org.eclipse.linuxtools.oprofile.core.daemon.OpEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OpUnitMask; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchPlugin; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchMessages; + +/** + * This class represents an oprofile runtime configuration of a counter. It is + * used to construct arguments for launching op_start on the host. It + * simply wraps OprofileDaemonEvent. + */ +public class OprofileCounter { + private static final String COUNTER_STRING = OprofileLaunchMessages.getString("oprofileCounter.counterString"); //$NON-NLS-1$ + + // The counter number + private int _number; + + // Is this counter enabled? + private boolean _enabled; + + // The event to collect on this counter + private OprofileDaemonEvent _daemonEvent; + + // List of valid events on this counter + private OpEvent[] _eventList = null; + + /** + * Constructor for OprofileCounter. + * @param nr the counter number + */ + public OprofileCounter(int nr) { + _number = nr; + _enabled = false; + _eventList = Oprofile.getEvents(_number); + _daemonEvent = new OprofileDaemonEvent(); + } + + /** + * Constructs all of the counters in the given launch configuration. + * @param config the launch configuration + * @return an array of all counters + */ + public static OprofileCounter[] getCounters(ILaunchConfiguration config) { + OprofileCounter[] ctrs = new OprofileCounter[Oprofile.getNumberOfCounters()]; + for (int i = 0; i < ctrs.length; i++) + { + ctrs[i] = new OprofileCounter(i); + if (config != null) + ctrs[i].loadConfiguration(config); + } + + return ctrs; + } + + /** + * Method setEnabled. + * @param enabled whether to set this counter as enabled + */ + public void setEnabled(boolean enabled) { + _enabled = enabled; + } + + /** + * Method setEvent. + * @param event the event for this counter + */ + public void setEvent(OpEvent event) { + _daemonEvent.setEvent(event); + } + + /** + * Method setProfileKernel. + * @param profileKernel whether this counter should count kernel events + */ + public void setProfileKernel(boolean profileKernel) { + _daemonEvent.setProfileKernel(profileKernel); + } + + /** + * Method setProfileUser. + * @param profileUser whether this counter should count user events + */ + public void setProfileUser(boolean profileUser) { + _daemonEvent.setProfileUser(profileUser); + } + + /** + * Method setCount. + * @param count the number of events between samples for this counter + */ + public void setCount(int count) { + _daemonEvent.setResetCount(count); + } + + /** + * Saves this counter's configuration into the specified launch + * configuration. + * @param config the launch configuration + */ + public void saveConfiguration(ILaunchConfigurationWorkingCopy config) { + config.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_ENABLED(_number), _enabled); + if (_daemonEvent.getEvent() != null) { + config.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_EVENT(_number), _daemonEvent.getEvent().getText()); + config.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_UNIT_MASK(_number), _daemonEvent.getEvent().getUnitMask().getMaskValue()); + } + config.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_PROFILE_KERNEL(_number), _daemonEvent.getProfileKernel()); + config.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_PROFILE_USER(_number), _daemonEvent.getProfileUser()); + config.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_COUNT(_number), _daemonEvent.getResetCount()); + } + + /** + * Loads a counter configuration from the specified launch configuration. + * @param config the launch configuration + */ + public void loadConfiguration(ILaunchConfiguration config) { + try { + _enabled = config.getAttribute(OprofileLaunchPlugin.ATTR_COUNTER_ENABLED(_number), false); + + String str = config.getAttribute(OprofileLaunchPlugin.ATTR_COUNTER_EVENT(_number), ""); //$NON-NLS-1$ + _daemonEvent.setEvent(_eventFromString(str)); + + if (_daemonEvent.getEvent() == null) { + return; + } + + + int maskValue = config.getAttribute(OprofileLaunchPlugin.ATTR_COUNTER_UNIT_MASK(_number), OpUnitMask.SET_DEFAULT_MASK); + _daemonEvent.getEvent().getUnitMask().setMaskValue(maskValue); + + _daemonEvent.setProfileKernel(config.getAttribute(OprofileLaunchPlugin.ATTR_COUNTER_PROFILE_KERNEL(_number), false)); + _daemonEvent.setProfileUser(config.getAttribute(OprofileLaunchPlugin.ATTR_COUNTER_PROFILE_USER(_number), false)); + + _daemonEvent.setResetCount(config.getAttribute(OprofileLaunchPlugin.ATTR_COUNTER_COUNT(_number), OprofileDaemonEvent.COUNT_UNINITIALIZED)); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + public OpUnitMask getUnitMask() { + OpEvent event = _daemonEvent.getEvent(); + + if (event != null) { + return event.getUnitMask(); + } else { + return null; + } + } + + /** + * Returns a textual label for this counter (used by UI) + * @return the label to use in widgets referring to this counter + */ + public String getText() { + Object[] args = new Object[] {new Integer(_number)}; + return MessageFormat.format(COUNTER_STRING, args); + } + + /** + * Method getNumber. + * @return the counter's number + */ + public int getNumber() { + return _number; + } + + /** + * Method getEnabled. + * @return whether this counter is enabled + */ + public boolean getEnabled() { + return _enabled; + } + + /** + * Method getEvent. + * @return the event for this counter + */ + public OpEvent getEvent() { + return _daemonEvent.getEvent(); + } + + /** + * Method getProfileKernel. + * @return whether this counter is counting kernel events + */ + public boolean getProfileKernel() { + return _daemonEvent.getProfileKernel(); + } + + /** + * Method getProfileUser. + * @return whether this counter is counting user events + */ + public boolean getProfileUser() { + return _daemonEvent.getProfileUser(); + } + + /** + * Method getCount. + * @return the number of events between samples for this counter + */ + public int getCount() { + return _daemonEvent.getResetCount(); + } + + /** + * Method getValidEvents. + * @return an array of all events that this counter can monitor + */ + public OpEvent[] getValidEvents() { + return _eventList; + } + + /** + * Gets the daemon event configuration for this counter. + * Not valid if this counter is not enabled! + * @return the OprofileDaemonEvent + */ + public OprofileDaemonEvent getDaemonEvent() { + return _daemonEvent; + } + + // Returns the event with the same label as the parameter STR + private OpEvent _eventFromString(String str) { + for (int i = 0; i < _eventList.length; i++) { + if (_eventList[i].getText().equals(str)) + return _eventList[i]; + } + + return null; + } +} + diff --git a/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/OprofileEventConfigTab.java b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/OprofileEventConfigTab.java new file mode 100644 index 0000000..7ba1423 --- /dev/null +++ b/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/configuration/OprofileEventConfigTab.java @@ -0,0 +1,916 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008, 2009 Red Hat, Inc. + * 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: + * Keith Seitz - initial API and implementation + * Kent Sebastian - + * + * CounterSubTab Contributors: + * Keith Seitz - initial API and implementation (before subclassing) + * Kent Sebastian - turned into a sub class, + * changed layouts, fixed up some interactivity issues, .. + * + * UnitMaskViewer Contributors: + * Keith Seitz - initial API and implementation + * Kent Sebastian + *******************************************************************************/ + +package org.eclipse.linuxtools.oprofile.launch.configuration; + +import java.text.MessageFormat; +import java.util.ArrayList; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.debug.ui.ILaunchConfigurationTab; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.linuxtools.oprofile.core.Oprofile; +import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.daemon.OpEvent; +import org.eclipse.linuxtools.oprofile.core.daemon.OpUnitMask; +import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchMessages; +import org.eclipse.linuxtools.oprofile.launch.OprofileLaunchPlugin; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchPlugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +import org.tizen.oprofile.core.OprofileComm; +import org.tizen.oprofile.launch.DefaultSettingConstants; + + +/** + * Thic class represents the event configuration tab of the launcher dialog. + */ +public class OprofileEventConfigTab extends AbstractLaunchConfigurationTab { + private Button _defaultEventCheck; + private OprofileCounter[] _counters ; + private CounterSubTab[] _counterSubTabs; + private StackLayout stackLayout = new StackLayout(); + TabFolder tabFolder; + Group buttonGroup; + + + + private boolean canInitialize; + + /** + * Essentially the constructor for this tab; creates the 'default event' + * checkbox and an appropriate number of counter tabs. + * @param parent the parent composite + */ + public void createControl(Composite parent) { + Oprofile.initialize(); + Composite top = new Composite(parent, SWT.NONE); + setControl(top); + top.setLayout(new GridLayout()); + + // TODO : have to change help context id (temporarily empty string) + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ""); //$NON-NLS-1$ + + //jinu added at 20090602---------------------- + if(ProfileLaunchPlugin.checkTarget() == 0 || Oprofile.getOpInfo()==null){ + Label timerModeLabel = new Label(top, SWT.LEFT); + timerModeLabel.setText(OprofileLaunchMessages.getString("common.notarget")); //$NON-NLS-1$ + canInitialize = false; + return; + }else{ + canInitialize = true; + } + //-------------------------------------- + + if (Oprofile.getTimerMode()) { + Label timerModeLabel = new Label(top, SWT.LEFT); + timerModeLabel.setText(OprofileLaunchMessages.getString("tab.event.timermode.no.options")); //$NON-NLS-1$ + } else { + createVerticalSpacer(top, 1); + + _counters = OprofileCounter.getCounters(null); + + //default event checkbox + _defaultEventCheck = new Button(top, SWT.CHECK); + _defaultEventCheck.setText(OprofileLaunchMessages.getString("tab.event.defaultevent.button.text")); //$NON-NLS-1$ + _defaultEventCheck.setLayoutData(new GridData()); + _defaultEventCheck.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent se) { + _handleEnabledToggle(); + } + }); + + createVerticalSpacer(top, 1); + + //tabs for each of the counters + OprofileCounter[] counters = OprofileCounter.getCounters(null); + TabItem[] counterTabs = new TabItem[counters.length]; + _counterSubTabs = new CounterSubTab[counters.length]; + + //jinu added at 20090602 ------------------------------- + Composite stackComp = new Composite(top, SWT.NONE); + stackComp.setLayout(stackLayout); + stackComp.setLayoutData(new GridData(GridData.FILL_BOTH)); + + buttonGroup = new Group(stackComp,SWT.BORDER); + buttonGroup.setText("Supported Type"); + buttonGroup.setLayout(new GridLayout(1,false)); + + String[][] defaultSettings = DefaultSettingConstants.getDefaultSettings(); + for(int i=0;i0) + ((Button)controls[0]).setSelection(true); + } + + //jinu added at 20090602 + private String getSelectedButton(){ + Control[] controls = buttonGroup.getChildren(); + String ret=null; + for(int i=0;i 0 && valid); + } + } + + /** + * @see ILaunchConfigurationTab#performApply(ILaunchConfigurationWorkingCopy) + */ + public void performApply(ILaunchConfigurationWorkingCopy config) { + //jinu added at 20090602------------------------------- + if(!canInitialize || ProfileLaunchPlugin.checkTarget() == 0){ + return; + } + //-------------------------------------- + + if (Oprofile.getTimerMode()) { + config.setAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, true); + } else { + config.setAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, _defaultEventCheck.getSelection()); + + //jinu added at 20090602 + config.setAttribute(OprofileLaunchPlugin.ATTR_SELECTED_DEFAULT_SETTING, getSelectedButton()); + + for (CounterSubTab cst : _counterSubTabs) { + cst.performApply(config); + } + } + } + + /** + * @see ILaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy) + */ + + public void setDefaults(ILaunchConfigurationWorkingCopy config) { + // commented by greatim at 2011.06.01 for fresh ide + //jinu added at 20090616 +// config.setAttribute(ISMLCDTLaunchConstants.ATTR_LAUNCH_MODE, "oprofile"); + //config.setAttribute(ISMLCDTLaunchConstants.ATTR_SKIP_DOWNLOAD, false); + + //jinu removed at 20090616 + /* + boolean useDefault = true; + + // When instantiated, the OprofileCounter will set defaults. + if(_counters!=null){ + for (int i = 0; i < _counters.length; i++) { + _counters[i].saveConfiguration(config); + if (_counters[i].getEnabled()) { + useDefault = false; + } + } + } + + config.setAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, useDefault); + */ + } + + + /** + * @see ILaunchConfigurationTab#getName() + */ + public String getName() { + return OprofileLaunchMessages.getString("tab.event.name"); //$NON-NLS-1$ + } + + /** + * @see ILaunchConfigurationTab#getImage() + */ + @Override + public Image getImage() { + return OprofileLaunchPlugin.getImageDescriptor(OprofileLaunchPlugin.ICON_EVENT_TAB).createImage(); + } + + /** + * Handles the toggling of the default event check box. Not meant to be called + * directly. + */ + private void _handleEnabledToggle() { + setEnabledState(!_defaultEventCheck.getSelection()); + updateLaunchConfigurationDialog(); + } + + /** + * Sets the state of the child counter tabs' widgets. + * @param state true for enabled, false for disabled + */ + private void setEnabledState(boolean state) { + //jinu added at 20090602------------------------------- + if(!state) + stackLayout.topControl = buttonGroup; + else + stackLayout.topControl = tabFolder; + //-------------------------------------- + + for (CounterSubTab cst : _counterSubTabs) { + cst.setEnabledState(state); + } + } + + + /** + * A sub-tab of the OprofileEventConfigTab launch configuration tab. + * Essentially, it is a frontend to an OprofileCounter. This is an + * inner class because it requires methods from the parent tab (such as + * updateLaunchConfigurationDialog() when a widget changes state). + */ + class CounterSubTab { + private Button _enabledCheck; + private Button _profileKernelCheck; + private Button _profileUserCheck; + private Label _countTextLabel; + private Text _countText; + private Label _eventDescLabel; + private Text _eventDescText; + private UnitMaskViewer _unitMaskViewer; + private ListViewer _eventList; + private OprofileCounter _counter; + + private ScrolledComposite _scrolledTop; + private Composite _tabTopContainer; + + /** + * Constructor for a subtab. Creates the layout and widgets for its content. + * @param parent composite the widgets will be created in + * @param counter the associated OprofileCounter object + */ + public CounterSubTab(Composite parent, OprofileCounter counter) { + _counter = counter; + + parent.setLayout(new GridLayout()); + + //scrollable composite on top + ScrolledComposite scrolledContainer = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + scrolledContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + scrolledContainer.setLayout(layout); + scrolledContainer.setExpandHorizontal(true); + scrolledContainer.setExpandVertical(true); + + //composite to contain the rest of the tab + Composite tabTopContainer = new Composite(scrolledContainer, SWT.NONE); + scrolledContainer.setContent(tabTopContainer); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + tabTopContainer.setLayout(layout); + tabTopContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + //top cell + Composite topCellComp = new Composite(tabTopContainer, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + topCellComp.setLayout(layout); + topCellComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); + + createTopCell(topCellComp); + + createVerticalSpacer(tabTopContainer, 2); + + //left side composite group for eventList + Composite eventListComp = new Composite(tabTopContainer, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + eventListComp.setLayout(layout); + //layoutdata is set later + + createLeftCell(eventListComp); + + + //right side composite group for other event config and unit mask + Composite eventConfigComp = new Composite(tabTopContainer, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + eventConfigComp.setLayout(layout); + eventConfigComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + createRightCell(eventConfigComp); + + + //set the list's composite layout based on the right cell's size + GridData data = new GridData(SWT.FILL, SWT.FILL, false, true); + data.heightHint = eventConfigComp.getSize().x; + eventListComp.setLayoutData(data); + + _scrolledTop = scrolledContainer; + _tabTopContainer = tabTopContainer; + } + + /** + * Creates the "Enabled" checkbox, and the event description text. + * @param parent composite these widgets will be created in + */ + private void createTopCell(Composite parent) { + //checkbox + _enabledCheck = new Button(parent, SWT.CHECK); + _enabledCheck.setText(OprofileLaunchMessages.getString("tab.event.counterSettings.enabled.button.text")); //$NON-NLS-1$ + _enabledCheck.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + _enabledCheck.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent se) { + _counter.setEnabled(_enabledCheck.getSelection()); + _setEnabledState(_counter.getEnabled()); + updateLaunchConfigurationDialog(); + } + }); + _enabledCheck.setEnabled(false); + + //label for textbox + _eventDescLabel = new Label(parent, SWT.NONE); + _eventDescLabel.setText(OprofileLaunchMessages.getString("tab.event.eventDescription.label.text")); //$NON-NLS-1$ + _eventDescLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + + //textbox + _eventDescText = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); + _eventDescText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + } + + /** + * Creates the event list widget. + * @param parent composite these widgets will be created in + */ + private void createLeftCell(Composite parent) { + _eventList = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); + _eventList.getList().setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true)); + + _eventList.setLabelProvider(new ILabelProvider(){ + public String getText(Object element) { + OpEvent e = (OpEvent) element; + return e.getText(); + } + public Image getImage(Object element) { return null; } + public void addListener(ILabelProviderListener listener) { } + public void dispose() { } + public boolean isLabelProperty(Object element, String property) { return false; } + public void removeListener(ILabelProviderListener listener) { } + }); + + _eventList.setContentProvider(new IStructuredContentProvider() { + public Object[] getElements(Object inputElement) { + OprofileCounter ctr = (OprofileCounter) inputElement; + return (OpEvent[]) ctr.getValidEvents(); + } + public void dispose() { } + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { } + }); + + //adds the events to the list from the counter + _eventList.setInput(_counter); + + _eventList.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent sce) { + _handleEventListSelectionChange(); + } + }); + } + + /** + * Creates the 2 profile space checkboxes, event count and unit mask widget. + * @param parent composite these widgets will be created in + */ + private void createRightCell(Composite parent) { + //profile kernel checkbox + _profileKernelCheck = new Button(parent, SWT.CHECK); + _profileKernelCheck.setText(OprofileLaunchMessages.getString("tab.event.counterSettings.profileKernel.check.text")); //$NON-NLS-1$ + _profileKernelCheck.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent se) { + _handleProfileKernelToggle(); + } + }); + + //profile user checkbox -- should this ever be disabled? + _profileUserCheck = new Button(parent, SWT.CHECK); + _profileUserCheck.setText(OprofileLaunchMessages.getString("tab.event.counterSettings.profileUser.check.text")); //$NON-NLS-1$ + _profileUserCheck.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent se) { + _handleProfileUserToggle(); + } + }); + + //event count label/text + _countTextLabel = new Label(parent, SWT.NONE); + _countTextLabel.setText(OprofileLaunchMessages.getString("tab.event.counterSettings.count.label.text")); //$NON-NLS-1$ + _countText = new Text(parent, SWT.SINGLE | SWT.BORDER); + _countText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + _countText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent me) { + _handleCountTextModify(); + } + }); + + //unit mask widget + Composite unitMaskComp = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + unitMaskComp.setLayout(layout); + unitMaskComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); + + _unitMaskViewer = new UnitMaskViewer(unitMaskComp); + } + + /** + * Initializes the tab on first creation. + * @param config default configuration for the counter and the associated widgets + */ + public void initializeTab(ILaunchConfiguration config) { + //make all controls inactive, since the 'default event' checkbox + // is checked by default + setEnabledState(false); + + if (config != null) { + _counter.loadConfiguration(config); + } + + boolean enabled = _counter.getEnabled(); + _enabledCheck.setSelection(enabled); + + if (_counter.getEvent() == null) { + // Default to first in list + _counter.setEvent(_counter.getValidEvents()[0]); + } + + //load default states + _profileKernelCheck.setSelection(_counter.getProfileKernel()); + _profileUserCheck.setSelection(_counter.getProfileUser()); + _countText.setText(Integer.toString(_counter.getCount())); + _eventDescText.setText(_counter.getEvent().getTextDescription()); + _unitMaskViewer.displayEvent(_counter.getEvent()); + _eventList.setSelection(new StructuredSelection(_counter.getEvent())); + } + + /** + * Applies the tab's current state to the launch configuration. + * @param config launch config to apply to + */ + public void performApply(ILaunchConfigurationWorkingCopy config) { + _counter.saveConfiguration(config); + } + + /** + * Enables/disables the widgets in this tab. + * @param state true to enable to the counter's state, false to disable all + */ + public void setEnabledState(boolean state) { + _enabledCheck.setEnabled(state); + + if (state) { + _setEnabledState(_counter.getEnabled()); + } else { + _setEnabledState(false); + } + } + + /** + * Method split from setEnabledState to avoid code duplication. + * Not meant to be called directly. + * @param state true to enable all widgets, false to disable all widgets + */ + private void _setEnabledState(boolean state) { + _profileKernelCheck.setEnabled(state); + _profileUserCheck.setEnabled(state); + _countText.setEnabled(state); + _eventDescText.setEnabled(state); + _unitMaskViewer.setEnabled(state); + _eventList.getList().setEnabled(state); + } + + /** + * Handling method for the event list. Gets the selection from the listviewer + * and updates the UnitMask and event description text box. + */ + private void _handleEventListSelectionChange() { + int index = _eventList.getList().getSelectionIndex(); + OpEvent event = (OpEvent) _eventList.getElementAt(index); + _counter.setEvent(event); + _eventDescText.setText(event.getTextDescription()); + _unitMaskViewer.displayEvent(event); + + // Check the min count to update the error message (events can have + // different minimum reset counts) + int min = _counter.getEvent().getMinCount(); + if (_counter.getCount() < min) { + setErrorMessage(getMinCountErrorMessage(min)); + } + + updateLaunchConfigurationDialog(); + } + + /** + * Handles the toggling of the "profile user" button. + */ + private void _handleProfileUserToggle() { + _counter.setProfileUser(_profileUserCheck.getSelection()); + updateLaunchConfigurationDialog(); + } + + /** + * Handles the toggling of the "profile kernel" button. + */ + private void _handleProfileKernelToggle() { + _counter.setProfileKernel(_profileKernelCheck.getSelection()); + updateLaunchConfigurationDialog(); + } + + /** + * Handles text modify events in the count text widget. + */ + private void _handleCountTextModify() { + String errorMessage = null; + try { + + // This seems counter-intuitive, but we must save the count + // so that isValid knows this launch config is invalid + int count = Integer.parseInt(_countText.getText()); + _counter.setCount(count); + + // Check minimum count + int min = _counter.getEvent().getMinCount(); + if (count < min) { + errorMessage = getMinCountErrorMessage(min); + } + } catch (NumberFormatException e) { + errorMessage = OprofileLaunchMessages.getString("tab.event.counterSettings.count.invalid"); //$NON-NLS-1$ + _counter.setCount(OprofileDaemonEvent.COUNT_INVALID); + } finally { + setErrorMessage(errorMessage); + updateLaunchConfigurationDialog(); + } + } + + /** + * Returns a string with the minimum allowed count, suitable foruse with setErrorMessage(). + * @param min minimum count + * @return a String containing the error message + */ + private String getMinCountErrorMessage(int min) { + String msg = OprofileLaunchMessages.getString("tab.event.counterSettings.count.too-small"); //$NON-NLS-1$ + Object[] args = new Object[] { new Integer(min) }; + return MessageFormat.format(msg, args); + } + + /** + * Changes parameters for the top scrolled composite which makes the scroll bars + * appear when content overflows the visible area. Called by the UnitMaskViewer + * whenever a new set of unit mask buttons are created, since the number of them is + * variable and there is no guarantee as to the default size of the launch configuration + * dialog in general. + */ + private void resizeScrollContainer() { + _scrolledTop.setMinSize(_tabTopContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + } + + + /** + * This class displays event unit masks via check boxes and appropriate labels. + */ + class UnitMaskViewer { + private Label _unitMaskLabel; + private Composite _top; + private Composite _maskListComp; + private Button[] _unitMaskButtons; + + /** + * Constructor, creates the widget. + * @param parent composite the widget will be created in + */ + public UnitMaskViewer(Composite parent) { + //"Unit Mask:" label + _unitMaskLabel = new Label(parent, SWT.NONE); + _unitMaskLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + _unitMaskLabel.setText(OprofileLaunchMessages.getString("unitmaskViewer.label.text")); //$NON-NLS-1$ + _unitMaskLabel.setVisible(true); + + //composite to contain the button widgets + Composite top = new Composite(parent, SWT.NONE); + top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + top.setLayout(layout); + _top = top; + + _maskListComp = null; + _unitMaskButtons = null; + } + + /** + * Handles button toggles; updates the counter's unit mask to the appropriate value. + * @param maskButton the button object + * @param index the button's mask index (used in OpUnitMask for a proper mask value) + */ + private void _handleToggle(Button maskButton, int index) { + OpUnitMask mask = _counter.getUnitMask(); + if (mask != null) { + if (maskButton.getSelection()) { + mask.setMaskFromIndex(index); + } else { + mask.unSetMaskFromIndex(index); + } + } + + //update the parent tab + updateLaunchConfigurationDialog(); + } + + /** + * Disposes of the old unit mask check list and creates a new one with + * the appropriate default value. + * @param oe the event + */ + public void displayEvent(OpEvent oe) { + OpUnitMask mask = oe.getUnitMask(); + int totalMasks = mask.getNumMasks(); + + if (_maskListComp != null) { + _maskListComp.dispose(); + } + + Composite newMaskComp = new Composite(_top, SWT.NONE); + newMaskComp.setLayout(new GridLayout()); + newMaskComp.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true)); + _maskListComp = newMaskComp; + + //creates these buttons with the default masks + mask.setDefaultMaskValue(); + + ArrayList