From 24bf99738240f4ab08b88672f8c9dc191aa5e340 Mon Sep 17 00:00:00 2001 From: rachytski Date: Thu, 12 Jul 2012 14:19:46 -0700 Subject: [PATCH] added consistent benchmarking for all RenderPolicies. --- android/jni/com/mapswithme/maps/Framework.cpp | 5 + android/jni/com/mapswithme/maps/Framework.hpp | 2 + .../com/mapswithme/maps/MWMApplication.cpp | 7 ++ .../maps/DownloadResourcesActivity.java | 35 +----- .../src/com/mapswithme/maps/MWMActivity.java | 6 + .../com/mapswithme/maps/MWMApplication.java | 26 +++++ iphone/Maps/Classes/Framework.cpp | 4 +- map/basic_render_policy.cpp | 10 ++ map/basic_render_policy.hpp | 4 + map/basic_tiling_render_policy.cpp | 9 ++ map/basic_tiling_render_policy.hpp | 4 + ...ark_framework.cpp => benchmark_engine.cpp} | 104 ++++++++---------- ...ark_framework.hpp => benchmark_engine.hpp} | 26 +++-- map/benchmark_render_policy_mt.cpp | 23 ---- map/benchmark_render_policy_mt.hpp | 11 -- map/benchmark_tiling_render_policy_mt.cpp | 18 --- map/benchmark_tiling_render_policy_mt.hpp | 12 -- map/coverage_generator.cpp | 43 +++++++- map/coverage_generator.hpp | 14 +++ map/framework.cpp | 18 ++- map/framework.hpp | 8 ++ map/framework_factory.cpp | 15 --- map/framework_factory.hpp | 12 -- map/map.pro | 16 +-- map/render_policy.cpp | 27 ++--- map/render_policy.hpp | 4 + map/render_queue.cpp | 10 ++ map/render_queue.hpp | 3 + map/render_queue_routine.cpp | 27 ++++- map/render_queue_routine.hpp | 8 ++ map/screen_coverage.cpp | 20 +++- qt/draw_widget.cpp | 3 +- 32 files changed, 302 insertions(+), 232 deletions(-) rename map/{benchmark_framework.cpp => benchmark_engine.cpp} (70%) rename map/{benchmark_framework.hpp => benchmark_engine.hpp} (66%) delete mode 100644 map/benchmark_render_policy_mt.cpp delete mode 100644 map/benchmark_render_policy_mt.hpp delete mode 100644 map/benchmark_tiling_render_policy_mt.cpp delete mode 100644 map/benchmark_tiling_render_policy_mt.hpp delete mode 100644 map/framework_factory.cpp delete mode 100644 map/framework_factory.hpp diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 1a1b339116..5a0664fd5d 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -492,4 +492,9 @@ namespace android { m_work.Scale(k); } + + bool Framework::IsBenchmarking() const + { + return m_work.IsBenchmarking(); + } } diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index c0af1b387d..81bdfba492 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -106,6 +106,8 @@ namespace android void AddString(string const & name, string const & value); void Scale(double k); + + bool IsBenchmarking() const; }; } diff --git a/android/jni/com/mapswithme/maps/MWMApplication.cpp b/android/jni/com/mapswithme/maps/MWMApplication.cpp index 1d79d0963a..a19a59e767 100644 --- a/android/jni/com/mapswithme/maps/MWMApplication.cpp +++ b/android/jni/com/mapswithme/maps/MWMApplication.cpp @@ -34,4 +34,11 @@ extern "C" if (!g_framework) g_framework = new android::Framework(); } + + JNIEXPORT jboolean JNICALL + Java_com_mapswithme_maps_MWMApplication_nativeIsBenchmarking(JNIEnv * env, + jobject thiz) + { + return static_cast(g_framework->IsBenchmarking()); + } } diff --git a/android/src/com/mapswithme/maps/DownloadResourcesActivity.java b/android/src/com/mapswithme/maps/DownloadResourcesActivity.java index 55cb3bc9e1..29949e8bf5 100644 --- a/android/src/com/mapswithme/maps/DownloadResourcesActivity.java +++ b/android/src/com/mapswithme/maps/DownloadResourcesActivity.java @@ -7,8 +7,6 @@ import android.app.ProgressDialog; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; -import android.os.PowerManager; -import android.os.PowerManager.WakeLock; import android.util.Log; import android.view.View; import android.widget.Button; @@ -51,33 +49,12 @@ public class DownloadResourcesActivity extends Activity implements LocationServi private LocationService mLocationService = null; private String mCountryName = null; - private WakeLock mWakeLock = null; - private int getBytesToDownload() { return getBytesToDownload(mApplication.getApkPath(), mApplication.getDataStoragePath()); } - private void disableAutomaticStandby() - { - if (mWakeLock == null) - { - PowerManager pm = (PowerManager) mApplication.getSystemService(android.content.Context.POWER_SERVICE); - mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); - mWakeLock.acquire(); - } - } - - private void enableAutomaticStandby() - { - if (mWakeLock != null) - { - mWakeLock.release(); - mWakeLock = null; - } - } - private void setDownloadMessage(int bytesToDownload) { Log.d(TAG, "prepareFilesDownload, bytesToDownload:" + bytesToDownload); @@ -109,14 +86,14 @@ public class DownloadResourcesActivity extends Activity implements LocationServi } else { - disableAutomaticStandby(); + mApplication.disableAutomaticStandby(); finishFilesDownload(mBytesToDownload); } } public void onDownloadClicked(View v) { - disableAutomaticStandby(); + mApplication.disableAutomaticStandby(); mProgress.setVisibility(View.VISIBLE); mProgress.setMax(mBytesToDownload); @@ -129,7 +106,7 @@ public class DownloadResourcesActivity extends Activity implements LocationServi public void onPauseClicked(View v) { - enableAutomaticStandby(); + mApplication.enableAutomaticStandby(); mResumeButton.setVisibility(View.VISIBLE); mPauseButton.setVisibility(View.GONE); @@ -139,7 +116,7 @@ public class DownloadResourcesActivity extends Activity implements LocationServi public void onResumeClicked(View v) { - disableAutomaticStandby(); + mApplication.disableAutomaticStandby(); mPauseButton.setVisibility(View.VISIBLE); mResumeButton.setVisibility(View.GONE); @@ -150,7 +127,7 @@ public class DownloadResourcesActivity extends Activity implements LocationServi public void onTryAgainClicked(View v) { - disableAutomaticStandby(); + mApplication.disableAutomaticStandby(); mProgress.setVisibility(View.VISIBLE); mTryAgainButton.setVisibility(View.GONE); @@ -197,7 +174,7 @@ public class DownloadResourcesActivity extends Activity implements LocationServi public void finishFilesDownload(int result) { - enableAutomaticStandby(); + mApplication.enableAutomaticStandby(); if (result == ERR_NO_MORE_FILES) { if (mCountryName != null && mDownloadCountryCheckBox.isChecked()) diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 2e192d6198..1b74b88172 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -375,6 +375,9 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService @Override protected void onPause() { + if (mApplication.nativeIsBenchmarking()) + mApplication.enableAutomaticStandby(); + getLocationService().stopUpdate(this); stopWatchingExternalStorage(); @@ -385,6 +388,9 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService @Override protected void onResume() { + if (mApplication.nativeIsBenchmarking()) + mApplication.disableAutomaticStandby(); + View button = findViewById(R.id.map_button_myposition); if (button.isSelected()) { diff --git a/android/src/com/mapswithme/maps/MWMApplication.java b/android/src/com/mapswithme/maps/MWMApplication.java index fa80e883ca..38b3b6abe8 100644 --- a/android/src/com/mapswithme/maps/MWMApplication.java +++ b/android/src/com/mapswithme/maps/MWMApplication.java @@ -10,6 +10,8 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; import android.os.Build; import android.os.Environment; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; import android.util.Log; import com.mapswithme.maps.location.LocationService; @@ -114,6 +116,28 @@ public class MWMApplication extends android.app.Application return getFilesDir().getAbsolutePath() + "/"; } + private WakeLock mWakeLock = null; + + public void disableAutomaticStandby() + { + if (mWakeLock == null) + { + PowerManager pm = (PowerManager) getSystemService(android.content.Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); + mWakeLock.acquire(); + } + } + + public void enableAutomaticStandby() + { + if (mWakeLock != null) + { + mWakeLock.release(); + mWakeLock = null; + } + } + + static { System.loadLibrary("mapswithme"); @@ -125,4 +149,6 @@ public class MWMApplication extends android.app.Application String extTmpPath, String settingsPath, boolean isPro); + + public native boolean nativeIsBenchmarking(); } diff --git a/iphone/Maps/Classes/Framework.cpp b/iphone/Maps/Classes/Framework.cpp index e763fd85e4..758b15d66a 100644 --- a/iphone/Maps/Classes/Framework.cpp +++ b/iphone/Maps/Classes/Framework.cpp @@ -1,13 +1,13 @@ #include "Framework.h" -#include "../../../map/framework_factory.hpp" +#include "../../../map/framework.hpp" static Framework * g_framework = 0; Framework & GetFramework() { if (g_framework == 0) - g_framework = FrameworkFactory::CreateFramework(); + g_framework = new Framework(); return *g_framework; } diff --git a/map/basic_render_policy.cpp b/map/basic_render_policy.cpp index 5cf38b05ad..042363ad76 100644 --- a/map/basic_render_policy.cpp +++ b/map/basic_render_policy.cpp @@ -153,3 +153,13 @@ bool BasicRenderPolicy::NeedRedraw() const return false; } + +int BasicRenderPolicy::InsertBenchmarkFence() +{ + return m_RenderQueue->InsertBenchmarkFence(); +} + +void BasicRenderPolicy::JoinBenchmarkFence(int fenceID) +{ + m_RenderQueue->JoinBenchmarkFence(fenceID); +} diff --git a/map/basic_render_policy.hpp b/map/basic_render_policy.hpp index 2981913005..b215307195 100644 --- a/map/basic_render_policy.hpp +++ b/map/basic_render_policy.hpp @@ -49,4 +49,8 @@ public: void SetCountryNameFn(TCountryNameFn countryNameFn); bool NeedRedraw() const; + + /// benchmarking protocol + int InsertBenchmarkFence(); + void JoinBenchmarkFence(int fenceID); }; diff --git a/map/basic_tiling_render_policy.cpp b/map/basic_tiling_render_policy.cpp index d506f31f96..bc092e5931 100644 --- a/map/basic_tiling_render_policy.cpp +++ b/map/basic_tiling_render_policy.cpp @@ -191,3 +191,12 @@ size_t BasicTilingRenderPolicy::TileSize() const return m_TileSize; } +int BasicTilingRenderPolicy::InsertBenchmarkFence() +{ + return m_CoverageGenerator->InsertBenchmarkFence(); +} + +void BasicTilingRenderPolicy::JoinBenchmarkFence(int fenceID) +{ + return m_CoverageGenerator->JoinBenchmarkFence(fenceID); +} diff --git a/map/basic_tiling_render_policy.hpp b/map/basic_tiling_render_policy.hpp index 52ddadfdbe..262285c2b0 100644 --- a/map/basic_tiling_render_policy.hpp +++ b/map/basic_tiling_render_policy.hpp @@ -66,4 +66,8 @@ public: int GetDrawScale(ScreenBase const & s) const; size_t ScaleEtalonSize() const; size_t TileSize() const; + + /// benchmarking protocol + int InsertBenchmarkFence(); + void JoinBenchmarkFence(int fenceID); }; diff --git a/map/benchmark_framework.cpp b/map/benchmark_engine.cpp similarity index 70% rename from map/benchmark_framework.cpp rename to map/benchmark_engine.cpp index cd15debe7f..968d2082ea 100644 --- a/map/benchmark_framework.cpp +++ b/map/benchmark_engine.cpp @@ -1,4 +1,4 @@ -#include "benchmark_framework.hpp" +#include "benchmark_engine.hpp" #include "benchmark_provider.hpp" #include "../platform/settings.hpp" @@ -123,35 +123,31 @@ struct MapsCollector } }; -void BenchmarkFramework::ReAddLocalMaps() +void BenchmarkEngine::PrepareMaps() { // remove all previously added maps in framework constructor Platform::FilesList files; - Framework::GetLocalMaps(files); + m_framework->GetLocalMaps(files); for_each(files.begin(), files.end(), - bind(&BenchmarkFramework::RemoveMap, this, _1)); + bind(&Framework::RemoveMap, m_framework, _1)); // add only maps needed for benchmarks MapsCollector collector; ForEachBenchmarkRecord(collector); for_each(collector.m_maps.begin(), collector.m_maps.end(), - bind(&BenchmarkFramework::AddMap, this, _1)); + bind(&Framework::AddMap, m_framework, _1)); } -BenchmarkFramework::BenchmarkFramework() +BenchmarkEngine::BenchmarkEngine(Framework * fw) : m_paintDuration(0), m_maxDuration(0), - m_isBenchmarkFinished(false), - m_isBenchmarkInitialized(false) + m_framework(fw) { - m_startTime = my::FormatCurrentTime(); - Framework::m_informationDisplay.enableBenchmarkInfo(true); - - ReAddLocalMaps(); + m_framework->GetInformationDisplay().enableBenchmarkInfo(true); } -void BenchmarkFramework::BenchmarkCommandFinished() +void BenchmarkEngine::BenchmarkCommandFinished() { double duration = m_paintDuration; @@ -159,7 +155,7 @@ void BenchmarkFramework::BenchmarkCommandFinished() { m_maxDuration = duration; m_maxDurationRect = m_curBenchmarkRect; - Framework::m_informationDisplay.addBenchmarkInfo("maxDurationRect: ", m_maxDurationRect, m_maxDuration); + m_framework->GetInformationDisplay().addBenchmarkInfo("maxDurationRect: ", m_maxDurationRect, m_maxDuration); } BenchmarkResult res; @@ -171,13 +167,10 @@ void BenchmarkFramework::BenchmarkCommandFinished() if (m_benchmarkResults.size() > 100) SaveBenchmarkResults(); - m_paintDuration = 0; - if (!m_isBenchmarkFinished) - NextBenchmarkCommand(); } -void BenchmarkFramework::SaveBenchmarkResults() +void BenchmarkEngine::SaveBenchmarkResults() { string resultsPath; Settings::Get("BenchmarkResults", resultsPath); @@ -200,7 +193,7 @@ void BenchmarkFramework::SaveBenchmarkResults() m_benchmarkResults.clear(); } -void BenchmarkFramework::SendBenchmarkResults() +void BenchmarkEngine::SendBenchmarkResults() { // ofstream fout(GetPlatform().WritablePathForFile("benchmarks/results.txt").c_str(), ios::app); // fout << "[COMPLETED]"; @@ -209,7 +202,7 @@ void BenchmarkFramework::SendBenchmarkResults() /// and delete results file } -void BenchmarkFramework::MarkBenchmarkResultsEnd() +void BenchmarkEngine::MarkBenchmarkResultsEnd() { string resultsPath; Settings::Get("BenchmarkResults", resultsPath); @@ -218,7 +211,7 @@ void BenchmarkFramework::MarkBenchmarkResultsEnd() fout << "END " << m_startTime << endl; } -void BenchmarkFramework::MarkBenchmarkResultsStart() +void BenchmarkEngine::MarkBenchmarkResultsStart() { string resultsPath; Settings::Get("BenchmarkResults", resultsPath); @@ -227,61 +220,50 @@ void BenchmarkFramework::MarkBenchmarkResultsStart() fout << "START " << m_startTime << endl; } -void BenchmarkFramework::NextBenchmarkCommand() +bool BenchmarkEngine::NextBenchmarkCommand() { if ((m_benchmarks[m_curBenchmark].m_provider->hasRect()) || (++m_curBenchmark < m_benchmarks.size())) { - Framework::m_navigator.SetFromRect(m2::AnyRectD(m_benchmarks[m_curBenchmark].m_provider->nextRect())); - m_curBenchmarkRect = Framework::m_navigator.Screen().GlobalRect().GetGlobalRect(); - Framework::Invalidate(); + double s = m_benchmarksTimer.ElapsedSeconds(); + + int fenceID = m_framework->GetRenderPolicy()->InsertBenchmarkFence(); + + m_framework->ShowRect(m_benchmarks[m_curBenchmark].m_provider->nextRect()); + m_curBenchmarkRect = m_framework->m_navigator.Screen().GlobalRect().GetGlobalRect(); + + m_framework->GetRenderPolicy()->JoinBenchmarkFence(fenceID); + + m_paintDuration += m_benchmarksTimer.ElapsedSeconds() - s; + BenchmarkCommandFinished(); + + return true; } else { - static bool isFirstTime = true; - if (isFirstTime) - { - m_isBenchmarkFinished = true; - isFirstTime = false; - SaveBenchmarkResults(); - MarkBenchmarkResultsEnd(); - SendBenchmarkResults(); - LOG(LINFO, ("Bechmarks took ", m_benchmarksTimer.ElapsedSeconds(), " seconds to complete")); - } + SaveBenchmarkResults(); + MarkBenchmarkResultsEnd(); + SendBenchmarkResults(); + LOG(LINFO, ("Bechmarks took ", m_benchmarksTimer.ElapsedSeconds(), " seconds to complete")); + return false; } } -void BenchmarkFramework::InitBenchmark() +void BenchmarkEngine::Start() { - DoGetBenchmarks doGet(m_benchmarks, Framework::m_navigator); + m_thread.Create(this); +} + +void BenchmarkEngine::Do() +{ + PrepareMaps(); + + DoGetBenchmarks doGet(m_benchmarks, m_framework->m_navigator); ForEachBenchmarkRecord(doGet); m_curBenchmark = 0; - //base_type::m_renderPolicy->addAfterFrame(bind(&this_type::BenchmarkCommandFinished, this)); - m_benchmarksTimer.Reset(); MarkBenchmarkResultsStart(); - NextBenchmarkCommand(); - - Framework::Invalidate(); -} - -void BenchmarkFramework::OnSize(int w, int h) -{ - Framework::OnSize(w, h); - if (!m_isBenchmarkInitialized) - { - m_isBenchmarkInitialized = true; - InitBenchmark(); - } -} - -void BenchmarkFramework::DoPaint(shared_ptr const & e) -{ - double s = m_benchmarksTimer.ElapsedSeconds(); - Framework::DoPaint(e); - m_paintDuration += m_benchmarksTimer.ElapsedSeconds() - s; - if (!m_isBenchmarkFinished) - BenchmarkCommandFinished(); + while (NextBenchmarkCommand()){}; } diff --git a/map/benchmark_framework.hpp b/map/benchmark_engine.hpp similarity index 66% rename from map/benchmark_framework.hpp rename to map/benchmark_engine.hpp index 6f2ef828e3..28d8a22378 100644 --- a/map/benchmark_framework.hpp +++ b/map/benchmark_engine.hpp @@ -5,6 +5,7 @@ #include "../geometry/rect2d.hpp" #include "../base/timer.hpp" +#include "../base/thread.hpp" #include "../std/string.hpp" #include "../std/vector.hpp" @@ -14,10 +15,17 @@ struct BenchmarkRectProvider; class WindowHandle; class PaintEvent; -class BenchmarkFramework : public Framework +/// BenchmarkEngine is class which: +/// - Creates it's own thread +/// - Feeds the Framework with the paint tasks he wants to performs +/// - Wait until each tasks completion +/// - Measure the time of each task and save the result +class BenchmarkEngine : public threads::IRoutine { private: + threads::Thread m_thread; + double m_paintDuration; double m_maxDuration; m2::RectD m_maxDurationRect; @@ -44,27 +52,23 @@ private: vector m_benchmarks; size_t m_curBenchmark; - bool m_isBenchmarkFinished; - bool m_isBenchmarkInitialized; + Framework * m_framework; void BenchmarkCommandFinished(); - void NextBenchmarkCommand(); + bool NextBenchmarkCommand(); void SaveBenchmarkResults(); void SendBenchmarkResults(); void MarkBenchmarkResultsStart(); void MarkBenchmarkResultsEnd(); - void InitBenchmark(); + void PrepareMaps(); - /// Removes all maps added in base class and adds only benchmarking maps - void ReAddLocalMaps(); + void Do(); public: - BenchmarkFramework(); + BenchmarkEngine(Framework * fw); - void OnSize(int w, int h); - - virtual void DoPaint(shared_ptr const & e); + void Start(); }; diff --git a/map/benchmark_render_policy_mt.cpp b/map/benchmark_render_policy_mt.cpp deleted file mode 100644 index f2a9e88bfe..0000000000 --- a/map/benchmark_render_policy_mt.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "../base/SRC_FIRST.hpp" - -#include "benchmark_render_policy_mt.hpp" - -#include "render_queue.hpp" - -#include "../base/logging.hpp" - -BenchmarkRenderPolicyMT::BenchmarkRenderPolicyMT(Params const & p) - : RenderPolicyMT(p) -{} - -void BenchmarkRenderPolicyMT::DrawFrame(shared_ptr const & e, - ScreenBase const & s) -{ - RenderPolicyMT::DrawFrame(e, s); - RenderPolicyMT::EndFrame(e, s); - GetRenderQueue().WaitForEmptyAndFinished(); - RenderPolicyMT::BeginFrame(e, s); - RenderPolicyMT::DrawFrame(e, s); -} - - diff --git a/map/benchmark_render_policy_mt.hpp b/map/benchmark_render_policy_mt.hpp deleted file mode 100644 index adc937b1a6..0000000000 --- a/map/benchmark_render_policy_mt.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "render_policy_mt.hpp" - -class BenchmarkRenderPolicyMT : public RenderPolicyMT -{ -public: - BenchmarkRenderPolicyMT(Params const & p); - - void DrawFrame(shared_ptr const & e, ScreenBase const & s); -}; diff --git a/map/benchmark_tiling_render_policy_mt.cpp b/map/benchmark_tiling_render_policy_mt.cpp deleted file mode 100644 index 467de4a9ac..0000000000 --- a/map/benchmark_tiling_render_policy_mt.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "../base/SRC_FIRST.hpp" -#include "benchmark_tiling_render_policy_mt.hpp" -#include "tile_renderer.hpp" - -BenchmarkTilingRenderPolicyMT::BenchmarkTilingRenderPolicyMT(Params const & p) - : TilingRenderPolicyMT(p) -{} - -void BenchmarkTilingRenderPolicyMT::DrawFrame(shared_ptr const & e, - ScreenBase const & s) -{ - TilingRenderPolicyMT::DrawFrame(e, s); - /// waiting for render queue to empty - GetTileRenderer().WaitForEmptyAndFinished(); - /// current screen should be fully covered, so the following call will only blit results - TilingRenderPolicyMT::DrawFrame(e, s); -} - diff --git a/map/benchmark_tiling_render_policy_mt.hpp b/map/benchmark_tiling_render_policy_mt.hpp deleted file mode 100644 index c22cbb1792..0000000000 --- a/map/benchmark_tiling_render_policy_mt.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "tiling_render_policy_mt.hpp" - -class BenchmarkTilingRenderPolicyMT : public TilingRenderPolicyMT -{ -public: - - BenchmarkTilingRenderPolicyMT(Params const & p); - - void DrawFrame(shared_ptr const & e, ScreenBase const & s); -}; diff --git a/map/coverage_generator.cpp b/map/coverage_generator.cpp index f35e837033..02f581e4bd 100644 --- a/map/coverage_generator.cpp +++ b/map/coverage_generator.cpp @@ -28,7 +28,9 @@ CoverageGenerator::CoverageGenerator( m_windowHandle(windowHandle), m_countryNameFn(countryNameFn), m_glQueue(glQueue), - m_skinName(skinName) + m_skinName(skinName), + m_fenceManager(2), + m_currentFenceID(-1) { g_coverageGeneratorDestroyed = false; @@ -127,12 +129,13 @@ void CoverageGenerator::InvalidateTilesImpl(m2::AnyRectD const & r, int startSca void CoverageGenerator::InvalidateTiles(m2::AnyRectD const & r, int startScale) { - /// this automatically will skip the previous CoverScreen commands - /// and MergeTiles commands from previously generated ScreenCoverages if (m_sequenceID == numeric_limits::max()) return; + /// this automatically will skip the previous CoverScreen commands + /// and MergeTiles commands from previously generated ScreenCoverages ++m_sequenceID; + m_queue.AddCommand(bind(&CoverageGenerator::InvalidateTilesImpl, this, r, startScale)); } @@ -147,9 +150,27 @@ void CoverageGenerator::AddCoverScreenTask(ScreenBase const & screen, bool doFor m_currentScreen = screen; ++m_sequenceID; + m_queue.AddCommand(bind(&CoverageGenerator::CoverScreen, this, screen, m_sequenceID)); } +int CoverageGenerator::InsertBenchmarkFence() +{ + m_currentFenceID = m_fenceManager.insertFence(); + return m_currentFenceID; +} + +void CoverageGenerator::JoinBenchmarkFence(int fenceID) +{ + CHECK(fenceID == m_currentFenceID, ("InsertBenchmarkFence without corresponding SignalBenchmarkFence detected")); + m_fenceManager.joinFence(fenceID); +} + +void CoverageGenerator::SignalBenchmarkFence() +{ + m_fenceManager.signalFence(m_currentFenceID); +} + void CoverageGenerator::CoverScreen(ScreenBase const & screen, int sequenceID) { if (sequenceID < m_sequenceID) @@ -232,6 +253,22 @@ void CoverageGenerator::CheckEmptyModel(int sequenceID) m_windowHandle->invalidate(); } +void CoverageGenerator::AddFinishSequenceTask(int sequenceID) +{ + m_queue.AddCommand(bind(&CoverageGenerator::FinishSequence, this, sequenceID)); +} + +void CoverageGenerator::FinishSequence(int sequenceID) +{ +/* if (sequenceID < m_sequenceID) + { + LOG(LINFO, ("sequence", sequenceID, "was cancelled")); + return; + }*/ + + SignalBenchmarkFence(); +} + void CoverageGenerator::WaitForEmptyAndFinished() { m_queue.Join(); diff --git a/map/coverage_generator.hpp b/map/coverage_generator.hpp index 829c434a8e..4b938f93f7 100644 --- a/map/coverage_generator.hpp +++ b/map/coverage_generator.hpp @@ -32,6 +32,11 @@ namespace yg class ResourceStyleCache; } +/// Control class for TilingRenderPolicy. It processes request from the RenderPolicy +/// to draw a specific ScreenBase by splitting it in tiles that is not rendered now and +/// feeding them into TileRenderer. Each command to render a tile is enqueued with +/// a small command, which is feeding the CoverageGenerator with the command to process +/// newly rendered tile(p.e. merge it into current ScreenCoverage). class CoverageGenerator { private: @@ -58,6 +63,9 @@ private: yg::gl::PacketsQueue * m_glQueue; string m_skinName; + FenceManager m_fenceManager; + int m_currentFenceID; + ScreenCoverage * CreateCoverage(); public: @@ -83,10 +91,12 @@ public: int sequenceID); void AddCheckEmptyModelTask(int sequenceID); + void AddFinishSequenceTask(int sequenceID); void CoverScreen(ScreenBase const & screen, int sequenceID); void MergeTile(Tiler::RectInfo const & rectInfo, int sequenceID); void CheckEmptyModel(int sequenceID); + void FinishSequence(int sequenceID); void Cancel(); @@ -96,6 +106,10 @@ public: ScreenCoverage & CurrentCoverage(); + int InsertBenchmarkFence(); + void JoinBenchmarkFence(int fenceID); + void SignalBenchmarkFence(); + void SetSequenceID(int sequenceID); threads::Mutex & Mutex(); diff --git a/map/framework.cpp b/map/framework.cpp index 1da28321f2..dba8958b61 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2,6 +2,7 @@ #include "draw_processor.hpp" #include "drawer_yg.hpp" #include "benchmark_provider.hpp" +#include "benchmark_engine.hpp" #include "geourl_process.hpp" #include "../defines.hpp" @@ -160,8 +161,15 @@ Framework::Framework() m_height(0), m_centeringMode(EDoNothing), m_informationDisplay(&m_storage), - m_lowestMapVersion(-1) + m_lowestMapVersion(-1), + m_benchmarkEngine(0) { + // checking whether we should enable benchmark + bool isBenchmarkingEnabled = false; + (void)Settings::Get("IsBenchmarking", isBenchmarkingEnabled); + if (isBenchmarkingEnabled) + m_benchmarkEngine = new BenchmarkEngine(this); + // Init strings bundle. m_stringsBundle.SetDefaultString("country_status_added_to_queue", "^is added to the\ndownloading queue."); m_stringsBundle.SetDefaultString("country_status_downloading", "Downloading^(^%)"); @@ -1036,6 +1044,9 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy) // Do full invalidate instead of any "pending" stuff. Invalidate(); + if (m_benchmarkEngine) + m_benchmarkEngine->Start(); + /* if (m_hasPendingInvalidate) { @@ -1120,3 +1131,8 @@ bool Framework::SetViewportByURL(string const & url) return false; } + +bool Framework::IsBenchmarking() const +{ + return m_benchmarkEngine != 0; +} diff --git a/map/framework.hpp b/map/framework.hpp index 00386421d7..76fb24cdf4 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -39,10 +39,14 @@ namespace search { class Result; } namespace gui { class Controller; } class CountryStatusDisplay; +class BenchmarkEngine; class Framework { protected: + + friend class BenchmarkEngine; + StringsBundle m_stringsBundle; mutable scoped_ptr m_pSearchEngine; @@ -105,6 +109,8 @@ protected: void DrawAdditionalInfo(shared_ptr const & e); + BenchmarkEngine * m_benchmarkEngine; + public: Framework(); virtual ~Framework(); @@ -324,6 +330,8 @@ public: m_stringsBundle.SetString(name, value); } + bool IsBenchmarking() const; + private: bool IsCountryLoaded(m2::PointD const & pt) const; }; diff --git a/map/framework_factory.cpp b/map/framework_factory.cpp deleted file mode 100644 index 8021748853..0000000000 --- a/map/framework_factory.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "framework_factory.hpp" -#include "benchmark_framework.hpp" - -#include "../platform/settings.hpp" - -Framework * FrameworkFactory::CreateFramework() -{ - bool benchmarkingEnabled = false; - (void)Settings::Get("IsBenchmarking", benchmarkingEnabled); - - if (benchmarkingEnabled) - return new BenchmarkFramework(); - else - return new Framework(); -} diff --git a/map/framework_factory.hpp b/map/framework_factory.hpp deleted file mode 100644 index 34683cccf4..0000000000 --- a/map/framework_factory.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "framework.hpp" -#include "../std/shared_ptr.hpp" - -class WindowHandle; - -class FrameworkFactory -{ -public: - static Framework * CreateFramework(); -}; diff --git a/map/map.pro b/map/map.pro index 35bb865f98..eafe3cfbe1 100644 --- a/map/map.pro +++ b/map/map.pro @@ -26,9 +26,7 @@ HEADERS += \ render_policy.hpp \ tiling_render_policy_mt.hpp \ tiling_render_policy_st.hpp \ - benchmark_tiling_render_policy_mt.hpp \ - benchmark_framework.hpp \ - framework_factory.hpp \ + benchmark_engine.hpp \ render_policy_st.hpp \ coverage_generator.hpp \ tiler.hpp \ @@ -38,7 +36,6 @@ HEADERS += \ basic_render_policy.hpp \ render_queue.hpp \ render_queue_routine.hpp \ - benchmark_render_policy_mt.hpp \ ruler.hpp \ measurement_utils.hpp \ simple_render_policy.hpp \ @@ -63,11 +60,9 @@ SOURCES += \ location_state.cpp \ benchmark_provider.cpp \ render_policy.cpp \ - benchmark_tiling_render_policy_mt.cpp \ tiling_render_policy_st.cpp \ tiling_render_policy_mt.cpp \ - benchmark_framework.cpp \ - framework_factory.cpp \ + benchmark_engine.cpp \ render_policy_st.cpp \ coverage_generator.cpp \ tiler.cpp \ @@ -77,7 +72,6 @@ SOURCES += \ basic_render_policy.cpp \ render_queue_routine.cpp \ render_queue.cpp \ - benchmark_render_policy_mt.cpp \ ruler.cpp \ measurement_utils.cpp \ window_handle.cpp \ @@ -99,3 +93,9 @@ SOURCES += \ SOURCES += qgl_render_context.cpp QT += opengl } + + + + + + diff --git a/map/render_policy.cpp b/map/render_policy.cpp index 7217072718..49f308ad1c 100644 --- a/map/render_policy.cpp +++ b/map/render_policy.cpp @@ -12,8 +12,6 @@ #include "render_policy_mt.hpp" #include "tiling_render_policy_st.hpp" #include "tiling_render_policy_mt.hpp" -#include "benchmark_render_policy_mt.hpp" -#include "benchmark_tiling_render_policy_mt.hpp" #include "../yg/internal/opengl.hpp" @@ -201,23 +199,17 @@ string const & RenderPolicy::SkinName() const return m_skinName; } +int RenderPolicy::InsertBenchmarkFence() +{ + return 0; +} + +void RenderPolicy::JoinBenchmarkFence(int fenceID) +{ +} + RenderPolicy * CreateRenderPolicy(RenderPolicy::Params const & params) { - bool benchmarkingEnabled = false; - Settings::Get("IsBenchmarking", benchmarkingEnabled); - - if (benchmarkingEnabled) - { - bool isBenchmarkingMT = false; - Settings::Get("IsBenchmarkingMT", isBenchmarkingMT); - - if (isBenchmarkingMT) - return new BenchmarkTilingRenderPolicyMT(params); - else - return new BenchmarkRenderPolicyMT(params); - } - else - { #ifdef OMIM_OS_ANDROID return new TilingRenderPolicyST(params); #endif @@ -227,5 +219,4 @@ RenderPolicy * CreateRenderPolicy(RenderPolicy::Params const & params) #ifdef OMIM_OS_DESKTOP return new TilingRenderPolicyST(params); #endif - } } diff --git a/map/render_policy.hpp b/map/render_policy.hpp index 6acadd93d2..7d1e25fd0c 100644 --- a/map/render_policy.hpp +++ b/map/render_policy.hpp @@ -124,6 +124,10 @@ public: double VisualScale() const; string const & SkinName() const; + + /// Benchmarking protocol + virtual int InsertBenchmarkFence(); + virtual void JoinBenchmarkFence(int fenceID); }; RenderPolicy * CreateRenderPolicy(RenderPolicy::Params const & params); diff --git a/map/render_queue.cpp b/map/render_queue.cpp index ac40ac6acc..af8b5e4e0b 100644 --- a/map/render_queue.cpp +++ b/map/render_queue.cpp @@ -135,3 +135,13 @@ void RenderQueue::SetGLQueue(yg::gl::PacketsQueue * glQueue) m_routine->setGLQueue(glQueue); } +int RenderQueue::InsertBenchmarkFence() +{ + return m_routine->insertBenchmarkFence(); +} + +void RenderQueue::JoinBenchmarkFence(int id) +{ + return m_routine->joinBenchmarkFence(id); +} + diff --git a/map/render_queue.hpp b/map/render_queue.hpp index 8f86400cb8..c227f804cb 100644 --- a/map/render_queue.hpp +++ b/map/render_queue.hpp @@ -80,4 +80,7 @@ public: void WaitForEmptyAndFinished(); void SetGLQueue(yg::gl::PacketsQueue * glQueue); + + int InsertBenchmarkFence(); + void JoinBenchmarkFence(int id); }; diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index f7248e40f5..c9e47b9f6d 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -23,9 +23,9 @@ #include "window_handle.hpp" #include "render_queue_routine.hpp" RenderQueueRoutine::RenderModelCommand::RenderModelCommand(ScreenBase const & frameScreen, - render_fn_t renderFn) - : m_frameScreen(frameScreen), - m_renderFn(renderFn) + render_fn_t renderFn) + : m_frameScreen(frameScreen), + m_renderFn(renderFn) {} RenderQueueRoutine::RenderQueueRoutine(shared_ptr const & renderState, @@ -37,6 +37,7 @@ RenderQueueRoutine::RenderQueueRoutine(shared_ptr const & r unsigned scaleEtalonSize, double visualScale, yg::Color const & bgColor) + : m_fenceManager(2) { m_skinName = skinName; m_visualScale = visualScale; @@ -49,6 +50,7 @@ RenderQueueRoutine::RenderQueueRoutine(shared_ptr const & r m_scaleEtalonSize = scaleEtalonSize; m_bgColor = bgColor; m_glQueue = 0; + m_currentFenceID = -1; } void RenderQueueRoutine::Cancel() @@ -506,6 +508,8 @@ void RenderQueueRoutine::Do() } invalidate(); + + signalBenchmarkFence(); } } @@ -610,3 +614,20 @@ void RenderQueueRoutine::setGLQueue(yg::gl::PacketsQueue * glQueue) { m_glQueue = glQueue; } + +int RenderQueueRoutine::insertBenchmarkFence() +{ + m_currentFenceID = m_fenceManager.insertFence(); + return m_currentFenceID; +} + +void RenderQueueRoutine::joinBenchmarkFence(int id) +{ + CHECK(m_currentFenceID == id, ()); + m_fenceManager.joinFence(id); +} + +void RenderQueueRoutine::signalBenchmarkFence() +{ + m_fenceManager.signalFence(m_currentFenceID); +} diff --git a/map/render_queue_routine.hpp b/map/render_queue_routine.hpp index f7bed8c2ff..31d97cd9e0 100644 --- a/map/render_queue_routine.hpp +++ b/map/render_queue_routine.hpp @@ -3,6 +3,7 @@ #include "../base/thread.hpp" #include "../base/condition.hpp" #include "../base/commands_queue.hpp" +#include "../base/fence_manager.hpp" #include "../geometry/rect2d.hpp" #include "../geometry/screenbase.hpp" #include "../std/list.hpp" @@ -84,6 +85,9 @@ private: /// A list of window handles to notify about ending rendering operations. list > m_windowHandles; + FenceManager m_fenceManager; + int m_currentFenceID; + bool m_isMultiSampled; bool m_doPeriodicalUpdate; double m_updateInterval; @@ -145,4 +149,8 @@ public: /// wait for all commands are processed. void waitForEmptyAndFinished(); void setGLQueue(yg::gl::PacketsQueue * glQueue); + + int insertBenchmarkFence(); + void signalBenchmarkFence(); + void joinBenchmarkFence(int id); }; diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp index 936308ec66..9944d7536c 100644 --- a/map/screen_coverage.cpp +++ b/map/screen_coverage.cpp @@ -283,7 +283,9 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) vector firstClassTiles; vector secondClassTiles; - for (unsigned i = 0; i < newRects.size(); ++i) + unsigned newRectsCount = newRects.size(); + + for (unsigned i = 0; i < newRectsCount; ++i) { Tiler::RectInfo nr = newRects[i]; @@ -319,8 +321,10 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) // filtering out rects that are fully covered by its descedants + int curNewTile = 0; + // adding commands for tiles which aren't in cache - for (size_t i = 0; i < firstClassTiles.size(); ++i) + for (size_t i = 0; i < firstClassTiles.size(); ++i, ++curNewTile) { Tiler::RectInfo const & ri = firstClassTiles[i]; @@ -331,6 +335,11 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) ri, GetSequenceID())); + if (curNewTile == newRectsCount - 1) + chain.addCommand(bind(&CoverageGenerator::AddFinishSequenceTask, + m_coverageGenerator, + GetSequenceID())); + m_tileRenderer->AddCommand(ri, GetSequenceID(), chain); @@ -340,7 +349,7 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) m_newTileRects.insert(ri); } - for (size_t i = 0; i < secondClassTiles.size(); ++i) + for (size_t i = 0; i < secondClassTiles.size(); ++i, ++curNewTile) { Tiler::RectInfo const & ri = secondClassTiles[i]; @@ -350,6 +359,11 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) m_tileRenderer, ri)); + if (curNewTile == newRectsCount - 1) + chain.addCommand(bind(&CoverageGenerator::AddFinishSequenceTask, + m_coverageGenerator, + GetSequenceID())); + m_tileRenderer->AddCommand(ri, GetSequenceID(), chain); } } diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 853c6f57a7..0695a5288c 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -2,7 +2,6 @@ #include "proxystyle.hpp" #include "slider_ctrl.hpp" -#include "../map/framework_factory.hpp" #include "../map/render_policy.hpp" #include "../gui/controller.hpp" @@ -55,7 +54,7 @@ namespace qt : QGLWidget(pParent), m_isInitialized(false), m_isTimerStarted(false), - m_framework(FrameworkFactory::CreateFramework()), + m_framework(new Framework()), m_isDrag(false), m_isRotate(false), //m_redrawInterval(100),