use of org.springframework.util.StopWatch in project pinpoint by naver.
the class ScatterChartController method getScatterData.
/**
* @param applicationName
* @param from
* @param to
* @param limit max number of data return. if the requested data exceed this limit, we need additional calls to
* fetch the rest of the data
* @return
*/
@RequestMapping(value = "/getScatterData", method = RequestMethod.GET)
public ModelAndView getScatterData(@RequestParam("application") String applicationName, @RequestParam("from") long from, @RequestParam("to") long to, @RequestParam("xGroupUnit") int xGroupUnit, @RequestParam("yGroupUnit") int yGroupUnit, @RequestParam("limit") int limit, @RequestParam(value = "backwardDirection", required = false, defaultValue = "true") boolean backwardDirection, @RequestParam(value = "filter", required = false) String filterText, @RequestParam(value = "_callback", required = false) String jsonpCallback, @RequestParam(value = "v", required = false, defaultValue = "1") int version) {
if (xGroupUnit <= 0) {
throw new IllegalArgumentException("xGroupUnit(" + xGroupUnit + ") must be positive number");
}
if (yGroupUnit < 0) {
throw new IllegalArgumentException("yGroupUnit(" + yGroupUnit + ") may not be negative number");
}
limit = LimitUtils.checkRange(limit);
StopWatch watch = new StopWatch();
watch.start("getScatterData");
// TODO range check verification exception occurs. "from" is bigger than "to"
final Range range = Range.createUncheckedRange(from, to);
logger.debug("fetch scatter data. RANGE={}, X-Group-Unit:{}, Y-Group-Unit:{}, LIMIT={}, BACKWARD_DIRECTION:{}, FILTER:{}", range, xGroupUnit, yGroupUnit, limit, backwardDirection, filterText);
ModelAndView mv = null;
if (StringUtils.isEmpty(filterText)) {
mv = selectScatterData(applicationName, range, xGroupUnit, Math.max(yGroupUnit, 1), limit, backwardDirection, version);
} else {
mv = selectFilterScatterData(applicationName, range, xGroupUnit, Math.max(yGroupUnit, 1), limit, backwardDirection, filterText, version);
}
if (jsonpCallback == null) {
mv.setViewName("jsonView");
} else {
mv.setViewName("jsonpView");
}
watch.stop();
logger.info("Fetch scatterData time : {}ms", watch.getLastTaskTimeMillis());
return mv;
}
use of org.springframework.util.StopWatch in project esup-papercut by EsupPortail.
the class PayBoxResourceController method getCsv.
@RequestMapping("/csv")
@Transactional
public void getCsv(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
String sharedSessionId = request.getParameter("sharedSessionId");
if (sharedSessionId != null) {
EsupPapercutSessionObject objectShared = (EsupPapercutSessionObject) session.getAttribute(sharedSessionId);
if (objectShared.isIsAdmin()) {
StopWatch stopWatch = new StopWatch("Stream - build CSV and send it");
stopWatch.start();
response.setContentType("text/csv");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=\"paybox_papercut_transaction_log.csv\"");
Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF8");
String csv = "Date transaction,uid,montant,ID transaction paybox";
writer.write(csv);
TypedQuery<PayboxPapercutTransactionLog> txLogsQuery = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByPaperCutContextEquals(objectShared.getPaperCutContext(), "transactionDate", "asc");
int offset = 0;
int nbLine = 0;
List<PayboxPapercutTransactionLog> txLogs;
while ((txLogs = txLogsQuery.setFirstResult(offset).setMaxResults(1000).getResultList()).size() > 0) {
log.debug("Build CSV Iteration - offset : " + offset);
for (PayboxPapercutTransactionLog txLog : txLogs) {
csv = "";
csv = csv + "\r\n";
csv = csv + txLog.getTransactionDate() + ",";
csv = csv + txLog.getUid() + ",";
csv = csv + txLog.getMontant() + ",";
csv = csv + txLog.getIdtrans();
writer.write(csv);
nbLine++;
}
offset += txLogs.size();
}
stopWatch.stop();
log.info("CSV of " + nbLine + " lines sent in " + stopWatch.getTotalTimeSeconds() + " sec.");
writer.close();
}
}
}
use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class DatasetHolderAggregator method aggregate.
public Dataset aggregate() {
if (this.aggregatedDataset != null) {
return this.aggregatedDataset;
}
synchronized (this) {
if (this.aggregatedDataset != null)
return this.aggregatedDataset;
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Dataset result = DatasetFactory.createGeneral();
stopWatch.stop();
logger.debug("init dataset: " + stopWatch.getLastTaskTimeMillis());
stopWatch.start();
this.aggregatedDataset = result;
if (this.inputStreams == null || this.inputStreams.size() == 0) {
return this.aggregatedDataset;
}
RDFDataMgr.read(result, new SequenceInputStream(Collections.enumeration(Collections.unmodifiableCollection(this.inputStreams))), this.rdfLanguage);
stopWatch.stop();
logger.debug("read dataset: " + stopWatch.getLastTaskTimeMillis());
return this.aggregatedDataset;
}
}
use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class WonConversationUtilsTest method main.
public static void main(String... args) throws Exception {
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.INFO);
// Dataset input = loadDataset("/won/utils/agreement/input/one-agreement-one-cancellation.trig");
Dataset input = loadDataset("/won/utils/conversationutils/input/longer-conversation.trig");
SparqlSelectFunction<QuerySolution> selectfunction = new SparqlSelectFunction<>("/conversation/messagesForHighlevelProtocols.rq", x -> x).addOrderBy("distance", Query.ORDER_ASCENDING).addInitialBinding("senderOfFirstMessage", new ResourceImpl("https://localhost:8443/won/resource/need/4517796920802783000"));
StopWatch sw = new StopWatch();
sw.start();
selectfunction.apply(input).forEach(x -> System.out.println("solution:" + x.toString()));
sw.stop();
System.out.println("query took: " + sw.getLastTaskTimeMillis() / 1000d + " seconds ");
// Thread.currentThread().sleep(30000);
sw.start();
AgreementProtocolState state = AgreementProtocolState.of(input);
sw.stop();
RDFDataMgr.write(System.out, state.getAgreements(), Lang.TRIG);
System.out.println("Analyzing the state of agreement protocol took: " + sw.getLastTaskTimeMillis() / 1000d + " seconds ");
System.out.println(state.getAgreementProtocolUris());
System.out.println(state.getEffects(URI.create("https://localhost:8443/won/resource/event/grj35bbhnkcrlfc72pqo")));
/*
RdfUtils.Pair<Dataset> diff = RdfUtils.diff(input, output);
if (!(diff.getFirst().isEmpty() && diff.getSecond().isEmpty())) {
System.out.println("diff - only in input:");
RDFDataMgr.write(System.out, diff.getFirst(), Lang.TRIG);
System.out.println("diff - only in output:");
RDFDataMgr.write(System.out, diff.getSecond(), Lang.TRIG);
} else {
System.out.println("input and output are equal");
}
*/
// Dataset output = HighlevelProtocols.getProposals(input);
// RDFDataMgr.write(System.out, output, Lang.TRIG);
// initialBinding.add("senderNeed", new ResourceImpl("https://localhost:8443/won/resource/need/7820503869697675000"));
// initialBinding.add("senderConnection", new ResourceImpl("https://localhost:8443/won/resource/connection/4t9deo4t6bqx83jxk5ex"));
// URI uri = WonConversationUtils.getLatestMessageOfNeed(input, URI.create("https://localhost:8443/won/resource/need/7820503869697675000"));
// URI uri = WonConversationUtils.getLatestMessageOfNeed(input, URI.create("https://192.168.124.49:8443/won/resource/need/z35td13ftmn5k1hzella"));
// System.out.println("uri: " + uri);
/*
List<QuerySolution> actual = WonConversationQueryBuilder.getBuilder((x -> x))
//.senderNeed(URI.create("https://localhost:8443/won/resource/need/7820503869697675000"))
.newestFirst()
.noResponses()
.build()
.apply(input);
*/
// System.out.println("actual: \n" + actual.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
/*
URI uri = WonConversationUtils.getLatestProposesMessageOfNeed(input, URI.create("https://localhost:8443/won/resource/need/7820503869697675000"));
System.out.println("uri: " + uri);
uri = WonConversationUtils.getLatestAcceptsMessageOfNeed(input, URI.create("https://localhost:8443/won/resource/need/7820503869697675000"));
System.out.println("uri: " + uri);*/
}
use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class DebugBotIncomingMessageToEventMappingAction method makeReferringMessage.
private Model makeReferringMessage(AgreementProtocolState state, MessageFinder messageFinder, MessageReferrer messageReferrer, TextMessageMaker textMessageMaker) {
int origPrio = Thread.currentThread().getPriority();
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
StopWatch queryStopWatch = new StopWatch();
queryStopWatch.start("query");
List<URI> targetUris = messageFinder.findMessages(state);
URI[] targetUriArray = targetUris.toArray(new URI[targetUris.size()]);
queryStopWatch.stop();
Thread.currentThread().setPriority(origPrio);
Duration queryDuration = Duration.ofMillis(queryStopWatch.getLastTaskTimeMillis());
Model messageModel = WonRdfUtils.MessageUtils.textMessage(textMessageMaker.makeTextMessage(queryDuration, state, targetUriArray));
return messageReferrer.referToMessages(messageModel, targetUriArray);
}
Aggregations