Search in sources :

Example 1 with OpModelImage

use of org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage in project linuxtools by eclipse.

the class TestingOpModelEvent 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)

Example 2 with OpModelImage

use of org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage in project linuxtools by eclipse.

the class TestingOpModelEvent3 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)

Example 3 with OpModelImage

use of org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage in project linuxtools by eclipse.

the class TestModelDataParse method testParse.

@Test
public void testParse() {
    // test attributes
    // $NON-NLS-1$
    assertEquals("/test/path/for/image", parsedImage.getName());
    assertEquals(205000, parsedImage.getCount());
    // test symbols
    OpModelSymbol[] symbols = parsedImage.getSymbols();
    assertEquals(2, symbols.length);
    OpModelSymbol sym1 = symbols[0], sym2 = symbols[1];
    // $NON-NLS-1$
    assertEquals("TestFunction1(int)", sym1.getName());
    // $NON-NLS-1$
    assertEquals("/test/path/for/src/image.cpp", sym1.getFilePath());
    assertEquals(180000, sym1.getCount());
    // $NON-NLS-1$
    assertEquals("TestFunction2(int, int)", sym2.getName());
    // $NON-NLS-1$
    assertEquals("/test/path/for/src/image2.cpp", sym2.getFilePath());
    assertEquals(20000, sym2.getCount());
    // test samples
    OpModelSample[] sym1_spls = sym1.getSamples(), sym2_spls = sym2.getSamples();
    assertEquals(4, sym1_spls.length);
    assertEquals(3, sym2_spls.length);
    OpModelSample sym1_spl1 = sym1_spls[0], sym1_spl2 = sym1_spls[1], sym1_spl3 = sym1_spls[2], sym1_spl4 = sym1_spls[3];
    OpModelSample sym2_spl1 = sym2_spls[0], sym2_spl2 = sym2_spls[1], sym2_spl3 = sym2_spls[2];
    assertEquals(130000, sym1_spl1.getCount());
    assertEquals(42, sym1_spl1.getLine());
    assertEquals(40000, sym1_spl2.getCount());
    assertEquals(36, sym1_spl2.getLine());
    assertEquals(9999, sym1_spl3.getCount());
    assertEquals(31, sym1_spl3.getLine());
    assertEquals(1, sym1_spl4.getCount());
    assertEquals(39, sym1_spl4.getLine());
    assertEquals(19998, sym2_spl1.getCount());
    assertEquals(94, sym2_spl1.getLine());
    assertEquals(1, sym2_spl2.getCount());
    assertEquals(12, sym2_spl2.getLine());
    assertEquals(1, sym2_spl3.getCount());
    assertEquals(55, sym2_spl3.getLine());
    // test dependent images
    assertEquals(true, parsedImage.hasDependents());
    assertEquals(5000, parsedImage.getDepCount());
    OpModelImage[] deps = parsedImage.getDependents();
    assertEquals(4, deps.length);
    OpModelImage dep1 = deps[0], dep2 = deps[1], dep3 = deps[2], dep4 = deps[3];
    assertEquals(false, dep1.hasDependents());
    // $NON-NLS-1$
    assertEquals("/no-vmlinux", dep1.getName());
    assertEquals(4400, dep1.getCount());
    assertEquals(false, dep2.hasDependents());
    OpModelSymbol[] dep2_syms = dep2.getSymbols();
    assertEquals(2, dep2_syms.length);
    OpModelSymbol dep2_sym1 = dep2_syms[0], dep2_sym2 = dep2_syms[1];
    OpModelSample[] dep2_sym1_spls = dep2_sym1.getSamples(), dep2_sym2_spls = dep2_sym2.getSamples();
    assertEquals(1, dep2_sym1_spls.length);
    assertEquals(1, dep2_sym2_spls.length);
    OpModelSample dep2_sym1_spl1 = dep2_sym1_spls[0], dep2_sym2_spl1 = dep2_sym2_spls[0];
    // $NON-NLS-1$
    assertEquals("/lib64/ld-2.9.so", dep2.getName());
    assertEquals(300, dep2.getCount());
    // $NON-NLS-1$
    assertEquals("do_lookup_x", dep2_sym1.getName());
    // $NON-NLS-1$
    assertEquals("dl-lookup.c", dep2_sym1.getFilePath());
    assertEquals(299, dep2_sym1.getCount());
    assertEquals(299, dep2_sym1_spl1.getCount());
    assertEquals(0, dep2_sym1_spl1.getLine());
    // $NON-NLS-1$
    assertEquals("_dl_unload_cache", dep2_sym2.getName());
    // $NON-NLS-1$
    assertEquals("rawmemchr.c", dep2_sym2.getFilePath());
    assertEquals(1, dep2_sym2.getCount());
    assertEquals(1, dep2_sym2_spl1.getCount());
    assertEquals(0, dep2_sym2_spl1.getLine());
    assertEquals(false, dep3.hasDependents());
    // $NON-NLS-1$
    assertEquals("/usr/lib64/libstdc++.so.6.0.10", dep3.getName());
    assertEquals(160, dep3.getCount());
    assertEquals(false, dep4.hasDependents());
    OpModelSymbol[] dep4_syms = dep4.getSymbols();
    assertEquals(2, dep4_syms.length);
    OpModelSymbol dep4_sym1 = dep4_syms[0], dep4_sym2 = dep4_syms[1];
    OpModelSample[] dep4_sym1_spls = dep4_sym1.getSamples(), dep4_sym2_spls = dep4_sym2.getSamples();
    assertEquals(1, dep4_sym1_spls.length);
    assertEquals(1, dep4_sym2_spls.length);
    OpModelSample dep4_sym1_spl1 = dep4_sym1_spls[0], dep4_sym2_spl1 = dep4_sym2_spls[0];
    // $NON-NLS-1$
    assertEquals("/lib64/libc-2.9.so", dep4.getName());
    assertEquals(140, dep4.getCount());
    // $NON-NLS-1$
    assertEquals("_IO_new_file_seekoff", dep4_sym1.getName());
    // $NON-NLS-1$
    assertEquals("", dep4_sym1.getFilePath());
    assertEquals(100, dep4_sym1.getCount());
    assertEquals(100, dep4_sym1_spl1.getCount());
    assertEquals(0, dep4_sym1_spl1.getLine());
    // $NON-NLS-1$
    assertEquals("bool std::operator!=<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)", dep4_sym2.getName());
    // $NON-NLS-1$
    assertEquals("", dep4_sym2.getFilePath());
    assertEquals(40, dep4_sym2.getCount());
    assertEquals(40, dep4_sym2_spl1.getCount());
    assertEquals(0, dep4_sym2_spl1.getLine());
    assertEquals(OpModelImage.IMAGE_PARSE_ERROR, parsedErrorImage.getCount());
    assertEquals(0, parsedErrorImage.getDepCount());
    assertNull(parsedErrorImage.getDependents());
    assertNull(parsedErrorImage.getSymbols());
    // $NON-NLS-1$
    assertEquals("", parsedErrorImage.getName());
}
Also used : OpModelImage(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage) OpModelSymbol(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSymbol) OpModelSample(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSample) Test(org.junit.Test)

Example 4 with OpModelImage

use of org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage in project linuxtools by eclipse.

the class TestModelDataParse method setUp.

@Before
public void setUp() throws Exception {
    /* this code mostly taken from OpxmlRunner */
    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(FrameworkUtil.getBundle(this.getClass()), new Path(REL_PATH_TO_TEST_XML), null)).getFile();
    reader.parse(new InputSource(new FileReader(filePath)));
    // 2nd test image
    parsedErrorImage = new OpModelImage();
    ModelDataProcessor.CallData errorImage = new ModelDataProcessor.CallData(parsedErrorImage);
    handler = OprofileSAXHandler.getInstance(errorImage);
    // 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_MULTI_IMAGE), null)).getFile();
    reader.parse(new InputSource(new FileReader(filePath)));
}
Also used : Path(org.eclipse.core.runtime.Path) OpModelImage(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage) InputSource(org.xml.sax.InputSource) ModelDataProcessor(org.eclipse.linuxtools.internal.oprofile.core.opxml.modeldata.ModelDataProcessor) 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 5 with OpModelImage

use of org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage in project linuxtools by eclipse.

the class Oprofile method getModelData.

/**
 * 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 | InterruptedException e) {
    }
    return image;
}
Also used : OpModelImage(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

OpModelImage (org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage)8 FileReader (java.io.FileReader)4 SAXParserFactory (javax.xml.parsers.SAXParserFactory)4 Path (org.eclipse.core.runtime.Path)4 OprofileSAXHandler (org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler)4 ModelDataProcessor (org.eclipse.linuxtools.internal.oprofile.core.opxml.modeldata.ModelDataProcessor)4 InputSource (org.xml.sax.InputSource)4 XMLReader (org.xml.sax.XMLReader)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXException (org.xml.sax.SAXException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 OpModelSample (org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSample)1 OpModelSymbol (org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSymbol)1 Before (org.junit.Before)1 Test (org.junit.Test)1