Bug 1059479 - remove Chromium path service and trace events code. r=bent

This commit is contained in:
Josh Aas 2014-09-02 14:23:58 -05:00
Родитель a98032818a
Коммит 85d03dd759
14 изменённых файлов: 0 добавлений и 1033 удалений

Просмотреть файл

@ -37,7 +37,6 @@ else:
UNIFIED_SOURCES += [
'src/base/at_exit.cc',
'src/base/base_paths.cc',
'src/base/base_switches.cc',
'src/base/command_line.cc',
'src/base/debug_util.cc',
@ -51,7 +50,6 @@ UNIFIED_SOURCES += [
'src/base/message_loop.cc',
'src/base/message_pump_default.cc',
'src/base/non_thread_safe.cc',
'src/base/path_service.cc',
'src/base/pickle.cc',
'src/base/rand_util.cc',
'src/base/ref_counted.cc',
@ -66,7 +64,6 @@ UNIFIED_SOURCES += [
'src/base/thread_collision_warner.cc',
'src/base/time.cc',
'src/base/timer.cc',
'src/base/trace_event.cc',
'src/base/tracked.cc',
'src/base/tracked_objects.cc',
'src/chrome/common/child_process.cc',
@ -88,7 +85,6 @@ UNIFIED_SOURCES += [
if os_win:
SOURCES += [
'src/base/base_paths_win.cc',
'src/base/condition_variable_win.cc',
'src/base/cpu.cc',
'src/base/debug_util_win.cc',
@ -191,7 +187,6 @@ if os_macosx:
'src/chrome/common/transport_dib_mac.cc',
]
SOURCES += [
'src/base/base_paths_mac.mm',
'src/base/chrome_application_mac.mm',
'src/base/file_util_mac.mm',
'src/base/mac_util.mm',
@ -212,7 +207,6 @@ if os_macosx:
if os_linux:
SOURCES += [
'src/base/atomicops_internals_x86_gcc.cc',
'src/base/base_paths_linux.cc',
'src/base/idle_timer_none.cc',
'src/base/process_util_linux.cc',
'src/base/time_posix.cc',

Просмотреть файл

@ -1,38 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_paths.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
namespace base {
bool PathProvider(int key, FilePath* result) {
// NOTE: DIR_CURRENT is a special cased in PathService::Get
FilePath cur;
switch (key) {
case base::DIR_EXE:
PathService::Get(base::FILE_EXE, &cur);
cur = cur.DirName();
break;
case base::DIR_MODULE:
PathService::Get(base::FILE_MODULE, &cur);
cur = cur.DirName();
break;
case base::DIR_TEMP:
if (!file_util::GetTempDir(&cur))
return false;
break;
default:
return false;
}
*result = cur;
return true;
}
} // namespace base

Просмотреть файл

@ -1,35 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_BASE_PATHS_H_
#define BASE_BASE_PATHS_H_
// This file declares path keys for the base module. These can be used with
// the PathService to access various special directories and files.
#include "base/basictypes.h"
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
#elif defined(OS_LINUX) || defined(OS_BSD)
#include "base/base_paths_linux.h"
#endif
#include "base/path_service.h"
namespace base {
enum {
PATH_START = 0,
DIR_CURRENT, // current directory
DIR_EXE, // directory containing FILE_EXE
DIR_MODULE, // directory containing FILE_MODULE
DIR_TEMP, // temporary directory
PATH_END
};
} // namespace base
#endif // BASE_BASE_PATHS_H_

Просмотреть файл

@ -1,46 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_paths_linux.h"
#include <unistd.h>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/string_piece.h"
#include "base/sys_string_conversions.h"
namespace base {
bool PathProviderLinux(int key, FilePath* result) {
FilePath path;
switch (key) {
case base::FILE_EXE:
case base::FILE_MODULE: { // TODO(evanm): is this correct?
char bin_dir[PATH_MAX + 1];
int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX);
if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
NOTREACHED() << "Unable to resolve /proc/self/exe.";
return false;
}
bin_dir[bin_dir_size] = 0;
*result = FilePath(bin_dir);
return true;
}
case base::DIR_SOURCE_ROOT:
// On linux, unit tests execute two levels deep from the source root.
// For example: sconsbuild/{Debug|Release}/net_unittest
if (!PathService::Get(base::DIR_EXE, &path))
return false;
path = path.Append(FilePath::kParentDirectory)
.Append(FilePath::kParentDirectory);
*result = path;
return true;
}
return false;
}
} // namespace base

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_BASE_PATHS_LINUX_H_
#define BASE_BASE_PATHS_LINUX_H_
// This file declares Linux-specific path keys for the base module.
// These can be used with the PathService to access various special
// directories and files.
namespace base {
enum {
PATH_LINUX_START = 200,
FILE_EXE, // Path and filename of the current executable.
FILE_MODULE, // Path and filename of the module containing the code for the
// PathService (which could differ from FILE_EXE if the
// PathService were compiled into a shared object, for example).
DIR_SOURCE_ROOT, // Returns the root of the source tree. This key is useful
// for tests that need to locate various resources. It
// should not be used outside of test code.
PATH_LINUX_END
};
} // namespace base
#endif // BASE_BASE_PATHS_LINUX_H_

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_BASE_PATHS_MAC_H_
#define BASE_BASE_PATHS_MAC_H_
// This file declares Mac-specific path keys for the base module.
// These can be used with the PathService to access various special
// directories and files.
namespace base {
enum {
PATH_MAC_START = 200,
FILE_EXE, // path and filename of the current executable
FILE_MODULE, // path and filename of the module containing the code for the
// PathService (which could differ from FILE_EXE if the
// PathService were compiled into a library, for example)
DIR_APP_DATA, // ~/Library/Application Support/Google/Chrome
DIR_LOCAL_APP_DATA, // same as above (can we remove?)
DIR_SOURCE_ROOT, // Returns the root of the source tree. This key is useful
// for tests that need to locate various resources. It
// should not be used outside of test code.
PATH_MAC_END
};
} // namespace base
#endif // BASE_BASE_PATHS_MAC_H_

Просмотреть файл

@ -1,58 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_paths_mac.h"
#import <Cocoa/Cocoa.h>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/mac_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
namespace base {
bool PathProviderMac(int key, FilePath* result) {
std::string cur;
switch (key) {
case base::FILE_EXE:
case base::FILE_MODULE: {
// Executable path can have relative references ("..") depending on
// how the app was launched.
NSString* path =
[[[NSBundle mainBundle] executablePath] stringByStandardizingPath];
cur = [path fileSystemRepresentation];
break;
}
case base::DIR_SOURCE_ROOT: {
FilePath path;
PathService::Get(base::DIR_EXE, &path);
if (mac_util::AmIBundled()) {
// The bundled app executables (Chromium, TestShell, etc) live five
// levels down, eg:
// src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium.
path = path.DirName();
path = path.DirName();
path = path.DirName();
path = path.DirName();
*result = path.DirName();
} else {
// Unit tests execute two levels deep from the source root, eg:
// src/xcodebuild/{Debug|Release}/base_unittests
path = path.DirName();
*result = path.DirName();
}
return true;
}
default:
return false;
}
*result = FilePath(cur);
return true;
}
} // namespace base

Просмотреть файл

@ -1,118 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_paths_win.h"
#include <windows.h>
#include <shlobj.h>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/win_util.h"
// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
extern "C" IMAGE_DOS_HEADER __ImageBase;
namespace base {
bool PathProviderWin(int key, FilePath* result) {
// We need to go compute the value. It would be nice to support paths with
// names longer than MAX_PATH, but the system functions don't seem to be
// designed for it either, with the exception of GetTempPath (but other
// things will surely break if the temp path is too long, so we don't bother
// handling it.
wchar_t system_buffer[MAX_PATH];
system_buffer[0] = 0;
FilePath cur;
std::wstring wstring_path;
switch (key) {
case base::FILE_EXE:
GetModuleFileName(NULL, system_buffer, MAX_PATH);
cur = FilePath(system_buffer);
break;
case base::FILE_MODULE: {
// the resource containing module is assumed to be the one that
// this code lives in, whether that's a dll or exe
HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
GetModuleFileName(this_module, system_buffer, MAX_PATH);
cur = FilePath(system_buffer);
break;
}
case base::DIR_WINDOWS:
GetWindowsDirectory(system_buffer, MAX_PATH);
cur = FilePath(system_buffer);
break;
case base::DIR_SYSTEM:
GetSystemDirectory(system_buffer, MAX_PATH);
cur = FilePath(system_buffer);
break;
case base::DIR_PROGRAM_FILES:
if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
return false;
cur = FilePath(system_buffer);
break;
case base::DIR_IE_INTERNET_CACHE:
if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
return false;
cur = FilePath(system_buffer);
break;
case base::DIR_COMMON_START_MENU:
if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
return false;
cur = FilePath(system_buffer);
break;
case base::DIR_START_MENU:
if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
return false;
cur = FilePath(system_buffer);
break;
case base::DIR_APP_DATA:
if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
system_buffer)))
return false;
cur = FilePath(system_buffer);
break;
case base::DIR_LOCAL_APP_DATA_LOW:
if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
return false;
}
// TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
system_buffer)))
return false;
wstring_path = system_buffer;
file_util::UpOneDirectory(&wstring_path);
file_util::AppendToPath(&wstring_path, L"LocalLow");
cur = FilePath(wstring_path);
break;
case base::DIR_LOCAL_APP_DATA:
if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
return false;
cur = FilePath(system_buffer);
break;
case base::DIR_SOURCE_ROOT:
// On Windows, unit tests execute two levels deep from the source root.
// For example: chrome/{Debug|Release}/ui_tests.exe
PathService::Get(base::DIR_EXE, &wstring_path);
file_util::UpOneDirectory(&wstring_path);
file_util::UpOneDirectory(&wstring_path);
cur = FilePath(wstring_path);
break;
default:
return false;
}
*result = cur;
return true;
}
} // namespace base

Просмотреть файл

@ -1,42 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_BASE_PATHS_WIN_H__
#define BASE_BASE_PATHS_WIN_H__
// This file declares windows-specific path keys for the base module.
// These can be used with the PathService to access various special
// directories and files.
namespace base {
enum {
PATH_WIN_START = 100,
FILE_EXE, // path and filename of the current executable
FILE_MODULE, // path and filename of the module containing the code for the
// PathService (which could differ from FILE_EXE if the
// PathService were compiled into a DLL, for example)
DIR_WINDOWS, // Windows directory, usually "c:\windows"
DIR_SYSTEM, // Usually c:\windows\system32"
DIR_PROGRAM_FILES, // Usually c:\program files
DIR_IE_INTERNET_CACHE, // Temporary Internet Files directory.
DIR_COMMON_START_MENU, // Usually "C:\Documents and Settings\All Users\
// Start Menu\Programs"
DIR_START_MENU, // Usually "C:\Documents and Settings\<user>\
// Start Menu\Programs"
DIR_APP_DATA, // Application Data directory under the user profile.
DIR_LOCAL_APP_DATA_LOW, // Local AppData directory for low integrity level.
DIR_LOCAL_APP_DATA, // "Local Settings\Application Data" directory under the
// user profile.
DIR_SOURCE_ROOT, // Returns the root of the source tree. This key is useful
// for tests that need to locate various resources. It
// should not be used outside of test code.
PATH_WIN_END
};
} // namespace base
#endif // BASE_BASE_PATHS_WIN_H__

Просмотреть файл

@ -1,267 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/path_service.h"
#ifdef OS_WIN
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
#endif
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/lock.h"
#include "base/logging.h"
#include "base/singleton.h"
#include "base/string_util.h"
namespace base {
bool PathProvider(int key, FilePath* result);
#if defined(OS_WIN)
bool PathProviderWin(int key, FilePath* result);
#elif defined(OS_MACOSX)
bool PathProviderMac(int key, FilePath* result);
#elif defined(OS_LINUX)
bool PathProviderLinux(int key, FilePath* result);
#endif
}
namespace {
typedef base::hash_map<int, FilePath> PathMap;
typedef base::hash_set<int> PathSet;
// We keep a linked list of providers. In a debug build we ensure that no two
// providers claim overlapping keys.
struct Provider {
PathService::ProviderFunc func;
struct Provider* next;
#ifndef NDEBUG
int key_start;
int key_end;
#endif
bool is_static;
};
static Provider base_provider = {
base::PathProvider,
NULL,
#ifndef NDEBUG
base::PATH_START,
base::PATH_END,
#endif
true
};
#ifdef OS_WIN
static Provider base_provider_win = {
base::PathProviderWin,
&base_provider,
#ifndef NDEBUG
base::PATH_WIN_START,
base::PATH_WIN_END,
#endif
true
};
#endif
#ifdef OS_MACOSX
static Provider base_provider_mac = {
base::PathProviderMac,
&base_provider,
#ifndef NDEBUG
base::PATH_MAC_START,
base::PATH_MAC_END,
#endif
true
};
#endif
#if defined(OS_LINUX)
static Provider base_provider_linux = {
base::PathProviderLinux,
&base_provider,
#ifndef NDEBUG
base::PATH_LINUX_START,
base::PATH_LINUX_END,
#endif
true
};
#endif
struct PathData {
Lock lock;
PathMap cache; // Track mappings from path key to path value.
PathSet overrides; // Track whether a path has been overridden.
Provider* providers; // Linked list of path service providers.
PathData() {
#if defined(OS_WIN)
providers = &base_provider_win;
#elif defined(OS_MACOSX)
providers = &base_provider_mac;
#elif defined(OS_LINUX)
providers = &base_provider_linux;
#endif
}
~PathData() {
Provider* p = providers;
while (p) {
Provider* next = p->next;
if (!p->is_static)
delete p;
p = next;
}
}
};
static PathData* GetPathData() {
return Singleton<PathData>::get();
}
} // namespace
// static
bool PathService::GetFromCache(int key, FilePath* result) {
PathData* path_data = GetPathData();
AutoLock scoped_lock(path_data->lock);
// check for a cached version
PathMap::const_iterator it = path_data->cache.find(key);
if (it != path_data->cache.end()) {
*result = it->second;
return true;
}
return false;
}
// static
void PathService::AddToCache(int key, const FilePath& path) {
PathData* path_data = GetPathData();
AutoLock scoped_lock(path_data->lock);
// Save the computed path in our cache.
path_data->cache[key] = path;
}
// TODO(brettw): this function does not handle long paths (filename > MAX_PATH)
// characters). This isn't supported very well by Windows right now, so it is
// moot, but we should keep this in mind for the future.
// static
bool PathService::Get(int key, FilePath* result) {
PathData* path_data = GetPathData();
DCHECK(path_data);
DCHECK(result);
DCHECK(key >= base::DIR_CURRENT);
// special case the current directory because it can never be cached
if (key == base::DIR_CURRENT)
return file_util::GetCurrentDirectory(result);
if (GetFromCache(key, result))
return true;
FilePath path;
// search providers for the requested path
// NOTE: it should be safe to iterate here without the lock
// since RegisterProvider always prepends.
Provider* provider = path_data->providers;
while (provider) {
if (provider->func(key, &path))
break;
DCHECK(path.empty()) << "provider should not have modified path";
provider = provider->next;
}
if (path.empty())
return false;
AddToCache(key, path);
*result = path;
return true;
}
// static
bool PathService::Get(int key, std::wstring* result) {
// Deprecated compatibility function.
FilePath path;
if (!Get(key, &path))
return false;
*result = path.ToWStringHack();
return true;
}
bool PathService::IsOverridden(int key) {
PathData* path_data = GetPathData();
DCHECK(path_data);
AutoLock scoped_lock(path_data->lock);
return path_data->overrides.find(key) != path_data->overrides.end();
}
bool PathService::Override(int key, const std::wstring& path) {
PathData* path_data = GetPathData();
DCHECK(path_data);
DCHECK(key > base::DIR_CURRENT) << "invalid path key";
std::wstring file_path = path;
#if defined(OS_WIN)
// On Windows we switch the current working directory to load plugins (at
// least). That's not the case on POSIX.
// Also, on POSIX, AbsolutePath fails if called on a non-existant path.
if (!file_util::AbsolutePath(&file_path))
return false;
#endif
// make sure the directory exists:
if (!file_util::CreateDirectory(file_path))
return false;
file_util::TrimTrailingSeparator(&file_path);
AutoLock scoped_lock(path_data->lock);
path_data->cache[key] = FilePath::FromWStringHack(file_path);
path_data->overrides.insert(key);
return true;
}
bool PathService::SetCurrentDirectory(const std::wstring& current_directory) {
return file_util::SetCurrentDirectory(current_directory);
}
void PathService::RegisterProvider(ProviderFunc func, int key_start,
int key_end) {
PathData* path_data = GetPathData();
DCHECK(path_data);
DCHECK(key_end > key_start);
AutoLock scoped_lock(path_data->lock);
Provider* p;
#ifndef NDEBUG
p = path_data->providers;
while (p) {
DCHECK(key_start >= p->key_end || key_end <= p->key_start) <<
"path provider collision";
p = p->next;
}
#endif
p = new Provider;
p->is_static = false;
p->func = func;
p->next = path_data->providers;
#ifndef NDEBUG
p->key_start = key_start;
p->key_end = key_end;
#endif
path_data->providers = p;
}

Просмотреть файл

@ -1,80 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_PATH_SERVICE_H__
#define BASE_PATH_SERVICE_H__
#include "build/build_config.h"
#ifdef OS_WIN
// TODO(erikkay): this should be removable, but because SetCurrentDirectory
// is the name of a Windows function, it gets macro-ized to SetCurrentDirectoryW
// by windows.h, which leads to a different name in the header vs. the impl.
// Even if we could fix that, it would still hose all callers of the function.
// The right thing is likely to rename.
#include <windows.h>
#endif
#include <string>
#include "base/base_paths.h"
class FilePath;
// The path service is a global table mapping keys to file system paths. It is
// OK to use this service from multiple threads.
//
class PathService {
public:
// Retrieves a path to a special directory or file and places it into the
// string pointed to by 'path'. If you ask for a directory it is guaranteed
// to NOT have a path separator at the end. For example, "c:\windows\temp"
// Directories are also guaranteed to exist when this function succeeds.
//
// Returns true if the directory or file was successfully retrieved. On
// failure, 'path' will not be changed.
static bool Get(int key, FilePath* path);
// This version, producing a wstring, is deprecated and only kept around
// until we can fix all callers.
static bool Get(int key, std::wstring* path);
// Overrides the path to a special directory or file. This cannot be used to
// change the value of DIR_CURRENT, but that should be obvious. Also, if the
// path specifies a directory that does not exist, the directory will be
// created by this method. This method returns true if successful.
//
// If the given path is relative, then it will be resolved against
// DIR_CURRENT.
//
// WARNING: Consumers of PathService::Get may expect paths to be constant
// over the lifetime of the app, so this method should be used with caution.
static bool Override(int key, const std::wstring& path);
// Return whether a path was overridden.
static bool IsOverridden(int key);
// Sets the current directory.
static bool SetCurrentDirectory(const std::wstring& current_directory);
// To extend the set of supported keys, you can register a path provider,
// which is just a function mirroring PathService::Get. The ProviderFunc
// returns false if it cannot provide a non-empty path for the given key.
// Otherwise, true is returned.
//
// WARNING: This function could be called on any thread from which the
// PathService is used, so the ProviderFunc MUST BE THREADSAFE.
//
typedef bool (*ProviderFunc)(int, FilePath*);
// Call to register a path provider. You must specify the range "[key_start,
// key_end)" of supported path keys.
static void RegisterProvider(ProviderFunc provider,
int key_start,
int key_end);
private:
static bool GetFromCache(int key, FilePath* path);
static void AddToCache(int key, const FilePath& path);
};
#endif // BASE_PATH_SERVICE_H__

Просмотреть файл

@ -1,155 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/trace_event.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
#include "base/process_util.h"
#include "base/string_util.h"
#include "base/time.h"
#define USE_UNRELIABLE_NOW
namespace base {
static const char* kEventTypeNames[] = {
"BEGIN",
"END",
"INSTANT"
};
static const FilePath::CharType* kLogFileName =
FILE_PATH_LITERAL("trace_%d.log");
TraceLog::TraceLog() : enabled_(false), log_file_(NULL) {
base::ProcessHandle proc = base::GetCurrentProcessHandle();
process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(proc));
}
TraceLog::~TraceLog() {
Stop();
}
// static
bool TraceLog::IsTracing() {
TraceLog* trace = Singleton<TraceLog>::get();
return trace->enabled_;
}
// static
bool TraceLog::StartTracing() {
TraceLog* trace = Singleton<TraceLog>::get();
return trace->Start();
}
bool TraceLog::Start() {
if (enabled_)
return true;
enabled_ = OpenLogFile();
if (enabled_) {
Log("var raw_trace_events = [\n");
trace_start_time_ = TimeTicks::Now();
timer_.Start(TimeDelta::FromMilliseconds(250), this, &TraceLog::Heartbeat);
}
return enabled_;
}
// static
void TraceLog::StopTracing() {
TraceLog* trace = Singleton<TraceLog>::get();
return trace->Stop();
}
void TraceLog::Stop() {
if (enabled_) {
enabled_ = false;
Log("];\n");
CloseLogFile();
timer_.Stop();
}
}
void TraceLog::Heartbeat() {
std::string cpu = StringPrintf("%d", process_metrics_->GetCPUUsage());
TRACE_EVENT_INSTANT("heartbeat.cpu", 0, cpu);
}
void TraceLog::CloseLogFile() {
if (log_file_) {
file_util::CloseFile(log_file_);
}
}
bool TraceLog::OpenLogFile() {
FilePath::StringType pid_filename =
StringPrintf(kLogFileName, base::GetCurrentProcId());
FilePath log_file_path;
if (!PathService::Get(base::DIR_EXE, &log_file_path))
return false;
log_file_path = log_file_path.Append(pid_filename);
log_file_ = file_util::OpenFile(log_file_path, "a");
if (!log_file_) {
// try the current directory
log_file_ = file_util::OpenFile(FilePath(pid_filename), "a");
if (!log_file_) {
return false;
}
}
return true;
}
void TraceLog::Trace(const std::string& name,
EventType type,
const void* id,
const std::wstring& extra,
const char* file,
int line) {
if (!enabled_)
return;
Trace(name, type, id, WideToUTF8(extra), file, line);
}
void TraceLog::Trace(const std::string& name,
EventType type,
const void* id,
const std::string& extra,
const char* file,
int line) {
if (!enabled_)
return;
#ifdef USE_UNRELIABLE_NOW
TimeTicks tick = TimeTicks::HighResNow();
#else
TimeTicks tick = TimeTicks::Now();
#endif
TimeDelta delta = tick - trace_start_time_;
int64_t usec = delta.InMicroseconds();
std::string msg =
StringPrintf("{'pid':'0x%lx', 'tid':'0x%lx', 'type':'%s', "
"'name':'%s', 'id':'0x%lx', 'extra':'%s', 'file':'%s', "
"'line_number':'%d', 'usec_begin': %I64d},\n",
base::GetCurrentProcId(),
PlatformThread::CurrentId(),
kEventTypeNames[type],
name.c_str(),
id,
extra.c_str(),
file,
line,
usec);
Log(msg);
}
void TraceLog::Log(const std::string& msg) {
AutoLock lock(file_lock_);
fprintf(log_file_, "%s", msg.c_str());
}
} // namespace base

Просмотреть файл

@ -1,126 +0,0 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Trace events to track application performance. Events consist of a name
// a type (BEGIN, END or INSTANT), a tracking id and extra string data.
// In addition, the current process id, thread id, a timestamp down to the
// microsecond and a file and line number of the calling location.
//
// The current implementation logs these events into a log file of the form
// trace_<pid>.log where it's designed to be post-processed to generate a
// trace report. In the future, it may use another mechansim to facilitate
// real-time analysis.
#ifndef BASE_TRACE_EVENT_H_
#define BASE_TRACE_EVENT_H_
#include "build/build_config.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
#include <string>
#include "base/lock.h"
#include "base/scoped_ptr.h"
#include "base/singleton.h"
#include "base/time.h"
#include "base/timer.h"
// Use the following macros rather than using the TraceLog class directly as the
// underlying implementation may change in the future. Here's a sample usage:
// TRACE_EVENT_BEGIN("v8.run", documentId, scriptLocation);
// RunScript(script);
// TRACE_EVENT_END("v8.run", documentId, scriptLocation);
// Record that an event (of name, id) has begun. All BEGIN events should have
// corresponding END events with a matching (name, id).
#define TRACE_EVENT_BEGIN(name, id, extra) \
Singleton<base::TraceLog>::get()->Trace(name, \
base::TraceLog::EVENT_BEGIN, \
reinterpret_cast<const void*>(id), \
extra, \
__FILE__, \
__LINE__)
// Record that an event (of name, id) has ended. All END events should have
// corresponding BEGIN events with a matching (name, id).
#define TRACE_EVENT_END(name, id, extra) \
Singleton<base::TraceLog>::get()->Trace(name, \
base::TraceLog::EVENT_END, \
reinterpret_cast<const void*>(id), \
extra, \
__FILE__, \
__LINE__)
// Record that an event (of name, id) with no duration has happened.
#define TRACE_EVENT_INSTANT(name, id, extra) \
Singleton<base::TraceLog>::get()->Trace(name, \
base::TraceLog::EVENT_INSTANT, \
reinterpret_cast<const void*>(id), \
extra, \
__FILE__, \
__LINE__)
namespace base {
class ProcessMetrics;
}
namespace base {
class TraceLog {
public:
enum EventType {
EVENT_BEGIN,
EVENT_END,
EVENT_INSTANT
};
// Is tracing currently enabled.
static bool IsTracing();
// Start logging trace events.
static bool StartTracing();
// Stop logging trace events.
static void StopTracing();
// Log a trace event of (name, type, id) with the optional extra string.
void Trace(const std::string& name,
EventType type,
const void* id,
const std::wstring& extra,
const char* file,
int line);
void Trace(const std::string& name,
EventType type,
const void* id,
const std::string& extra,
const char* file,
int line);
private:
// This allows constructor and destructor to be private and usable only
// by the Singleton class.
friend struct DefaultSingletonTraits<TraceLog>;
TraceLog();
~TraceLog();
bool OpenLogFile();
void CloseLogFile();
bool Start();
void Stop();
void Heartbeat();
void Log(const std::string& msg);
bool enabled_;
FILE* log_file_;
Lock file_lock_;
TimeTicks trace_start_time_;
scoped_ptr<base::ProcessMetrics> process_metrics_;
RepeatingTimer<TraceLog> timer_;
};
} // namespace base
#endif // BASE_TRACE_EVENT_H_

Просмотреть файл

@ -7,7 +7,6 @@
#include "GeckoChildProcessHost.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/process_watcher.h"