GpuDeviceInformationParser { public synchronized GpuDeviceInformation parseXml(String xmlContent) throws GpuInfoException { if (unmarshaller == null) { try { init(); } catch (SAXException | ParserConfigurationException | JAXBException e) { LOG.error("Exception while initialize parser", e); throw new GpuInfoException(e); } } InputSource inputSource = new InputSource(new StringReader(xmlContent)); SAXSource source = new SAXSource(xmlReader, inputSource); try { return (GpuDeviceInformation) unmarshaller.unmarshal(source); } catch (JAXBException e) { LOG.error("Exception while parsing xml", e); throw new GpuInfoException(e); } }  synchronized GpuDeviceInformation parseXml(String xmlContent);  }
@Test public void testParse() throws IOException, GpuInfoException { File f = new File("tony-core/src/test/resources/nvidia-smi-sample-xml-output"); String s = FileUtils.readFileToString(f, "UTF-8"); GpuDeviceInformationParser parser = new GpuDeviceInformationParser(); GpuDeviceInformation info = parser.parseXml(s); Assert.assertEquals("375.66", info.getDriverVersion()); Assert.assertEquals(2, info.getGpus().size()); PerGpuDeviceInformation gpu1 = info.getGpus().get(1); Assert.assertEquals("Tesla P100-PCIE-12GB", gpu1.getProductName()); Assert.assertEquals(12193, gpu1.getGpuFBMemoryUsage().getTotalMemoryMiB()); Assert.assertEquals(16384, gpu1.getGpuMainMemoryUsage().getTotalMemoryMiB()); Assert.assertEquals(10.3f, gpu1.getGpuUtilizations().getOverallGpuUtilization(), 1e-6); }