use of org.perf4j.StopWatch in project cuba by cuba-platform.
the class FrameComponentLoader method loadComponent.
@Override
public void loadComponent() {
if (resultComponent.getMessagesPack() == null) {
resultComponent.setMessagesPack(messagesPack);
}
assignXmlDescriptor(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadResponsive(resultComponent, element);
loadAlign(resultComponent, element);
loadHeight(resultComponent, element, ComponentsHelper.getComponentHeigth(resultComponent));
loadWidth(resultComponent, element, ComponentsHelper.getComponentWidth(resultComponent));
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
if (context.getFrame() != null) {
resultComponent.setFrame(context.getFrame());
}
String src = element.attributeValue("src");
String screenId = element.attributeValue("screen");
String screenPath = StringUtils.isEmpty(screenId) ? src : screenId;
if (element.attributeValue("id") != null) {
screenPath = element.attributeValue("id");
}
if (context.getFrame() != null) {
String parentId = context.getFullFrameId();
if (StringUtils.isNotEmpty(parentId)) {
screenPath = parentId + "." + screenPath;
}
}
StopWatch loadDescriptorWatch = new Slf4JStopWatch(screenPath + "#" + UIPerformanceLogger.LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
loadDescriptorWatch.start();
String currentFrameId = context.getCurrentFrameId();
try {
context.setCurrentFrameId(frameId);
frameLoader.loadComponent();
} finally {
context.setCurrentFrameId(currentFrameId);
loadDescriptorWatch.stop();
}
}
use of org.perf4j.StopWatch in project cuba by cuba-platform.
the class RuntimePropertiesFrameLoader method loadComponent.
@Override
public void loadComponent() {
if (resultComponent.getMessagesPack() == null) {
resultComponent.setMessagesPack(messagesPack);
}
assignXmlDescriptor(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadAlign(resultComponent, element);
loadHeight(resultComponent, element, ComponentsHelper.getComponentHeigth(resultComponent));
loadWidth(resultComponent, element, ComponentsHelper.getComponentWidth(resultComponent));
String src = element.attributeValue("src");
if (src == null) {
src = DEFAULT_DESCRIPTOR;
}
String runtimeDs = element.attributeValue("runtimeDs");
if (StringUtils.isEmpty(runtimeDs)) {
throw new GuiDevelopmentException("runtimePropsDatasource is not set for runtimeProperties component", context.getFullFrameId());
}
context.getParams().put("runtimeDs", runtimeDs);
String categoriesDs = element.attributeValue("categoriesDs");
if (StringUtils.isEmpty(categoriesDs)) {
throw new GuiDevelopmentException("categoriesDs is not set for runtimeProperties component", context.getFullFrameId());
}
context.getParams().put("categoriesDs", categoriesDs);
String rows = element.attributeValue("rows");
context.getParams().put("rows", rows);
String cols = element.attributeValue("cols");
context.getParams().put("cols", cols);
String fieldWidth = element.attributeValue("fieldWidth");
context.getParams().put("fieldWidth", fieldWidth);
String fieldCaptionWidth = element.attributeValue("fieldCaptionWidth");
context.getParams().put("fieldCaptionWidth", fieldCaptionWidth);
String screenPath = Objects.equals(src, DEFAULT_DESCRIPTOR) ? "runtimeProperties" : src;
if (element.attributeValue("id") != null) {
screenPath = element.attributeValue("id");
}
if (context.getFrame() != null) {
String parentId = context.getFullFrameId();
if (StringUtils.isNotEmpty(parentId)) {
screenPath = parentId + "." + screenPath;
}
}
StopWatch loadDescriptorWatch = new Slf4JStopWatch(screenPath + "#" + UIPerformanceLogger.LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
loadDescriptorWatch.start();
String currentFrameId = context.getCurrentFrameId();
try {
context.setCurrentFrameId(frameId);
frameLoader.loadComponent();
} finally {
context.setCurrentFrameId(currentFrameId);
loadDescriptorWatch.stop();
}
}
use of org.perf4j.StopWatch in project bioformats by openmicroscopy.
the class Memoizer method saveMemo.
/**
* Save a reader including all reader wrappers inside a memo file.
*/
public boolean saveMemo() {
if (skipSave) {
LOGGER.trace("skip memo");
return false;
}
final Deser ser = getDeser();
final StopWatch sw = stopWatch();
boolean rv = true;
try {
// Create temporary location for output
// Note: can't rename tempfile until resources are closed.
tempFile = File.createTempFile(memoFile.getName(), "", memoFile.getParentFile());
ser.saveStart(tempFile);
// Save to temporary location.
ser.saveVersion(VERSION);
ser.saveReleaseVersion(FormatTools.VERSION);
ser.saveReader(reader);
ser.saveStop();
LOGGER.debug("saved to temp file: {}", tempFile);
} catch (Throwable t) {
// Any exception should be ignored, and false returned.
LOGGER.warn(String.format("failed to save memo file: %s", memoFile), t);
rv = false;
} finally {
// Close the output stream quietly regardless.
try {
ser.saveStop();
sw.stop("loci.formats.Memoizer.saveMemo");
} catch (Throwable t) {
LOGGER.error("output close failed", t);
}
// resources can lead to segfaults
if (rv) {
if (!tempFile.renameTo(memoFile)) {
LOGGER.error("temp file rename returned false: {}", tempFile);
} else {
LOGGER.debug("saved memo file: {} ({} bytes)", memoFile, memoFile.length());
}
}
deleteQuietly(tempFile);
}
return rv;
}
use of org.perf4j.StopWatch in project bioformats by openmicroscopy.
the class Memoizer method setId.
// -- ReaderWrapper API methods --
@Override
public void setId(String id) throws FormatException, IOException {
StopWatch sw = stopWatch();
try {
realFile = new Location(id);
memoFile = getMemoFile(id);
if (memoFile == null) {
// Memoization disabled.
if (userMetadataStore != null) {
reader.setMetadataStore(userMetadataStore);
}
// EARLY EXIT
super.setId(id);
return;
}
// Should never throw kryo exceptions
IFormatReader memo = loadMemo();
loadedFromMemo = false;
savedToMemo = false;
if (memo != null) {
// loadMemo has already called handleMetadataStore with non-null
try {
loadedFromMemo = true;
reader = memo;
reader.reopenFile();
} catch (FileNotFoundException e) {
LOGGER.info("could not reopen file - deleting invalid memo file: {}", memoFile);
deleteQuietly(memoFile);
memo = null;
reader.close();
loadedFromMemo = false;
}
}
if (memo == null) {
OMEXMLService service = getService();
super.setMetadataStore(service.createOMEXMLMetadata());
long start = System.currentTimeMillis();
super.setId(id);
long elapsed = System.currentTimeMillis() - start;
// Between setId and saveMemo
handleMetadataStore(null);
if (elapsed < minimumElapsed) {
LOGGER.debug("skipping save memo. elapsed millis: {}", elapsed);
// EARLY EXIT!
return;
}
// Should never throw.
savedToMemo = saveMemo();
}
} catch (ServiceException e) {
LOGGER.error("Could not create OMEXMLMetadata", e);
} finally {
sw.stop("loci.formats.Memoizer.setId");
}
}
use of org.perf4j.StopWatch in project bioformats by openmicroscopy.
the class OpenBytesPerformanceTest method testOpenBytesAllTilesPreAllocatedBuffer.
@Test(dependsOnMethods = { "setId" })
@Assumption(methods = "isNotBigImage")
public void testOpenBytesAllTilesPreAllocatedBuffer() throws Exception {
for (int series = 0; series < seriesCount; series++) {
assertSeries(series);
for (int image = 0; image < imageCount; image++) {
LOGGER.info("Reading from series {} image {}", series, image);
optimalTileWidth = reader.getOptimalTileWidth();
optimalTileHeight = reader.getOptimalTileHeight();
LOGGER.info("Optimal tile {}x{}", optimalTileWidth, optimalTileHeight);
int tilesWide = (int) Math.ceil((double) sizeX / optimalTileWidth);
int tilesHigh = (int) Math.ceil((double) sizeY / optimalTileHeight);
LOGGER.info("Tile counts {}x{}", tilesWide, tilesHigh);
int x, y = 0;
StopWatch stopWatch;
byte[] buf = new byte[optimalTileWidth * optimalTileHeight * FormatTools.getBytesPerPixel(reader.getPixelType())];
LOGGER.info("Allocated buffer size: {}", buf.length);
for (int tileX = 0; tileX < tilesWide; tileX++) {
for (int tileY = 0; tileY < tilesHigh; tileY++) {
x = tileX * optimalTileWidth;
y = tileY * optimalTileHeight;
int actualTileWidth = (int) Math.min(optimalTileWidth, reader.getSizeX() - x);
int actualTileHeight = (int) Math.min(optimalTileHeight, reader.getSizeY() - y);
LOGGER.info("Reading tile at {}x{}", x, y);
stopWatch = new Slf4JStopWatch(String.format("%s.prealloc_tile.%s.[%d:%d]", ((ReaderWrapper) reader).unwrap().getClass().getName(), filename, series, image));
reader.openBytes(image, buf, x, y, actualTileWidth, actualTileHeight);
stopWatch.stop();
}
}
}
}
}
Aggregations