Chromium Code Reviews| Index: chrome/test/perf/generate_profile.cc |
| diff --git a/chrome/tools/profiles/generate_profile.cc b/chrome/test/perf/generate_profile.cc |
| similarity index 76% |
| rename from chrome/tools/profiles/generate_profile.cc |
| rename to chrome/test/perf/generate_profile.cc |
| index fbd761eed7db0f2a3ea836de9016fbd78f6ecbac..248908bb28c4a0e9b2b793589a811a1def46515e 100644 |
| --- a/chrome/tools/profiles/generate_profile.cc |
| +++ b/chrome/test/perf/generate_profile.cc |
| @@ -2,10 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -// This program generates a user profile and history by randomly generating |
| -// data and feeding it to the history service. |
| - |
| -#include "chrome/tools/profiles/thumbnail-inl.h" |
| +#include "chrome/test/perf/generate_profile.h" |
| #include "base/at_exit.h" |
| #include "base/command_line.h" |
| @@ -26,27 +23,19 @@ |
| #include "chrome/common/thumbnail_score.h" |
| #include "chrome/test/base/testing_browser_process.h" |
| #include "chrome/test/base/testing_profile.h" |
| -#include "content/browser/browser_thread_impl.h" |
| +#include "chrome/tools/profiles/thumbnail-inl.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_service.h" |
| +#include "content/public/test/test_browser_thread.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/ui_base_paths.h" |
| #include "ui/gfx/codec/jpeg_codec.h" |
| -#if defined(TOOLKIT_GTK) |
| -#include <gtk/gtk.h> |
| -#endif |
| - |
| using base::Time; |
| using content::BrowserThread; |
| -// Addition types data can be generated for. By default only urls/visits are |
| -// added. |
| -enum Types { |
| - TOP_SITES = 1 << 0, |
| - FULL_TEXT = 1 << 1 |
| -}; |
| +namespace { |
| // RAII for initializing and shutting down the TestBrowserProcess |
| class InitBrowserProcess { |
| @@ -71,12 +60,12 @@ const float kWordLengthProbabilities[] = { 0.069f, 0.132f, 0.199f, |
| // Return a float uniformly in [0,1]. |
| // Useful for making probabilistic decisions. |
| -float RandomFloat() { |
| +inline float RandomFloat() { |
|
Paweł Hajdan Jr.
2013/04/26 23:19:32
nit: Is this "inline" needed? Why? Same below.
Ju
Elliot Glaysher
2013/04/29 21:41:35
This isn't needed...in Release builds. At -O2, gcc
|
| return rand() / static_cast<float>(RAND_MAX); |
| } |
| // Return an integer uniformly in [min,max). |
| -int RandomInt(int min, int max) { |
| +inline int RandomInt(int min, int max) { |
| return min + (rand() % (max-min)); |
| } |
| @@ -154,10 +143,12 @@ void InsertURLBatch(Profile* profile, |
| // Scoping value for page IDs (required by the history service). |
| void* id_scope = reinterpret_cast<void*>(1); |
| - scoped_ptr<SkBitmap> google_bitmap( |
| - gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); |
| - scoped_ptr<SkBitmap> weewar_bitmap( |
| - gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); |
| + scoped_refptr<base::RefCountedMemory> google_bitmap( |
| + new base::RefCountedStaticMemory(kGoogleThumbnail, |
| + sizeof(kGoogleThumbnail))); |
| + scoped_refptr<base::RefCountedMemory> weewar_bitmap( |
| + new base::RefCountedStaticMemory(kWeewarThumbnail, |
| + sizeof(kWeewarThumbnail))); |
| printf("Inserting %d URLs...\n", batch_size); |
| GURL previous_url; |
| @@ -203,10 +194,10 @@ void InsertURLBatch(Profile* profile, |
| if (types & FULL_TEXT) |
| history_service->SetPageContents(url, ConstructRandomPage()); |
| if (types & TOP_SITES && top_sites) { |
| - const SkBitmap& bitmap = (RandomInt(0, 2) == 0) ? *google_bitmap : |
| - *weewar_bitmap; |
| - gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap); |
| - top_sites->SetPageThumbnail(url, image, score); |
| + top_sites->SetPageThumbnailToJPEGBytes( |
| + url, |
| + (RandomInt(0, 2) == 0) ? google_bitmap.get() : weewar_bitmap.get(), |
| + score); |
| } |
| previous_url = url; |
| @@ -216,53 +207,25 @@ void InsertURLBatch(Profile* profile, |
| } |
| } |
| -int main(int argc, char* argv[]) { |
| - CommandLine::Init(argc, argv); |
| - base::EnableTerminationOnHeapCorruption(); |
| +} // namespace |
| + |
| +bool GenerateProfile(GenerateProfileTypes types, |
| + int url_count, |
| + const base::FilePath& dst_dir) { |
| base::AtExitManager exit_manager; |
|
Paweł Hajdan Jr.
2013/04/26 23:19:32
This probably shouldn't be here now that it's not
|
| - CommandLine* cl = CommandLine::ForCurrentProcess(); |
| - |
| - int types = 0; |
| - if (cl->HasSwitch("top-sites")) |
| - types |= TOP_SITES; |
| - if (cl->HasSwitch("full-text")) |
| - types |= FULL_TEXT; |
| - |
| - // We require two arguments: urlcount and profiledir. |
| - const CommandLine::StringVector& args = cl->GetArgs(); |
| - if (args.size() < 2) { |
| - printf("usage: %s [--top-sites] [--full-text] <urlcount> " |
| - "<profiledir>\n", argv[0]); |
| - printf("\n --top-sites Generate thumbnails\n"); |
| - printf("\n --full-text Generate full text index\n"); |
| - return -1; |
| - } |
| - int url_count = 0; |
| - base::StringToInt(args[0], &url_count); |
| - base::FilePath dst_dir(args[1]); |
| - if (!dst_dir.IsAbsolute()) { |
| - base::FilePath current_dir; |
| - file_util::GetCurrentDirectory(¤t_dir); |
| - dst_dir = current_dir.Append(dst_dir); |
| - } |
| if (!file_util::CreateDirectory(dst_dir)) { |
| PLOG(ERROR) << "Unable to create directory " << dst_dir.value().c_str(); |
|
Paweł Hajdan Jr.
2013/04/26 23:19:32
return false
|
| } |
| - icu_util::Initialize(); |
| - // Copied from base/test/test_suite.cc. |
| -#if defined(TOOLKIT_GTK) |
| - gtk_init_check(&argc, &argv); |
| -#endif |
| + // We want this profile to be as deterministic as possible, so seed the |
| + // random number generator with the number of urls we're generating. |
| + srand(static_cast<unsigned int>(url_count)); |
| InitBrowserProcess initialize_browser_process; |
| - chrome::RegisterPathProvider(); |
| - ui::RegisterPathProvider(); |
| MessageLoopForUI message_loop; |
| - content::BrowserThreadImpl ui_thread(BrowserThread::UI, &message_loop); |
| - content::BrowserThreadImpl db_thread(BrowserThread::DB, &message_loop); |
| - ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
| + content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| + content::TestBrowserThread db_thread(BrowserThread::DB, &message_loop); |
| TestingProfile profile; |
| profile.CreateHistoryService(false, false); |
| if (types & TOP_SITES) { |
| @@ -270,8 +233,6 @@ int main(int argc, char* argv[]) { |
| profile.BlockUntilTopSitesLoaded(); |
| } |
| - srand(static_cast<unsigned int>(Time::Now().ToInternalValue())); |
| - |
| // The maximum number of URLs to insert into history in one batch. |
| const int kBatchSize = 2000; |
| int page_id = 0; |
| @@ -296,15 +257,15 @@ int main(int argc, char* argv[]) { |
| while (!path.empty()) { |
| base::FilePath dst_file = dst_dir.Append(path.BaseName()); |
| file_util::Delete(dst_file, false); |
| - printf("Copying file %" PRFilePath " to " |
| - "%" PRFilePath "\n", path.value().c_str(), |
| - dst_file.value().c_str()); |
| if (!file_util::CopyFile(path, dst_file)) { |
| PLOG(ERROR) << "Copying file failed"; |
| - return -1; |
| + return false; |
| } |
| path = file_iterator.Next(); |
| } |
| - return 0; |
| + // Restore the random seed. |
| + srand(static_cast<unsigned int>(Time::Now().ToInternalValue())); |
| + |
| + return true; |
| } |