use of org.springframework.util.StopWatch in project engine by craftercms.
the class GraphQLFactoryImpl method getInstance.
/**
* {@inheritDoc}
*/
public GraphQL getInstance(SiteContext siteContext) {
StopWatch watch = new StopWatch("GraphQL Schema");
watch.start("Schema Build");
GraphQLSchema schema = buildSchema(siteContext);
watch.stop();
if (logger.isTraceEnabled()) {
logger.trace(watch.prettyPrint());
}
return GraphQL.newGraphQL(schema).build();
}
use of org.springframework.util.StopWatch in project engine by craftercms.
the class ContentTypeBasedDataFetcher method doGet.
/**
* {@inheritDoc}
*/
@Override
public Object doGet(final DataFetchingEnvironment env) {
Field field = env.getMergedField().getSingleField();
String fieldName = field.getName();
// Get arguments for pagination & sorting
int offset = Optional.ofNullable(env.<Integer>getArgument(ARG_NAME_OFFSET)).orElse(0);
int limit = Optional.ofNullable(env.<Integer>getArgument(ARG_NAME_LIMIT)).orElse(defaultLimit);
String sortBy = Optional.ofNullable(env.<String>getArgument(ARG_NAME_SORT_BY)).orElse(defaultSortField);
String sortOrder = Optional.ofNullable(env.<String>getArgument(ARG_NAME_SORT_ORDER)).orElse(defaultSortOrder);
List<String> queryFieldIncludes = new LinkedList<>();
// Add content-type to includes, we might need it for a GraphQL TypeResolver
queryFieldIncludes.add(QUERY_FIELD_NAME_CONTENT_TYPE);
List<Map<String, Object>> items = new LinkedList<>();
Map<String, Object> result = new HashMap<>(2);
result.put(FIELD_NAME_ITEMS, items);
// Setup the ES query
SearchSourceBuilder source = new SearchSourceBuilder();
BoolQueryBuilder query = boolQuery();
source.query(query).from(offset).size(limit).sort(sortBy, SortOrder.fromString(sortOrder));
StopWatch watch = new StopWatch(field.getName() + " - " + field.getAlias());
watch.start("build filters");
// Filter by the content-type
switch(fieldName) {
case FIELD_NAME_CONTENT_ITEMS:
query.filter(existsQuery(QUERY_FIELD_NAME_CONTENT_TYPE));
break;
case FIELD_NAME_PAGES:
query.filter(regexpQuery(QUERY_FIELD_NAME_CONTENT_TYPE, CONTENT_TYPE_REGEX_PAGE));
break;
case FIELD_NAME_COMPONENTS:
query.filter(regexpQuery(QUERY_FIELD_NAME_CONTENT_TYPE, CONTENT_TYPE_REGEX_COMPONENT));
break;
default:
// Get the content-type name from the field name
query.filter(termQuery(QUERY_FIELD_NAME_CONTENT_TYPE, getOriginalName(fieldName)));
break;
}
// Check the selected fields to build the ES query
Optional<Field> itemsField = field.getSelectionSet().getSelections().stream().map(f -> (Field) f).filter(f -> f.getName().equals(FIELD_NAME_ITEMS)).findFirst();
if (itemsField.isPresent()) {
List<Selection> selections = itemsField.get().getSelectionSet().getSelections();
selections.forEach(selection -> processSelection(StringUtils.EMPTY, selection, query, queryFieldIncludes, env));
}
// Only fetch the selected fields for better performance
source.fetchSource(queryFieldIncludes.toArray(new String[0]), new String[0]);
watch.stop();
logger.debug("Executing query: {}", source);
watch.start("searching items");
SearchResponse response = elasticsearch.search(new SearchRequest().source(source));
watch.stop();
watch.start("processing items");
result.put(FIELD_NAME_TOTAL, response.getHits().totalHits);
if (response.getHits().totalHits > 0) {
for (SearchHit hit : response.getHits().getHits()) {
items.add(fixItems(hit.getSourceAsMap()));
}
}
watch.stop();
if (logger.isTraceEnabled()) {
logger.trace(watch.prettyPrint());
}
return result;
}
use of org.springframework.util.StopWatch in project gocd by gocd.
the class UserSqlMapDaoCachingTest method enabledUserCacheShouldBeThreadSafe.
@Test
@Timeout(60)
public void enabledUserCacheShouldBeThreadSafe() throws Exception {
ThreadSafetyChecker threadSafetyChecker = new ThreadSafetyChecker(10000);
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("enabledUserCount");
stopWatch.start("enabledUserCount");
userDao.enabledUserCount();
stopWatch.stop();
// System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("saveOrUpdate");
stopWatch.start("saveOrUpdate");
userDao.saveOrUpdate(new User("some-random-user " + runIndex));
stopWatch.stop();
// System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("enableUsers");
stopWatch.start("enableUsers");
userDao.enableUsers(Arrays.asList("some-random-user " + runIndex));
stopWatch.stop();
// System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.run(250);
}
use of org.springframework.util.StopWatch in project spring-framework by spring-projects.
the class PerformanceMonitorInterceptor method invokeUnderTrace.
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = createInvocationTraceName(invocation);
StopWatch stopWatch = new StopWatch(name);
stopWatch.start(name);
try {
return invocation.proceed();
} finally {
stopWatch.stop();
writeToLog(logger, stopWatch.shortSummary());
}
}
use of org.springframework.util.StopWatch in project spring-framework by spring-projects.
the class IntroductionBenchmarkTests method timeManyInvocations.
@Test
public void timeManyInvocations() {
StopWatch sw = new StopWatch();
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.setProxyTargetClass(false);
pf.addAdvice(new SimpleCounterIntroduction());
ITestBean proxy = (ITestBean) pf.getProxy();
Counter counter = (Counter) proxy;
sw.start(INVOCATIONS + " invocations on proxy, not hitting introduction");
for (int i = 0; i < INVOCATIONS; i++) {
proxy.getAge();
}
sw.stop();
sw.start(INVOCATIONS + " invocations on proxy, hitting introduction");
for (int i = 0; i < INVOCATIONS; i++) {
counter.getCount();
}
sw.stop();
sw.start(INVOCATIONS + " invocations on target");
for (int i = 0; i < INVOCATIONS; i++) {
target.getAge();
}
sw.stop();
System.out.println(sw.prettyPrint());
}
Aggregations