Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 #include "base/commandlineflags.h" | 49 #include "base/commandlineflags.h" |
| 50 | 50 |
| 51 // On some systems (like freebsd), we can't call write() at all in a | 51 // On some systems (like freebsd), we can't call write() at all in a |
| 52 // global constructor, perhaps because errno hasn't been set up. | 52 // global constructor, perhaps because errno hasn't been set up. |
| 53 // (In windows, we can't call it because it might call malloc.) | 53 // (In windows, we can't call it because it might call malloc.) |
| 54 // Calling the write syscall is safer (it doesn't set errno), so we | 54 // Calling the write syscall is safer (it doesn't set errno), so we |
| 55 // prefer that. Note we don't care about errno for logging: we just | 55 // prefer that. Note we don't care about errno for logging: we just |
| 56 // do logging on a best-effort basis. | 56 // do logging on a best-effort basis. |
| 57 #if defined(_MSC_VER) | 57 #if defined(_MSC_VER) |
| 58 #define WRITE_TO_STDERR(buf, len) WriteToStderr(buf, len); // in port.cc | 58 #define WRITE_TO_STDERR(buf, len) WriteToStderr(buf, len); // in port.cc |
| 59 #elif defined(__ANDROID__) || defined(ANDROID) | |
| 60 #include <android/log.h> | |
| 61 #define WRITE_TO_STDERR(buf, len) \ | |
| 62 __android_log_write(ANDROID_LOG_ERROR, "gperftools", buf) | |
| 59 #elif defined(HAVE_SYS_SYSCALL_H) | 63 #elif defined(HAVE_SYS_SYSCALL_H) |
| 60 #include <sys/syscall.h> | 64 #include <sys/syscall.h> |
| 61 #define WRITE_TO_STDERR(buf, len) syscall(SYS_write, STDERR_FILENO, buf, len) | 65 #define WRITE_TO_STDERR(buf, len) syscall(SYS_write, STDERR_FILENO, buf, len) |
| 62 #else | 66 #else |
| 63 #define WRITE_TO_STDERR(buf, len) write(STDERR_FILENO, buf, len) | 67 #define WRITE_TO_STDERR(buf, len) write(STDERR_FILENO, buf, len) |
| 64 #endif | 68 #endif |
| 65 | 69 |
| 66 // MSVC and mingw define their own, safe version of vnsprintf (the | 70 // MSVC and mingw define their own, safe version of vnsprintf (the |
| 67 // windows one in broken) in port.cc. Everyone else can use the | 71 // windows one in broken) in port.cc. Everyone else can use the |
| 68 // version here. We had to give it a unique name for windows. | 72 // version here. We had to give it a unique name for windows. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 // NOTE: we add a newline to the end of the output if it's not there already | 201 // NOTE: we add a newline to the end of the output if it's not there already |
| 198 inline void LogPrintf(int severity, const char* pat, va_list ap) { | 202 inline void LogPrintf(int severity, const char* pat, va_list ap) { |
| 199 // We write directly to the stderr file descriptor and avoid FILE | 203 // We write directly to the stderr file descriptor and avoid FILE |
| 200 // buffering because that may invoke malloc() | 204 // buffering because that may invoke malloc() |
| 201 char buf[1600]; | 205 char buf[1600]; |
| 202 perftools_vsnprintf(buf, sizeof(buf)-1, pat, ap); | 206 perftools_vsnprintf(buf, sizeof(buf)-1, pat, ap); |
| 203 if (buf[0] != '\0' && buf[strlen(buf)-1] != '\n') { | 207 if (buf[0] != '\0' && buf[strlen(buf)-1] != '\n') { |
| 204 assert(strlen(buf)+1 < sizeof(buf)); | 208 assert(strlen(buf)+1 < sizeof(buf)); |
| 205 strcat(buf, "\n"); | 209 strcat(buf, "\n"); |
| 206 } | 210 } |
| 211 #if defined(__ANDROID__) || defined(ANDROID) | |
| 212 android_LogPriority priority = ANDROID_LOG_UNKNOWN; | |
| 213 switch (severity) { | |
| 214 case INFO: | |
|
willchan no longer on Chromium
2013/05/07 14:45:36
Indentation is off. Please follow the format in ht
Dai Mikurube (NOT FULLTIME)
2013/05/07 17:10:15
Done.
| |
| 215 priority = ANDROID_LOG_INFO; | |
| 216 break; | |
| 217 case WARNING: | |
| 218 priority = ANDROID_LOG_WARN; | |
| 219 break; | |
| 220 case ERROR: | |
| 221 priority = ANDROID_LOG_ERROR; | |
| 222 break; | |
| 223 case FATAL: | |
| 224 priority = ANDROID_LOG_FATAL; | |
| 225 break; | |
| 226 } | |
| 227 __android_log_write(priority, "gperftools", buf); | |
| 228 #else // defined(__ANDROID__) || defined(ANDROID) | |
| 207 WRITE_TO_STDERR(buf, strlen(buf)); | 229 WRITE_TO_STDERR(buf, strlen(buf)); |
| 230 #endif // defined(__ANDROID__) || defined(ANDROID) | |
| 208 if ((severity) == FATAL) { | 231 if ((severity) == FATAL) { |
| 209 // LOG(FATAL) indicates a big problem, so don't run atexit() calls | 232 // LOG(FATAL) indicates a big problem, so don't run atexit() calls |
| 210 tcmalloc::Abort(); | 233 tcmalloc::Abort(); |
| 211 } | 234 } |
| 212 } | 235 } |
| 213 | 236 |
| 214 // Note that since the order of global constructors is unspecified, | 237 // Note that since the order of global constructors is unspecified, |
| 215 // global code that calls RAW_LOG may execute before FLAGS_verbose is set. | 238 // global code that calls RAW_LOG may execute before FLAGS_verbose is set. |
| 216 // Such code will run with verbosity == 0 no matter what. | 239 // Such code will run with verbosity == 0 no matter what. |
| 217 #define VLOG_IS_ON(severity) (FLAGS_verbose >= severity) | 240 #define VLOG_IS_ON(severity) (FLAGS_verbose >= severity) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 #else | 275 #else |
| 253 typedef int RawFD; | 276 typedef int RawFD; |
| 254 const RawFD kIllegalRawFD = -1; // what open returns if it fails | 277 const RawFD kIllegalRawFD = -1; // what open returns if it fails |
| 255 #endif // defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) | 278 #endif // defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) |
| 256 | 279 |
| 257 RawFD RawOpenForWriting(const char* filename); // uses default permissions | 280 RawFD RawOpenForWriting(const char* filename); // uses default permissions |
| 258 void RawWrite(RawFD fd, const char* buf, size_t len); | 281 void RawWrite(RawFD fd, const char* buf, size_t len); |
| 259 void RawClose(RawFD fd); | 282 void RawClose(RawFD fd); |
| 260 | 283 |
| 261 #endif // _LOGGING_H_ | 284 #endif // _LOGGING_H_ |
| OLD | NEW |