| OLD | NEW |
| 1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, 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 12 matching lines...) Expand all Loading... |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 #include <config.h> | 30 #include <config.h> |
| 31 #if (defined(_WIN32) || defined(__MINGW32__)) && !defined(__CYGWIN__) && !define
d(__CYGWIN32) | 31 #if (defined(_WIN32) || defined(__MINGW32__)) && !defined(__CYGWIN__) && !define
d(__CYGWIN32) |
| 32 # define PLATFORM_WINDOWS 1 | 32 # define PLATFORM_WINDOWS 1 |
| 33 #elif defined(__ANDROID__) || defined(ANDROID) |
| 34 # define PLATFORM_ANDROID 1 |
| 33 #endif | 35 #endif |
| 34 | 36 |
| 35 #include <ctype.h> // for isspace() | 37 #include <ctype.h> // for isspace() |
| 36 #include <stdlib.h> // for getenv() | 38 #include <stdlib.h> // for getenv() |
| 37 #include <stdio.h> // for snprintf(), sscanf() | 39 #include <stdio.h> // for snprintf(), sscanf() |
| 38 #include <string.h> // for memmove(), memchr(), etc. | 40 #include <string.h> // for memmove(), memchr(), etc. |
| 39 #include <fcntl.h> // for open() | 41 #include <fcntl.h> // for open() |
| 40 #include <errno.h> // for errno | 42 #include <errno.h> // for errno |
| 41 #ifdef HAVE_UNISTD_H | 43 #ifdef HAVE_UNISTD_H |
| 42 #include <unistd.h> // for read() | 44 #include <unistd.h> // for read() |
| 43 #endif | 45 #endif |
| 44 #if defined __MACH__ // Mac OS X, almost certainly | 46 #if defined __MACH__ // Mac OS X, almost certainly |
| 45 #include <mach-o/dyld.h> // for iterating over dll's in ProcMapsIter | 47 #include <mach-o/dyld.h> // for iterating over dll's in ProcMapsIter |
| 46 #include <mach-o/loader.h> // for iterating over dll's in ProcMapsIter | 48 #include <mach-o/loader.h> // for iterating over dll's in ProcMapsIter |
| 47 #include <sys/types.h> | 49 #include <sys/types.h> |
| 48 #include <sys/sysctl.h> // how we figure out numcpu's on OS X | 50 #include <sys/sysctl.h> // how we figure out numcpu's on OS X |
| 49 #elif defined __FreeBSD__ | 51 #elif defined __FreeBSD__ |
| 50 #include <sys/sysctl.h> | 52 #include <sys/sysctl.h> |
| 51 #elif defined __sun__ // Solaris | 53 #elif defined __sun__ // Solaris |
| 52 #include <procfs.h> // for, e.g., prmap_t | 54 #include <procfs.h> // for, e.g., prmap_t |
| 53 #elif defined(PLATFORM_WINDOWS) | 55 #elif defined(PLATFORM_WINDOWS) |
| 54 #include <process.h> // for getpid() (actually, _getpid()) | 56 #include <process.h> // for getpid() (actually, _getpid()) |
| 55 #include <shlwapi.h> // for SHGetValueA() | 57 #include <shlwapi.h> // for SHGetValueA() |
| 56 #include <tlhelp32.h> // for Module32First() | 58 #include <tlhelp32.h> // for Module32First() |
| 59 #elif defined(PLATFORM_ANDROID) |
| 60 #include <sys/system_properties.h> |
| 57 #endif | 61 #endif |
| 58 #include "base/sysinfo.h" | 62 #include "base/sysinfo.h" |
| 59 #include "base/commandlineflags.h" | 63 #include "base/commandlineflags.h" |
| 60 #include "base/dynamic_annotations.h" // for RunningOnValgrind | 64 #include "base/dynamic_annotations.h" // for RunningOnValgrind |
| 61 #include "base/logging.h" | 65 #include "base/logging.h" |
| 62 #include "base/cycleclock.h" | 66 #include "base/cycleclock.h" |
| 63 | 67 |
| 64 #ifdef PLATFORM_WINDOWS | 68 #ifdef PLATFORM_WINDOWS |
| 65 #ifdef MODULEENTRY32 | 69 #ifdef MODULEENTRY32 |
| 66 // In a change from the usual W-A pattern, there is no A variant of | 70 // In a change from the usual W-A pattern, there is no A variant of |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // the high bit of the 1st char of CPUPROFILE. In the child, we | 189 // the high bit of the 1st char of CPUPROFILE. In the child, we |
| 186 // notice the high bit is set and append the pid(). This works | 190 // notice the high bit is set and append the pid(). This works |
| 187 // assuming cpuprofile filenames don't normally have the high bit set | 191 // assuming cpuprofile filenames don't normally have the high bit set |
| 188 // in their first character! If that assumption is violated, we'll | 192 // in their first character! If that assumption is violated, we'll |
| 189 // still get a profile, but one with an unexpected name. | 193 // still get a profile, but one with an unexpected name. |
| 190 // TODO(csilvers): set an envvar instead when we can do it reliably. | 194 // TODO(csilvers): set an envvar instead when we can do it reliably. |
| 191 // | 195 // |
| 192 // In Chromium this hack is intentionally disabled, because the path is not | 196 // In Chromium this hack is intentionally disabled, because the path is not |
| 193 // re-initialized upon fork. | 197 // re-initialized upon fork. |
| 194 bool GetUniquePathFromEnv(const char* env_name, char* path) { | 198 bool GetUniquePathFromEnv(const char* env_name, char* path) { |
| 199 #if defined(PLATFORM_ANDROID) |
| 200 char envval[PROP_VALUE_MAX]; |
| 201 __system_property_get(env_name, envval); |
| 202 #else |
| 195 char* envval = getenv(env_name); | 203 char* envval = getenv(env_name); |
| 204 #endif |
| 196 if (envval == NULL || *envval == '\0') | 205 if (envval == NULL || *envval == '\0') |
| 197 return false; | 206 return false; |
| 198 if (envval[0] & 128) { // high bit is set | 207 if (envval[0] & 128) { // high bit is set |
| 199 snprintf(path, PATH_MAX, "%c%s_%u", // add pid and clear high bit | 208 snprintf(path, PATH_MAX, "%c%s_%u", // add pid and clear high bit |
| 200 envval[0] & 127, envval+1, (unsigned int)(getpid())); | 209 envval[0] & 127, envval+1, (unsigned int)(getpid())); |
| 201 } else { | 210 } else { |
| 202 snprintf(path, PATH_MAX, "%s", envval); | 211 snprintf(path, PATH_MAX, "%s", envval); |
| 203 #if 0 | 212 #if 0 |
| 204 envval[0] |= 128; // set high bit for kids to see | 213 envval[0] |= 128; // set high bit for kids to see |
| 205 #endif | 214 #endif |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 ProcMapsIterator::Buffer linebuf; | 1131 ProcMapsIterator::Buffer linebuf; |
| 1123 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { | 1132 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { |
| 1124 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), | 1133 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), |
| 1125 start, end, flags, offset, inode, filename, | 1134 start, end, flags, offset, inode, filename, |
| 1126 0); | 1135 0); |
| 1127 RawWrite(fd, linebuf.buf_, written); | 1136 RawWrite(fd, linebuf.buf_, written); |
| 1128 } | 1137 } |
| 1129 } | 1138 } |
| 1130 | 1139 |
| 1131 } // namespace tcmalloc | 1140 } // namespace tcmalloc |
| OLD | NEW |