Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: third_party/tcmalloc/chromium/src/base/sysinfo.cc

Issue 6532051: Fix heap profiler to always append the process id to the heap dump.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | third_party/tcmalloc/chromium/src/heap-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // gcc -- if you do a setenv() in a shared libarary in a global 169 // gcc -- if you do a setenv() in a shared libarary in a global
170 // constructor, the environment setting is lost by the time main() is 170 // constructor, the environment setting is lost by the time main() is
171 // called. The only safe thing we can do in such a situation is to 171 // called. The only safe thing we can do in such a situation is to
172 // modify the existing envvar. So we do a hack: in the parent, we set 172 // modify the existing envvar. So we do a hack: in the parent, we set
173 // the high bit of the 1st char of CPUPROFILE. In the child, we 173 // the high bit of the 1st char of CPUPROFILE. In the child, we
174 // notice the high bit is set and append the pid(). This works 174 // notice the high bit is set and append the pid(). This works
175 // assuming cpuprofile filenames don't normally have the high bit set 175 // assuming cpuprofile filenames don't normally have the high bit set
176 // in their first character! If that assumption is violated, we'll 176 // in their first character! If that assumption is violated, we'll
177 // still get a profile, but one with an unexpected name. 177 // still get a profile, but one with an unexpected name.
178 // TODO(csilvers): set an envvar instead when we can do it reliably. 178 // TODO(csilvers): set an envvar instead when we can do it reliably.
179 //
180 // In Chromium this hack is intentionally disabled, because the path is not
181 // re-initialized upon fork.
179 bool GetUniquePathFromEnv(const char* env_name, char* path) { 182 bool GetUniquePathFromEnv(const char* env_name, char* path) {
180 char* envval = getenv(env_name); 183 char* envval = getenv(env_name);
181 if (envval == NULL || *envval == '\0') 184 if (envval == NULL || *envval == '\0')
182 return false; 185 return false;
183 if (envval[0] & 128) { // high bit is set 186 if (envval[0] & 128) { // high bit is set
184 snprintf(path, PATH_MAX, "%c%s_%u", // add pid and clear high bit 187 snprintf(path, PATH_MAX, "%c%s_%u", // add pid and clear high bit
185 envval[0] & 127, envval+1, (unsigned int)(getpid())); 188 envval[0] & 127, envval+1, (unsigned int)(getpid()));
186 } else { 189 } else {
187 snprintf(path, PATH_MAX, "%s", envval); 190 snprintf(path, PATH_MAX, "%s", envval);
188 envval[0] |= 128; // set high bit for kids to see 191 #if 0
192 envval[0] |= 128; // set high bit for kids to seed
willchan no longer on Chromium 2011/05/20 21:26:06 seed? is that a typo?
Alexander Potapenko 2011/05/23 09:45:01 Done.
193 #endif
189 } 194 }
190 return true; 195 return true;
191 } 196 }
192 197
193 // ---------------------------------------------------------------------- 198 // ----------------------------------------------------------------------
194 // CyclesPerSecond() 199 // CyclesPerSecond()
195 // NumCPUs() 200 // NumCPUs()
196 // It's important this not call malloc! -- they may be called at 201 // It's important this not call malloc! -- they may be called at
197 // global-construct time, before we've set up all our proper malloc 202 // global-construct time, before we've set up all our proper malloc
198 // hooks and such. 203 // hooks and such.
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 ProcMapsIterator::Buffer linebuf; 913 ProcMapsIterator::Buffer linebuf;
909 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { 914 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) {
910 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), 915 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_),
911 start, end, flags, offset, inode, filename, 916 start, end, flags, offset, inode, filename,
912 0); 917 0);
913 RawWrite(fd, linebuf.buf_, written); 918 RawWrite(fd, linebuf.buf_, written);
914 } 919 }
915 } 920 }
916 921
917 } // namespace tcmalloc 922 } // namespace tcmalloc
OLDNEW
« no previous file with comments | « no previous file | third_party/tcmalloc/chromium/src/heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698