/* * Prints the probe with the specified name. There * are certain conditions that this method wont print * anything: * * 1) No such probe exists. * 2) The probe has not been closed. */ void printProbe(string s) { TimeProbe* tp; if (probes[s] == 0) return; tp = probes[s]; if (tp->getStatus() != TimeProbe::CLOSED) return; timeval* t1 = tp->getStart(); timeval* t2 = tp->getEnd(); if (t1->tv_usec > t2->tv_usec) { t2->tv_usec += 1000000; t2->tv_sec--; } timeval lapsed; lapsed.tv_usec = t2->tv_usec - t1->tv_usec; lapsed.tv_sec = (int) (t2->tv_sec - t1->tv_sec); cout << s << ": "; printf("Time elapsed: %d.%06dsec\n", (int) lapsed.tv_sec,(int) lapsed.tv_usec); }
/** * Open the probe with the specified name and measures * the time value at that point in the program's path * of execution. * * If a probe for that name already exists, this method * does nothing. */ void openProbe(string s) { TimeProbe* tp; if (probes[s] == 0) { tp = new TimeProbe(); probes[s] = tp; } else { tp = probes[s]; } if (tp->getStatus() != TimeProbe::INACTIVE) return; tp->setStatus(TimeProbe::OPEN); timeval* tv = new timeval(); struct timezone tz; gettimeofday(tv, &tz); tp->setStart(tv); }
void QueryResult::init(const FieldSelector& selector, const IndexReaderPtr& pIndexReader, const QueryHits& hits) { StoredFieldsReaderPtr pStoredFieldsReader = pIndexReader->createStoredFieldsReader(); if (pStoredFieldsReader.isNull()) { return; } TimeProbe probe; probe.start(); m_docs.reserve(hits.size()); setTracer(hits.getTracer()); setTotalHits(hits.getTotalHits()); QueryHits::Iterator it = hits.iterator(); while (it.hasNext()) { const QueryHits::HitDoc& hitDoc = it.next(); ResultDocPtr pResDoc(new ResultDoc(hitDoc.getDocId(), hitDoc.getScore(), selector.size())); addDoc(pResDoc); pStoredFieldsReader->getDocument(selector, *pResDoc); } probe.stop(); FX_QUERY_TRACE(INFO, getTracer(), "fetch field time [%d] ms", (int32_t)probe.elapsed() / 1000); }
void IndexBuilderAppRunner::buildIndex() { try { cout << _T("Begin build index, config file: ") << m_sConfFile << endl; TimeProbe p; p.start(); ProgressObserverPtr pOb(new ConsoleProgressObserver(1000)); FX_NS(collection)::Collection::buildIndex(m_sConfFile, pOb); p.stop(); cout << _T("Build index success! finished in ") << p.elapsedSeconds() << _T(" s.") << endl; } catch(const FirteXException& fe) { cout << _T("Build index FAILED: ") << fe.what() << endl; } }
/** * Closes the probe for the given name. If the probe * is not open or if the probe is already closed this * method does nothing. */ void closeProbe(string s) { TimeProbe* tp; if (probes[s] == 0) return; tp = probes[s]; if (tp->getStatus() != TimeProbe::OPEN) return; timeval* tv = new timeval(); struct timezone tz; gettimeofday(tv, NULL); tp->setEnd(tv); tp->setStatus(TimeProbe::CLOSED); }
void LexiconBuilderAppRunner::buildLexicon() { try { cout << "Begin build lexicon, source file: " << m_sSourceFile << endl << ", target file: " << m_sTargetFile << endl; TimeProbe p; DoubleArrayTrie trie(100000); trie.buildFromFile(m_sSourceFile); trie.save(m_sTargetFile); cout << _T("Build lexicon success! finished in ") << p.elapsedSeconds() << _T(" s.") << endl; } catch(const FirteXException& fe) { cout << _T("Build lexicon FAILED: ") << fe.what() << endl; } }
void GibbsTrackingFilter< ItkQBallImageType >::GenerateData() { TimeProbe preClock; preClock.Start(); // check if input is qball or tensor image and generate qball if necessary if (m_QBallImage.IsNull() && m_TensorImage.IsNotNull()) { TensorImageToQBallImageFilter<float,float>::Pointer filter = TensorImageToQBallImageFilter<float,float>::New(); filter->SetInput( m_TensorImage ); filter->Update(); m_QBallImage = filter->GetOutput(); } else if (m_DuplicateImage) // generate local working copy of QBall image (if not disabled) { typedef itk::ImageDuplicator< ItkQBallImageType > DuplicateFilterType; typename DuplicateFilterType::Pointer duplicator = DuplicateFilterType::New(); duplicator->SetInputImage( m_QBallImage ); duplicator->Update(); m_QBallImage = duplicator->GetOutput(); } // perform mean subtraction on odfs typedef ImageRegionIterator< ItkQBallImageType > InputIteratorType; InputIteratorType it(m_QBallImage, m_QBallImage->GetLargestPossibleRegion() ); it.GoToBegin(); while (!it.IsAtEnd()) { itk::OrientationDistributionFunction<float, QBALL_ODFSIZE> odf(it.Get().GetDataPointer()); float mean = odf.GetMeanValue(); odf -= mean; it.Set(odf.GetDataPointer()); ++it; } // check if mask image is given if it needs resampling PrepareMaskImage(); // load parameter file LoadParameters(); // prepare parameters float minSpacing; if(m_QBallImage->GetSpacing()[0]<m_QBallImage->GetSpacing()[1] && m_QBallImage->GetSpacing()[0]<m_QBallImage->GetSpacing()[2]) minSpacing = m_QBallImage->GetSpacing()[0]; else if (m_QBallImage->GetSpacing()[1] < m_QBallImage->GetSpacing()[2]) minSpacing = m_QBallImage->GetSpacing()[1]; else minSpacing = m_QBallImage->GetSpacing()[2]; if(m_ParticleLength == 0) m_ParticleLength = 1.5*minSpacing; if(m_ParticleWidth == 0) m_ParticleWidth = 0.5*minSpacing; if(m_ParticleWeight == 0) EstimateParticleWeight(); float alpha = log(m_EndTemperature/m_StartTemperature); m_Steps = m_Iterations/10000; if (m_Steps<10) m_Steps = 10; if (m_Steps>m_Iterations) { MITK_INFO << "GibbsTrackingFilter: not enough iterations!"; m_AbortTracking = true; } if (m_CurvatureThreshold < mitk::eps) m_CurvatureThreshold = 0; unsigned long singleIts = (unsigned long)((1.0*m_Iterations) / (1.0*m_Steps)); // seed random generators Statistics::MersenneTwisterRandomVariateGenerator::Pointer randGen = Statistics::MersenneTwisterRandomVariateGenerator::New(); if (m_RandomSeed>-1) randGen->SetSeed(m_RandomSeed); else randGen->SetSeed(); // load sphere interpolator to evaluate the ODFs SphereInterpolator* interpolator = new SphereInterpolator(m_LutPath); // handle lookup table not found cases if( !interpolator->IsInValidState() ) { m_IsInValidState = false; m_AbortTracking = true; m_BuildFibers = false; mitkThrow() << "Unable to load lookup tables."; } // initialize the actual tracking components (ParticleGrid, Metropolis Hastings Sampler and Energy Computer) ParticleGrid* particleGrid; GibbsEnergyComputer* encomp; MetropolisHastingsSampler* sampler; try{ particleGrid = new ParticleGrid(m_MaskImage, m_ParticleLength, m_ParticleGridCellCapacity); encomp = new GibbsEnergyComputer(m_QBallImage, m_MaskImage, particleGrid, interpolator, randGen); encomp->SetParameters(m_ParticleWeight,m_ParticleWidth,m_ConnectionPotential*m_ParticleLength*m_ParticleLength,m_CurvatureThreshold,m_InexBalance,m_ParticlePotential); sampler = new MetropolisHastingsSampler(particleGrid, encomp, randGen, m_CurvatureThreshold); } catch(...) { MITK_ERROR << "Particle grid allocation failed. Not enough memory? Try to increase the particle length."; m_IsInValidState = false; m_AbortTracking = true; m_BuildFibers = false; return; } MITK_INFO << "----------------------------------------"; MITK_INFO << "Iterations: " << m_Iterations; MITK_INFO << "Steps: " << m_Steps; MITK_INFO << "Particle length: " << m_ParticleLength; MITK_INFO << "Particle width: " << m_ParticleWidth; MITK_INFO << "Particle weight: " << m_ParticleWeight; MITK_INFO << "Start temperature: " << m_StartTemperature; MITK_INFO << "End temperature: " << m_EndTemperature; MITK_INFO << "In/Ex balance: " << m_InexBalance; MITK_INFO << "Min. fiber length: " << m_MinFiberLength; MITK_INFO << "Curvature threshold: " << m_CurvatureThreshold; MITK_INFO << "Random seed: " << m_RandomSeed; MITK_INFO << "----------------------------------------"; // main loop preClock.Stop(); TimeProbe clock; clock.Start(); m_NumAcceptedFibers = 0; unsigned long counter = 1; boost::progress_display disp(m_Steps*singleIts); if (!m_AbortTracking) for( m_CurrentStep = 1; m_CurrentStep <= m_Steps; m_CurrentStep++ ) { // update temperatur for simulated annealing process float temperature = m_StartTemperature * exp(alpha*(((1.0)*m_CurrentStep)/((1.0)*m_Steps))); sampler->SetTemperature(temperature); for (unsigned long i=0; i<singleIts; i++) { ++disp; if (m_AbortTracking) break; sampler->MakeProposal(); if (m_BuildFibers || (i==singleIts-1 && m_CurrentStep==m_Steps)) { m_ProposalAcceptance = (float)sampler->GetNumAcceptedProposals()/counter; m_NumParticles = particleGrid->m_NumParticles; m_NumConnections = particleGrid->m_NumConnections; FiberBuilder fiberBuilder(particleGrid, m_MaskImage); m_FiberPolyData = fiberBuilder.iterate(m_MinFiberLength); m_NumAcceptedFibers = m_FiberPolyData->GetNumberOfLines(); m_BuildFibers = false; } counter++; } m_ProposalAcceptance = (float)sampler->GetNumAcceptedProposals()/counter; m_NumParticles = particleGrid->m_NumParticles; m_NumConnections = particleGrid->m_NumConnections; if (m_AbortTracking) break; } if (m_AbortTracking) { FiberBuilder fiberBuilder(particleGrid, m_MaskImage); m_FiberPolyData = fiberBuilder.iterate(m_MinFiberLength); m_NumAcceptedFibers = m_FiberPolyData->GetNumberOfLines(); } clock.Stop(); delete sampler; delete encomp; delete interpolator; delete particleGrid; m_AbortTracking = true; m_BuildFibers = false; int h = clock.GetTotal()/3600; int m = ((int)clock.GetTotal()%3600)/60; int s = (int)clock.GetTotal()%60; MITK_INFO << "GibbsTrackingFilter: finished gibbs tracking in " << h << "h, " << m << "m and " << s << "s"; m = (int)preClock.GetTotal()/60; s = (int)preClock.GetTotal()%60; MITK_INFO << "GibbsTrackingFilter: preparation of the data took " << m << "m and " << s << "s"; MITK_INFO << "GibbsTrackingFilter: " << m_NumAcceptedFibers << " fibers accepted"; // sampler->PrintProposalTimes(); SaveParameters(); }
void HTTPSearchService::handleQuery(const Statement& state, EvHttpRequestContext* pCtx) const { IndexReaderPtr pIndexReader = m_searchRes.getIndexReader(); FIRTEX_ASSERT2(pIndexReader.isNotNull()); try { TimeProbe probe; probe.start(); QueryParser parser(pIndexReader->getAnalyzerMapper(), m_searchRes.getDefaultField()); IndexSearcher searcher(pIndexReader); QueryHitsPtr pHits = searcher.search(state, parser); QueryResult result; if (pHits.isNotNull()) { FieldSelectClausePtr pFieldClause = state.getFieldSelectClause(); QueryClausePtr pQueryClause = state.getQueryClause(); if (pFieldClause.isNotNull() && pQueryClause.isNotNull()) { QueryPtr pQuery = parser.parse(pQueryClause->getQueryString()); FIRTEX_ASSERT2(pQuery.isNotNull()); FieldSelector selector(pIndexReader->getDocSchema()); for (size_t i = 0; i < pFieldClause->getFieldCount(); ++i) { const FieldSelectClause::SnippetParam& param = pFieldClause->getField(i); FieldFilterPtr pFieldFilter; if (param.snippet) { SnippetGenerator* pSnippetGen = new SnippetGenerator(); pFieldFilter.reset(pSnippetGen); if (!pSnippetGen->init(pQuery, parser.getAnalyzerMapper(), param.field, param.preTag, param.postTag, param.separator)) { FX_LOG(ERROR, "Init snippet generator for field: [%s] FAILED", param.field.c_str()); sendErrorMessage("Init snippet generator for field: " + param.field + " FAILED", pCtx); return; } } if (!selector.addField(param.field, pFieldFilter)) { FX_LOG(ERROR, "Invalid field: [%s]", param.field.c_str()); } } result.init(selector, pIndexReader, *pHits); } else { result.init(pIndexReader, *pHits); } } probe.stop(); result.setTimeCost(probe.elapsed() / 1000); FX_QUERY_TRACE(INFO, result.getTracer(), "search phase time [%d]", (int32_t)result.getTimeCost()); stringstream ss; XMLResultFormatter formatter; formatter.format(result, ss); sendResponse(ss.str(), pCtx); } catch(const FirteXException& e) { FX_LOG(ERROR, "Handle request FAILED: [%s], reason: [%s]", pCtx->getQuery().c_str(), e.what().c_str()); sendErrorMessage("Handle request failed", pCtx); } }