private void logProfiling(long start, Configuration config) { if (config.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY).orElse(false)) { long duration = System.currentTimeMillis() - start; LOG.info("\n -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------\n"); profiler.dump(duration, LOG); LOG.info("\n -------- End of profiling for purge --------\n"); } } }
/** * Delete the non root components (ie. sub-view, application or project copy) from the specified collection of {@link ComponentDto} * and data from their child tables. * <p> * This method has no effect when passed an empty collection or only root components. * </p> */ public void deleteNonRootComponentsInView(DbSession dbSession, Collection<ComponentDto> components) { Set<ComponentDto> nonRootComponents = components.stream().filter(PurgeDao::isNotRoot).collect(MoreCollectors.toSet()); if (nonRootComponents.isEmpty()) { return; } PurgeProfiler profiler = new PurgeProfiler(); PurgeCommands purgeCommands = new PurgeCommands(dbSession, profiler); deleteNonRootComponentsInView(nonRootComponents, purgeCommands); }
@Test public void shouldResetPurgeProfiling() { profiler.start("foo"); clock.sleep(10); profiler.stop(); profiler.reset(); profiler.start("bar"); clock.sleep(5); profiler.stop(); profiler.start("foo"); clock.sleep(8); profiler.stop(); profiler.dump(50, logger); verify(logger).info(contains("foo: 8ms")); verify(logger).info(contains("bar: 5ms")); }
@Test public void shouldProfilePurge() { profiler.start("foo"); clock.sleep(10); profiler.stop(); profiler.start("bar"); clock.sleep(5); profiler.stop(); profiler.start("foo"); clock.sleep(8); profiler.stop(); profiler.dump(50, logger); verify(logger).info(contains("foo: 18ms")); verify(logger).info(contains("bar: 5ms")); }
public ProjectCleaner purge(DbSession session, IdUuidPair rootId, Configuration projectConfig, Collection<String> disabledComponentUuids) { long start = System.currentTimeMillis(); profiler.reset(); PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectConfig, rootId, disabledComponentUuids); periodCleaner.clean(session, configuration.rootProjectIdUuid().getUuid(), projectConfig); purgeDao.purge(session, configuration, purgeListener, profiler); session.commit(); logProfiling(start, projectConfig); return this; }
public void dump(long totalTime, Logger logger) { List<Entry<String, Long>> data = new ArrayList<>(durations.entrySet()); Collections.sort(data, (o1, o2) -> o2.getValue().compareTo(o1.getValue())); double percent = totalTime / 100.0; for (Entry<String, Long> entry : truncateList(data)) { StringBuilder sb = new StringBuilder(); sb.append(" o ").append(entry.getKey()).append(": ").append(TimeUtils.formatDuration(entry.getValue())) .append(" (").append((int) (entry.getValue() / percent)).append("%)"); logger.info(sb.toString()); } }
public ProjectCleaner purge(DbSession session, IdUuidPair rootId, Configuration projectConfig, Collection<String> disabledComponentUuids) { long start = System.currentTimeMillis(); profiler.reset(); PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectConfig, rootId, disabledComponentUuids); periodCleaner.clean(session, configuration.rootProjectIdUuid().getUuid(), projectConfig); purgeDao.purge(session, configuration, purgeListener, profiler); session.commit(); logProfiling(start, projectConfig); return this; }
public void dump(long totalTime, Logger logger) { List<Entry<String, Long>> data = new ArrayList<>(durations.entrySet()); Collections.sort(data, (o1, o2) -> o2.getValue().compareTo(o1.getValue())); double percent = totalTime / 100.0; for (Entry<String, Long> entry : truncateList(data)) { StringBuilder sb = new StringBuilder(); sb.append(" o ").append(entry.getKey()).append(": ").append(TimeUtils.formatDuration(entry.getValue())) .append(" (").append((int) (entry.getValue() / percent)).append("%)"); logger.info(sb.toString()); } }
public void deleteBranch(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeMapper purgeMapper = mapper(session); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); deleteRootComponent(uuid, purgeMapper, purgeCommands); }
@Test public void no_profiling_when_property_is_false() { settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false); underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList()); verify(profiler, never()).dump(anyLong(), any()); }
void deletePermissions(long rootId) { profiler.start("deletePermissions (group_roles)"); purgeMapper.deleteGroupRolesByComponentId(rootId); session.commit(); profiler.stop(); profiler.start("deletePermissions (user_roles)"); purgeMapper.deleteUserRolesByComponentId(rootId); session.commit(); profiler.stop(); }
public void deleteProject(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeMapper purgeMapper = mapper(session); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); session.getMapper(BranchMapper.class).selectByProjectUuid(uuid) .stream() .filter(branch -> !uuid.equals(branch.getUuid())) .forEach(branch -> deleteRootComponent(branch.getUuid(), purgeMapper, purgeCommands)); deleteRootComponent(uuid, purgeMapper, purgeCommands); }
@Test public void profiling_when_property_is_true() { settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true); underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings.asConfig(), emptyList()); verify(profiler).dump(anyLong(), any()); }
@Before public void prepare() { clock = new MockedClock(); profiler = new PurgeProfiler(clock); logger = mock(Logger.class); }
private void logProfiling(long start, Configuration config) { if (config.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY).orElse(false)) { long duration = System.currentTimeMillis() - start; LOG.info("\n -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------\n"); profiler.dump(duration, LOG); LOG.info("\n -------- End of profiling for purge --------\n"); } } }
@Test public void shouldDeleteAnalyses() { db.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml"); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3"))); db.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots"); }