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

Side by Side Diff: third_party/tcmalloc/chromium/src/thread_cache.h

Issue 9212025: Support use of third party time function to profiler (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2008, Google Inc. 1 // Copyright (c) 2008, 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 void Scavenge(); 90 void Scavenge();
91 void Print(TCMalloc_Printer* out) const; 91 void Print(TCMalloc_Printer* out) const;
92 92
93 int GetSamplePeriod(); 93 int GetSamplePeriod();
94 94
95 // Record allocation of "k" bytes. Return true iff allocation 95 // Record allocation of "k" bytes. Return true iff allocation
96 // should be sampled 96 // should be sampled
97 bool SampleAllocation(size_t k); 97 bool SampleAllocation(size_t k);
98 98
99 // Record additional bytes allocated.
100 void AddToByteAllocatedTotal(size_t k) { total_bytes_allocated_ += k; }
101
102 // Return the total number of bytes allocated from this heap. The value will
103 // wrap when there is an overflow, and so only the differences between two
104 // values should be relied on (and even then, modulo 2^32).
105 uint32 GetTotalBytesAllocated() const;
106
107 // On the current thread, return GetTotalBytesAllocated().
108 static uint32 GetBytesAllocatedOnCurrentThread();
109
99 static void InitModule(); 110 static void InitModule();
100 static void InitTSD(); 111 static void InitTSD();
101 static ThreadCache* GetThreadHeap(); 112 static ThreadCache* GetThreadHeap();
102 static ThreadCache* GetCache(); 113 static ThreadCache* GetCache();
103 static ThreadCache* GetCacheIfPresent(); 114 static ThreadCache* GetCacheIfPresent();
104 static ThreadCache* CreateCacheIfNecessary(); 115 static ThreadCache* CreateCacheIfNecessary();
105 static void BecomeIdle(); 116 static void BecomeIdle();
106 117
107 // Return the number of thread heaps in use. 118 // Return the number of thread heaps in use.
108 static inline int HeapsInUse(); 119 static inline int HeapsInUse();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // Represents overall_thread_cache_size_ minus the sum of max_size_ 295 // Represents overall_thread_cache_size_ minus the sum of max_size_
285 // across all ThreadCaches. Protected by Static::pageheap_lock. 296 // across all ThreadCaches. Protected by Static::pageheap_lock.
286 static ssize_t unclaimed_cache_space_; 297 static ssize_t unclaimed_cache_space_;
287 298
288 // This class is laid out with the most frequently used fields 299 // This class is laid out with the most frequently used fields
289 // first so that hot elements are placed on the same cache line. 300 // first so that hot elements are placed on the same cache line.
290 301
291 size_t size_; // Combined size of data 302 size_t size_; // Combined size of data
292 size_t max_size_; // size_ > max_size_ --> Scavenge() 303 size_t max_size_; // size_ > max_size_ --> Scavenge()
293 304
305 // Chromium profiling.
willchan no longer on Chromium 2012/02/15 01:29:56 You should comment more what this is. In particula
jar (doing other things) 2012/02/15 02:05:08 Done.
306 uint32 total_bytes_allocated_; // Total, modulo 2^32.
307
294 // We sample allocations, biased by the size of the allocation 308 // We sample allocations, biased by the size of the allocation
295 Sampler sampler_; // A sampler 309 Sampler sampler_; // A sampler
296 310
297 FreeList list_[kNumClasses]; // Array indexed by size-class 311 FreeList list_[kNumClasses]; // Array indexed by size-class
298 312
299 pthread_t tid_; // Which thread owns it 313 pthread_t tid_; // Which thread owns it
300 bool in_setspecific_; // In call to pthread_setspecific? 314 bool in_setspecific_; // In call to pthread_setspecific?
301 315
302 // Allocate a new heap. REQUIRES: Static::pageheap_lock is held. 316 // Allocate a new heap. REQUIRES: Static::pageheap_lock is held.
303 static ThreadCache* NewHeap(pthread_t tid); 317 static ThreadCache* NewHeap(pthread_t tid);
(...skipping 16 matching lines...) Expand all
320 extern PageHeapAllocator<ThreadCache> threadcache_allocator; 334 extern PageHeapAllocator<ThreadCache> threadcache_allocator;
321 335
322 inline int ThreadCache::HeapsInUse() { 336 inline int ThreadCache::HeapsInUse() {
323 return threadcache_allocator.inuse(); 337 return threadcache_allocator.inuse();
324 } 338 }
325 339
326 inline bool ThreadCache::SampleAllocation(size_t k) { 340 inline bool ThreadCache::SampleAllocation(size_t k) {
327 return sampler_.SampleAllocation(k); 341 return sampler_.SampleAllocation(k);
328 } 342 }
329 343
344 inline uint32 ThreadCache::GetTotalBytesAllocated() const {
345 return total_bytes_allocated_;
346 }
347
330 inline void* ThreadCache::Allocate(size_t size, size_t cl) { 348 inline void* ThreadCache::Allocate(size_t size, size_t cl) {
331 ASSERT(size <= kMaxSize); 349 ASSERT(size <= kMaxSize);
332 ASSERT(size == Static::sizemap()->ByteSizeForClass(cl)); 350 ASSERT(size == Static::sizemap()->ByteSizeForClass(cl));
333 351
334 FreeList* list = &list_[cl]; 352 FreeList* list = &list_[cl];
335 if (list->empty()) { 353 if (list->empty()) {
336 return FetchFromCentralCache(cl, size); 354 return FetchFromCentralCache(cl, size);
337 } 355 }
338 size_ -= size; 356 size_ -= size;
339 return list->Pop(); 357 return list->Pop();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // because we may be in the thread destruction code and may have 401 // because we may be in the thread destruction code and may have
384 // already cleaned up the cache for this thread. 402 // already cleaned up the cache for this thread.
385 inline ThreadCache* ThreadCache::GetCacheIfPresent() { 403 inline ThreadCache* ThreadCache::GetCacheIfPresent() {
386 if (!tsd_inited_) return NULL; 404 if (!tsd_inited_) return NULL;
387 return GetThreadHeap(); 405 return GetThreadHeap();
388 } 406 }
389 407
390 } // namespace tcmalloc 408 } // namespace tcmalloc
391 409
392 #endif // TCMALLOC_THREAD_CACHE_H_ 410 #endif // TCMALLOC_THREAD_CACHE_H_
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/tcmalloc.cc ('k') | third_party/tcmalloc/chromium/src/thread_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698