Commit 8a48f3f9 authored by felipeg@chromium.org's avatar felipeg@chromium.org

Change cygprofile to work on Android.

We want to use cygprofile for the same purpose as the chromeos: To generate order_text_session files based on earliest run of each function call.

BUG=150893


Review URL: https://chromiumcodereview.appspot.com/11348354

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171034 0039d316-1c4b-4281-b951-d872f2087c98
parent 45e1d228
...@@ -2750,7 +2750,7 @@ ...@@ -2750,7 +2750,7 @@
}], }],
], ],
}], }],
['order_profiling!=0 and (chromeos==1 or OS=="linux")', { ['order_profiling!=0 and (chromeos==1 or OS=="linux" or OS=="android")', {
'target_conditions' : [ 'target_conditions' : [
['_toolset=="target"', { ['_toolset=="target"', {
'cflags': [ 'cflags': [
......
...@@ -32,9 +32,9 @@ ...@@ -32,9 +32,9 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <unordered_set>
#include <vector> #include <vector>
#include "base/hash_tables.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
...@@ -131,7 +131,7 @@ class CygTlsLog { ...@@ -131,7 +131,7 @@ class CygTlsLog {
// Keeps track of all functions that have been logged on this thread // Keeps track of all functions that have been logged on this thread
// so we do not record dublicates. // so we do not record dublicates.
std::unordered_set<void*> functions_called_; std::hash_set<void*> functions_called_;
// Thread identifier as Linux kernel shows it. For debugging purposes. // Thread identifier as Linux kernel shows it. For debugging purposes.
// LWP (light-weight process) is a unique ID of the thread in the system, // LWP (light-weight process) is a unique ID of the thread in the system,
...@@ -152,7 +152,7 @@ struct AllLogs { ...@@ -152,7 +152,7 @@ struct AllLogs {
base::LazyInstance<AllLogs>::Leaky all_logs_ = LAZY_INSTANCE_INITIALIZER; base::LazyInstance<AllLogs>::Leaky all_logs_ = LAZY_INSTANCE_INITIALIZER;
// Per-thread pointer to the current log object. // Per-thread pointer to the current log object.
__thread CygTlsLog* tls_current_log = NULL; static __thread CygTlsLog* tls_current_log = NULL;
// Magic value of above to prevent the instrumentation. Used when CygTlsLog is // Magic value of above to prevent the instrumentation. Used when CygTlsLog is
// being constructed (to prevent reentering by malloc, for example) and by // being constructed (to prevent reentering by malloc, for example) and by
...@@ -163,8 +163,16 @@ CygTlsLog* const kMagicBeingConstructed = reinterpret_cast<CygTlsLog*>(1); ...@@ -163,8 +163,16 @@ CygTlsLog* const kMagicBeingConstructed = reinterpret_cast<CygTlsLog*>(1);
// Note, that we also flush by timer so not all thread logs may grow up to this. // Note, that we also flush by timer so not all thread logs may grow up to this.
const int CygTlsLog::kBufMaxSize = 3000; const int CygTlsLog::kBufMaxSize = 3000;
#if defined(OS_ANDROID)
const char CytTlsLog::kLogFileNamePrefix =
"/data/local/tmp/chrome/cyglog/";
#else
const char CytTlsLog::kLogFileNamePrefix = "/var/log/chrome/";
#endif
// "cyglog.PID.LWP.pthread_self.PPID" // "cyglog.PID.LWP.pthread_self.PPID"
const char CygTlsLog::kLogFilenameFmt[] = "/var/log/chrome/cyglog.%d.%d.%ld-%d"; const char CygTlsLog::kLogFilenameFmt[] = "%scyglog.%d.%d.%ld-%d";
CygCommon* CygCommon::GetInstance() { CygCommon* CygCommon::GetInstance() {
return Singleton<CygCommon>::get(); return Singleton<CygCommon>::get();
...@@ -281,9 +289,17 @@ void CygTlsLog::AddNewLog(CygTlsLog* newlog) { ...@@ -281,9 +289,17 @@ void CygTlsLog::AddNewLog(CygTlsLog* newlog) {
AllLogs& all_logs = all_logs_.Get(); AllLogs& all_logs = all_logs_.Get();
base::AutoLock lock(all_logs.mutex); base::AutoLock lock(all_logs.mutex);
if (all_logs.logs.empty()) { if (all_logs.logs.empty()) {
// An Android app never fork, it always starts with a pre-defined number of
// process descibed by the android manifest file. In fact, there is not
// support for pthread_atfork at the android system libraries. All chrome
// for android processes will start as independent processs and each one
// will generate its own logs that will later have to be merged as usual.
#if !defined(OS_ANDROID)
CHECK(!pthread_atfork(CygTlsLog::AtForkPrepare, CHECK(!pthread_atfork(CygTlsLog::AtForkPrepare,
CygTlsLog::AtForkParent, CygTlsLog::AtForkParent,
CygTlsLog::AtForkChild)); CygTlsLog::AtForkChild));
#endif
// The very first process starts its flush thread here. Forked processes // The very first process starts its flush thread here. Forked processes
// will do it in AtForkChild(). // will do it in AtForkChild().
...@@ -304,12 +320,11 @@ static void WriteLogLine(int fd, const char* fmt, ...) { ...@@ -304,12 +320,11 @@ static void WriteLogLine(int fd, const char* fmt, ...) {
void CygTlsLog::FlushLog() { void CygTlsLog::FlushLog() {
bool first_log_write = false; bool first_log_write = false;
if (log_filename_.empty()) { if (log_filename_.empty()) {
first_log_write = true; first_log_write = true;
char buf[80]; char buf[80];
snprintf(buf, sizeof(buf), kLogFilenameFmt, snprintf(buf, sizeof(buf), kLogFilenameFmt,
getpid(), lwp_, pthread_self_, getppid()); kLogFileNamePrefix, getpid(), lwp_, pthread_self_, getppid());
log_filename_ = buf; log_filename_ = buf;
unlink(log_filename_.c_str()); unlink(log_filename_.c_str());
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
'cygprofile.cc', 'cygprofile.cc',
], ],
'cflags!': [ '-finstrument-functions' ], 'cflags!': [ '-finstrument-functions' ],
'cflags': [ '-std=c++0x' ], # for unordered_set
}, },
], ],
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment