Search in sources :

Example 6 with OprofileSAXHandler

use of org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler in project linuxtools by eclipse.

the class TestInfoParse method setUp.

@Before
public void setUp() throws Exception {
    /* this code mostly taken from OpxmlRunner */
    XMLReader reader = null;
    info = new OpInfo();
    OprofileSAXHandler handler = OprofileSAXHandler.getInstance(info);
    // Create XMLReader
    SAXParserFactory factory = SAXParserFactory.newInstance();
    reader = factory.newSAXParser().getXMLReader();
    // Set content/error handlers
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    String filePath = FileLocator.toFileURL(FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(REL_PATH_TO_TEST_XML), null)).getFile();
    reader.parse(new InputSource(new FileReader(filePath)));
    info_0ctr = new OpInfo();
    handler = OprofileSAXHandler.getInstance(info_0ctr);
    // Set content/error handlers
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    filePath = FileLocator.toFileURL(FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(REL_PATH_TO_TEST_XML_0CTR), null)).getFile();
    reader.parse(new InputSource(new FileReader(filePath)));
}
Also used : Path(org.eclipse.core.runtime.Path) InputSource(org.xml.sax.InputSource) OpInfo(org.eclipse.linuxtools.internal.oprofile.core.daemon.OpInfo) FileReader(java.io.FileReader) OprofileSAXHandler(org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Before(org.junit.Before)

Example 7 with OprofileSAXHandler

use of org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler in project linuxtools by eclipse.

the class OpxmlRunner method run.

/**
 * 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
 */
public boolean run(String[] args, Object callData) {
    XMLReader reader = null;
    OprofileSAXHandler handler = OprofileSAXHandler.getInstance(callData);
    // Create XMLReader
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        reader = factory.newSAXParser().getXMLReader();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    // Set content/error handlers
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    // Check for timer support
    InfoAdapter.checkTimerSupport();
    // Run opxml
    try {
        File file = constructFile(args);
        // handle the opxml_session file
        if (args[0].equals(SessionManager.SESSIONS)) {
            SessionManager sessManNew = new SessionManager(SessionManager.SESSION_LOCATION);
            populateWithCurrentSession(sessManNew);
            sessManNew.write();
            FileReader fr = new FileReader(file);
            reader.parse(new InputSource(fr));
        // file has not been saved
        } else if (!file.exists()) {
            AbstractDataAdapter aea;
            if (args[0].equals(CheckEventAdapter.CHECK_EVENTS)) {
                aea = new CheckEventAdapter(args[1], args[2], args[3]);
                aea.process();
                BufferedReader bi = new BufferedReader(new InputStreamReader(aea.getInputStream()));
                reader.parse(new InputSource(bi));
            } else if (args[0].equals(InfoAdapter.INFO)) {
                aea = new InfoAdapter();
                aea.process();
                BufferedReader bi = new BufferedReader(new InputStreamReader(aea.getInputStream()));
                reader.parse(new InputSource(bi));
            } else if (args[0].equals(ModelDataAdapter.MODEL_DATA)) {
                // has not been generated
                if (!handleModelData(args)) {
                    return false;
                }
                FileReader fr = new FileReader(file);
                reader.parse(new InputSource(fr));
            } else {
                // $NON-NLS-1$
                throw new RuntimeException("Unrecognized argument encountered");
            }
        } else {
            // always regenerate the 'current' session file
            if (args.length == 3 && args[0].equals(SessionManager.MODEL_DATA) && args[2].equals(SessionManager.CURRENT)) {
                if (!handleModelData(args)) {
                    return false;
                }
            }
            FileReader fr = new FileReader(file);
            reader.parse(new InputSource(fr));
        }
        return true;
    } catch (SAXException e) {
        e.printStackTrace();
        // $NON-NLS-1$
        OprofileCorePlugin.showErrorDialog("opxmlSAXParseException", null);
    } catch (IOException e) {
        e.printStackTrace();
        // $NON-NLS-1$
        OprofileCorePlugin.showErrorDialog("opxmlParse", null);
    }
    return false;
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) SessionManager(org.eclipse.linuxtools.internal.oprofile.core.opxml.sessions.SessionManager) OprofileSAXHandler(org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) InfoAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.info.InfoAdapter) CheckEventAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) AbstractDataAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.AbstractDataAdapter) File(java.io.File) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 8 with OprofileSAXHandler

use of org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler in project linuxtools by eclipse.

the class TestingOpModelEvent2 method getNewImage.

@Override
protected OpModelImage getNewImage() {
    /* this code mostly taken from OpxmlRunner */
    OpModelImage parsedImage = null;
    try {
        XMLReader reader = null;
        parsedImage = new OpModelImage();
        ModelDataProcessor.CallData image = new ModelDataProcessor.CallData(parsedImage);
        OprofileSAXHandler handler = OprofileSAXHandler.getInstance(image);
        // Create XMLReader
        SAXParserFactory factory = SAXParserFactory.newInstance();
        reader = factory.newSAXParser().getXMLReader();
        // Set content/error handlers
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);
        String filePath = FileLocator.toFileURL(FileLocator.find(TestPlugin.getDefault().getBundle(), new Path(REL_PATH_TO_TEST_XML), null)).getFile();
        reader.parse(new InputSource(new FileReader(filePath)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return parsedImage;
}
Also used : Path(org.eclipse.core.runtime.Path) OpModelImage(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage) InputSource(org.xml.sax.InputSource) FileNotFoundException(java.io.FileNotFoundException) OprofileSAXHandler(org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ModelDataProcessor(org.eclipse.linuxtools.internal.oprofile.core.opxml.modeldata.ModelDataProcessor) FileReader(java.io.FileReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

FileReader (java.io.FileReader)8 SAXParserFactory (javax.xml.parsers.SAXParserFactory)8 OprofileSAXHandler (org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler)8 InputSource (org.xml.sax.InputSource)8 XMLReader (org.xml.sax.XMLReader)8 Path (org.eclipse.core.runtime.Path)7 IOException (java.io.IOException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 OpModelImage (org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage)4 ModelDataProcessor (org.eclipse.linuxtools.internal.oprofile.core.opxml.modeldata.ModelDataProcessor)4 SAXException (org.xml.sax.SAXException)4 FileNotFoundException (java.io.FileNotFoundException)3 Before (org.junit.Before)3 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 CoreException (org.eclipse.core.runtime.CoreException)1 OpInfo (org.eclipse.linuxtools.internal.oprofile.core.daemon.OpInfo)1 AbstractDataAdapter (org.eclipse.linuxtools.internal.oprofile.core.opxml.AbstractDataAdapter)1 CheckEventAdapter (org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter)1