You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by hb...@apache.org on 2017/01/17 19:31:10 UTC
[16/51] [partial] incubator-quickstep git commit: Added shell script
to download prerequisite third party libs
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/heap-profile-stats.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/heap-profile-stats.h b/third_party/gperftools/src/heap-profile-stats.h
deleted file mode 100644
index ae45d58..0000000
--- a/third_party/gperftools/src/heap-profile-stats.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2013, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// This file defines structs to accumulate memory allocation and deallocation
-// counts. These structs are commonly used for malloc (in HeapProfileTable)
-// and mmap (in MemoryRegionMap).
-
-// A bucket is data structure for heap profiling to store a pair of a stack
-// trace and counts of (de)allocation. Buckets are stored in a hash table
-// which is declared as "HeapProfileBucket**".
-//
-// A hash value is computed from a stack trace. Collision in the hash table
-// is resolved by separate chaining with linked lists. The links in the list
-// are implemented with the member "HeapProfileBucket* next".
-//
-// A structure of a hash table HeapProfileBucket** bucket_table would be like:
-// bucket_table[0] => NULL
-// bucket_table[1] => HeapProfileBucket() => HeapProfileBucket() => NULL
-// ...
-// bucket_table[i] => HeapProfileBucket() => NULL
-// ...
-// bucket_table[n] => HeapProfileBucket() => NULL
-
-#ifndef HEAP_PROFILE_STATS_H_
-#define HEAP_PROFILE_STATS_H_
-
-struct HeapProfileStats {
- // Returns true if the two HeapProfileStats are semantically equal.
- bool Equivalent(const HeapProfileStats& other) const {
- return allocs - frees == other.allocs - other.frees &&
- alloc_size - free_size == other.alloc_size - other.free_size;
- }
-
- int32 allocs; // Number of allocation calls.
- int32 frees; // Number of free calls.
- int64 alloc_size; // Total size of all allocated objects so far.
- int64 free_size; // Total size of all freed objects so far.
-};
-
-// Allocation and deallocation statistics per each stack trace.
-struct HeapProfileBucket : public HeapProfileStats {
- // Longest stack trace we record.
- static const int kMaxStackDepth = 32;
-
- uintptr_t hash; // Hash value of the stack trace.
- int depth; // Depth of stack trace.
- const void** stack; // Stack trace.
- HeapProfileBucket* next; // Next entry in hash-table.
-};
-
-#endif // HEAP_PROFILE_STATS_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/heap-profile-table.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/heap-profile-table.cc b/third_party/gperftools/src/heap-profile-table.cc
deleted file mode 100644
index 5191afb..0000000
--- a/third_party/gperftools/src/heap-profile-table.cc
+++ /dev/null
@@ -1,625 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2006, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-// Maxim Lifantsev (refactoring)
-//
-
-#include <config.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> // for write()
-#endif
-#include <fcntl.h> // for open()
-#ifdef HAVE_GLOB_H
-#include <glob.h>
-#ifndef GLOB_NOMATCH // true on some old cygwins
-# define GLOB_NOMATCH 0
-#endif
-#endif
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h> // for PRIxPTR
-#endif
-#ifdef HAVE_POLL_H
-#include <poll.h>
-#endif
-#include <errno.h>
-#include <stdarg.h>
-#include <string>
-#include <map>
-#include <algorithm> // for sort(), equal(), and copy()
-
-#include "heap-profile-table.h"
-
-#include "base/logging.h"
-#include "raw_printer.h"
-#include "symbolize.h"
-#include <gperftools/stacktrace.h>
-#include <gperftools/malloc_hook.h>
-#include "memory_region_map.h"
-#include "base/commandlineflags.h"
-#include "base/logging.h" // for the RawFD I/O commands
-#include "base/sysinfo.h"
-
-using std::sort;
-using std::equal;
-using std::copy;
-using std::string;
-using std::map;
-
-using tcmalloc::FillProcSelfMaps; // from sysinfo.h
-using tcmalloc::DumpProcSelfMaps; // from sysinfo.h
-
-//----------------------------------------------------------------------
-
-DEFINE_bool(cleanup_old_heap_profiles,
- EnvToBool("HEAP_PROFILE_CLEANUP", true),
- "At initialization time, delete old heap profiles.");
-
-DEFINE_int32(heap_check_max_leaks,
- EnvToInt("HEAP_CHECK_MAX_LEAKS", 20),
- "The maximum number of leak reports to print.");
-
-//----------------------------------------------------------------------
-
-// header of the dumped heap profile
-static const char kProfileHeader[] = "heap profile: ";
-static const char kProcSelfMapsHeader[] = "\nMAPPED_LIBRARIES:\n";
-
-//----------------------------------------------------------------------
-
-const char HeapProfileTable::kFileExt[] = ".heap";
-
-//----------------------------------------------------------------------
-
-static const int kHashTableSize = 179999; // Size for bucket_table_.
-/*static*/ const int HeapProfileTable::kMaxStackDepth;
-
-//----------------------------------------------------------------------
-
-// We strip out different number of stack frames in debug mode
-// because less inlining happens in that case
-#ifdef NDEBUG
-static const int kStripFrames = 2;
-#else
-static const int kStripFrames = 3;
-#endif
-
-// For sorting Stats or Buckets by in-use space
-static bool ByAllocatedSpace(HeapProfileTable::Stats* a,
- HeapProfileTable::Stats* b) {
- // Return true iff "a" has more allocated space than "b"
- return (a->alloc_size - a->free_size) > (b->alloc_size - b->free_size);
-}
-
-//----------------------------------------------------------------------
-
-HeapProfileTable::HeapProfileTable(Allocator alloc,
- DeAllocator dealloc,
- bool profile_mmap)
- : alloc_(alloc),
- dealloc_(dealloc),
- profile_mmap_(profile_mmap),
- bucket_table_(NULL),
- num_buckets_(0),
- address_map_(NULL) {
- // Make a hash table for buckets.
- const int table_bytes = kHashTableSize * sizeof(*bucket_table_);
- bucket_table_ = static_cast<Bucket**>(alloc_(table_bytes));
- memset(bucket_table_, 0, table_bytes);
-
- // Make an allocation map.
- address_map_ =
- new(alloc_(sizeof(AllocationMap))) AllocationMap(alloc_, dealloc_);
-
- // Initialize.
- memset(&total_, 0, sizeof(total_));
- num_buckets_ = 0;
-}
-
-HeapProfileTable::~HeapProfileTable() {
- // Free the allocation map.
- address_map_->~AllocationMap();
- dealloc_(address_map_);
- address_map_ = NULL;
-
- // Free the hash table.
- for (int i = 0; i < kHashTableSize; i++) {
- for (Bucket* curr = bucket_table_[i]; curr != 0; /**/) {
- Bucket* bucket = curr;
- curr = curr->next;
- dealloc_(bucket->stack);
- dealloc_(bucket);
- }
- }
- dealloc_(bucket_table_);
- bucket_table_ = NULL;
-}
-
-HeapProfileTable::Bucket* HeapProfileTable::GetBucket(int depth,
- const void* const key[]) {
- // Make hash-value
- uintptr_t h = 0;
- for (int i = 0; i < depth; i++) {
- h += reinterpret_cast<uintptr_t>(key[i]);
- h += h << 10;
- h ^= h >> 6;
- }
- h += h << 3;
- h ^= h >> 11;
-
- // Lookup stack trace in table
- unsigned int buck = ((unsigned int) h) % kHashTableSize;
- for (Bucket* b = bucket_table_[buck]; b != 0; b = b->next) {
- if ((b->hash == h) &&
- (b->depth == depth) &&
- equal(key, key + depth, b->stack)) {
- return b;
- }
- }
-
- // Create new bucket
- const size_t key_size = sizeof(key[0]) * depth;
- const void** kcopy = reinterpret_cast<const void**>(alloc_(key_size));
- copy(key, key + depth, kcopy);
- Bucket* b = reinterpret_cast<Bucket*>(alloc_(sizeof(Bucket)));
- memset(b, 0, sizeof(*b));
- b->hash = h;
- b->depth = depth;
- b->stack = kcopy;
- b->next = bucket_table_[buck];
- bucket_table_[buck] = b;
- num_buckets_++;
- return b;
-}
-
-int HeapProfileTable::GetCallerStackTrace(
- int skip_count, void* stack[kMaxStackDepth]) {
- return MallocHook::GetCallerStackTrace(
- stack, kMaxStackDepth, kStripFrames + skip_count + 1);
-}
-
-void HeapProfileTable::RecordAlloc(
- const void* ptr, size_t bytes, int stack_depth,
- const void* const call_stack[]) {
- Bucket* b = GetBucket(stack_depth, call_stack);
- b->allocs++;
- b->alloc_size += bytes;
- total_.allocs++;
- total_.alloc_size += bytes;
-
- AllocValue v;
- v.set_bucket(b); // also did set_live(false); set_ignore(false)
- v.bytes = bytes;
- address_map_->Insert(ptr, v);
-}
-
-void HeapProfileTable::RecordFree(const void* ptr) {
- AllocValue v;
- if (address_map_->FindAndRemove(ptr, &v)) {
- Bucket* b = v.bucket();
- b->frees++;
- b->free_size += v.bytes;
- total_.frees++;
- total_.free_size += v.bytes;
- }
-}
-
-bool HeapProfileTable::FindAlloc(const void* ptr, size_t* object_size) const {
- const AllocValue* alloc_value = address_map_->Find(ptr);
- if (alloc_value != NULL) *object_size = alloc_value->bytes;
- return alloc_value != NULL;
-}
-
-bool HeapProfileTable::FindAllocDetails(const void* ptr,
- AllocInfo* info) const {
- const AllocValue* alloc_value = address_map_->Find(ptr);
- if (alloc_value != NULL) {
- info->object_size = alloc_value->bytes;
- info->call_stack = alloc_value->bucket()->stack;
- info->stack_depth = alloc_value->bucket()->depth;
- }
- return alloc_value != NULL;
-}
-
-bool HeapProfileTable::FindInsideAlloc(const void* ptr,
- size_t max_size,
- const void** object_ptr,
- size_t* object_size) const {
- const AllocValue* alloc_value =
- address_map_->FindInside(&AllocValueSize, max_size, ptr, object_ptr);
- if (alloc_value != NULL) *object_size = alloc_value->bytes;
- return alloc_value != NULL;
-}
-
-bool HeapProfileTable::MarkAsLive(const void* ptr) {
- AllocValue* alloc = address_map_->FindMutable(ptr);
- if (alloc && !alloc->live()) {
- alloc->set_live(true);
- return true;
- }
- return false;
-}
-
-void HeapProfileTable::MarkAsIgnored(const void* ptr) {
- AllocValue* alloc = address_map_->FindMutable(ptr);
- if (alloc) {
- alloc->set_ignore(true);
- }
-}
-
-// We'd be happier using snprintfer, but we don't to reduce dependencies.
-int HeapProfileTable::UnparseBucket(const Bucket& b,
- char* buf, int buflen, int bufsize,
- const char* extra,
- Stats* profile_stats) {
- if (profile_stats != NULL) {
- profile_stats->allocs += b.allocs;
- profile_stats->alloc_size += b.alloc_size;
- profile_stats->frees += b.frees;
- profile_stats->free_size += b.free_size;
- }
- int printed =
- snprintf(buf + buflen, bufsize - buflen, "%6d: %8" PRId64 " [%6d: %8" PRId64 "] @%s",
- b.allocs - b.frees,
- b.alloc_size - b.free_size,
- b.allocs,
- b.alloc_size,
- extra);
- // If it looks like the snprintf failed, ignore the fact we printed anything
- if (printed < 0 || printed >= bufsize - buflen) return buflen;
- buflen += printed;
- for (int d = 0; d < b.depth; d++) {
- printed = snprintf(buf + buflen, bufsize - buflen, " 0x%08" PRIxPTR,
- reinterpret_cast<uintptr_t>(b.stack[d]));
- if (printed < 0 || printed >= bufsize - buflen) return buflen;
- buflen += printed;
- }
- printed = snprintf(buf + buflen, bufsize - buflen, "\n");
- if (printed < 0 || printed >= bufsize - buflen) return buflen;
- buflen += printed;
- return buflen;
-}
-
-HeapProfileTable::Bucket**
-HeapProfileTable::MakeSortedBucketList() const {
- Bucket** list = static_cast<Bucket**>(alloc_(sizeof(Bucket) * num_buckets_));
-
- int bucket_count = 0;
- for (int i = 0; i < kHashTableSize; i++) {
- for (Bucket* curr = bucket_table_[i]; curr != 0; curr = curr->next) {
- list[bucket_count++] = curr;
- }
- }
- RAW_DCHECK(bucket_count == num_buckets_, "");
-
- sort(list, list + num_buckets_, ByAllocatedSpace);
-
- return list;
-}
-
-void HeapProfileTable::IterateOrderedAllocContexts(
- AllocContextIterator callback) const {
- Bucket** list = MakeSortedBucketList();
- AllocContextInfo info;
- for (int i = 0; i < num_buckets_; ++i) {
- *static_cast<Stats*>(&info) = *static_cast<Stats*>(list[i]);
- info.stack_depth = list[i]->depth;
- info.call_stack = list[i]->stack;
- callback(info);
- }
- dealloc_(list);
-}
-
-int HeapProfileTable::FillOrderedProfile(char buf[], int size) const {
- Bucket** list = MakeSortedBucketList();
-
- // Our file format is "bucket, bucket, ..., bucket, proc_self_maps_info".
- // In the cases buf is too small, we'd rather leave out the last
- // buckets than leave out the /proc/self/maps info. To ensure that,
- // we actually print the /proc/self/maps info first, then move it to
- // the end of the buffer, then write the bucket info into whatever
- // is remaining, and then move the maps info one last time to close
- // any gaps. Whew!
- int map_length = snprintf(buf, size, "%s", kProcSelfMapsHeader);
- if (map_length < 0 || map_length >= size) return 0;
- bool dummy; // "wrote_all" -- did /proc/self/maps fit in its entirety?
- map_length += FillProcSelfMaps(buf + map_length, size - map_length, &dummy);
- RAW_DCHECK(map_length <= size, "");
- char* const map_start = buf + size - map_length; // move to end
- memmove(map_start, buf, map_length);
- size -= map_length;
-
- Stats stats;
- memset(&stats, 0, sizeof(stats));
- int bucket_length = snprintf(buf, size, "%s", kProfileHeader);
- if (bucket_length < 0 || bucket_length >= size) return 0;
- bucket_length = UnparseBucket(total_, buf, bucket_length, size,
- " heapprofile", &stats);
-
- // Dump the mmap list first.
- if (profile_mmap_) {
- BufferArgs buffer(buf, bucket_length, size);
- MemoryRegionMap::IterateBuckets<BufferArgs*>(DumpBucketIterator, &buffer);
- bucket_length = buffer.buflen;
- }
-
- for (int i = 0; i < num_buckets_; i++) {
- bucket_length = UnparseBucket(*list[i], buf, bucket_length, size, "",
- &stats);
- }
- RAW_DCHECK(bucket_length < size, "");
-
- dealloc_(list);
-
- RAW_DCHECK(buf + bucket_length <= map_start, "");
- memmove(buf + bucket_length, map_start, map_length); // close the gap
-
- return bucket_length + map_length;
-}
-
-// static
-void HeapProfileTable::DumpBucketIterator(const Bucket* bucket,
- BufferArgs* args) {
- args->buflen = UnparseBucket(*bucket, args->buf, args->buflen, args->bufsize,
- "", NULL);
-}
-
-inline
-void HeapProfileTable::DumpNonLiveIterator(const void* ptr, AllocValue* v,
- const DumpArgs& args) {
- if (v->live()) {
- v->set_live(false);
- return;
- }
- if (v->ignore()) {
- return;
- }
- Bucket b;
- memset(&b, 0, sizeof(b));
- b.allocs = 1;
- b.alloc_size = v->bytes;
- b.depth = v->bucket()->depth;
- b.stack = v->bucket()->stack;
- char buf[1024];
- int len = UnparseBucket(b, buf, 0, sizeof(buf), "", args.profile_stats);
- RawWrite(args.fd, buf, len);
-}
-
-// Callback from NonLiveSnapshot; adds entry to arg->dest
-// if not the entry is not live and is not present in arg->base.
-void HeapProfileTable::AddIfNonLive(const void* ptr, AllocValue* v,
- AddNonLiveArgs* arg) {
- if (v->live()) {
- v->set_live(false);
- } else {
- if (arg->base != NULL && arg->base->map_.Find(ptr) != NULL) {
- // Present in arg->base, so do not save
- } else {
- arg->dest->Add(ptr, *v);
- }
- }
-}
-
-bool HeapProfileTable::WriteProfile(const char* file_name,
- const Bucket& total,
- AllocationMap* allocations) {
- RAW_VLOG(1, "Dumping non-live heap profile to %s", file_name);
- RawFD fd = RawOpenForWriting(file_name);
- if (fd != kIllegalRawFD) {
- RawWrite(fd, kProfileHeader, strlen(kProfileHeader));
- char buf[512];
- int len = UnparseBucket(total, buf, 0, sizeof(buf), " heapprofile",
- NULL);
- RawWrite(fd, buf, len);
- const DumpArgs args(fd, NULL);
- allocations->Iterate<const DumpArgs&>(DumpNonLiveIterator, args);
- RawWrite(fd, kProcSelfMapsHeader, strlen(kProcSelfMapsHeader));
- DumpProcSelfMaps(fd);
- RawClose(fd);
- return true;
- } else {
- RAW_LOG(ERROR, "Failed dumping filtered heap profile to %s", file_name);
- return false;
- }
-}
-
-void HeapProfileTable::CleanupOldProfiles(const char* prefix) {
- if (!FLAGS_cleanup_old_heap_profiles)
- return;
- string pattern = string(prefix) + ".*" + kFileExt;
-#if defined(HAVE_GLOB_H)
- glob_t g;
- const int r = glob(pattern.c_str(), GLOB_ERR, NULL, &g);
- if (r == 0 || r == GLOB_NOMATCH) {
- const int prefix_length = strlen(prefix);
- for (int i = 0; i < g.gl_pathc; i++) {
- const char* fname = g.gl_pathv[i];
- if ((strlen(fname) >= prefix_length) &&
- (memcmp(fname, prefix, prefix_length) == 0)) {
- RAW_VLOG(1, "Removing old heap profile %s", fname);
- unlink(fname);
- }
- }
- }
- globfree(&g);
-#else /* HAVE_GLOB_H */
- RAW_LOG(WARNING, "Unable to remove old heap profiles (can't run glob())");
-#endif
-}
-
-HeapProfileTable::Snapshot* HeapProfileTable::TakeSnapshot() {
- Snapshot* s = new (alloc_(sizeof(Snapshot))) Snapshot(alloc_, dealloc_);
- address_map_->Iterate(AddToSnapshot, s);
- return s;
-}
-
-void HeapProfileTable::ReleaseSnapshot(Snapshot* s) {
- s->~Snapshot();
- dealloc_(s);
-}
-
-// Callback from TakeSnapshot; adds a single entry to snapshot
-void HeapProfileTable::AddToSnapshot(const void* ptr, AllocValue* v,
- Snapshot* snapshot) {
- snapshot->Add(ptr, *v);
-}
-
-HeapProfileTable::Snapshot* HeapProfileTable::NonLiveSnapshot(
- Snapshot* base) {
- RAW_VLOG(2, "NonLiveSnapshot input: %d %d\n",
- int(total_.allocs - total_.frees),
- int(total_.alloc_size - total_.free_size));
-
- Snapshot* s = new (alloc_(sizeof(Snapshot))) Snapshot(alloc_, dealloc_);
- AddNonLiveArgs args;
- args.dest = s;
- args.base = base;
- address_map_->Iterate<AddNonLiveArgs*>(AddIfNonLive, &args);
- RAW_VLOG(2, "NonLiveSnapshot output: %d %d\n",
- int(s->total_.allocs - s->total_.frees),
- int(s->total_.alloc_size - s->total_.free_size));
- return s;
-}
-
-// Information kept per unique bucket seen
-struct HeapProfileTable::Snapshot::Entry {
- int count;
- int bytes;
- Bucket* bucket;
- Entry() : count(0), bytes(0) { }
-
- // Order by decreasing bytes
- bool operator<(const Entry& x) const {
- return this->bytes > x.bytes;
- }
-};
-
-// State used to generate leak report. We keep a mapping from Bucket pointer
-// the collected stats for that bucket.
-struct HeapProfileTable::Snapshot::ReportState {
- map<Bucket*, Entry> buckets_;
-};
-
-// Callback from ReportLeaks; updates ReportState.
-void HeapProfileTable::Snapshot::ReportCallback(const void* ptr,
- AllocValue* v,
- ReportState* state) {
- Entry* e = &state->buckets_[v->bucket()]; // Creates empty Entry first time
- e->bucket = v->bucket();
- e->count++;
- e->bytes += v->bytes;
-}
-
-void HeapProfileTable::Snapshot::ReportLeaks(const char* checker_name,
- const char* filename,
- bool should_symbolize) {
- // This is only used by the heap leak checker, but is intimately
- // tied to the allocation map that belongs in this module and is
- // therefore placed here.
- RAW_LOG(ERROR, "Leak check %s detected leaks of %" PRIuS " bytes "
- "in %" PRIuS " objects",
- checker_name,
- size_t(total_.alloc_size),
- size_t(total_.allocs));
-
- // Group objects by Bucket
- ReportState state;
- map_.Iterate(&ReportCallback, &state);
-
- // Sort buckets by decreasing leaked size
- const int n = state.buckets_.size();
- Entry* entries = new Entry[n];
- int dst = 0;
- for (map<Bucket*,Entry>::const_iterator iter = state.buckets_.begin();
- iter != state.buckets_.end();
- ++iter) {
- entries[dst++] = iter->second;
- }
- sort(entries, entries + n);
-
- // Report a bounded number of leaks to keep the leak report from
- // growing too long.
- const int to_report =
- (FLAGS_heap_check_max_leaks > 0 &&
- n > FLAGS_heap_check_max_leaks) ? FLAGS_heap_check_max_leaks : n;
- RAW_LOG(ERROR, "The %d largest leaks:", to_report);
-
- // Print
- SymbolTable symbolization_table;
- for (int i = 0; i < to_report; i++) {
- const Entry& e = entries[i];
- for (int j = 0; j < e.bucket->depth; j++) {
- symbolization_table.Add(e.bucket->stack[j]);
- }
- }
- static const int kBufSize = 2<<10;
- char buffer[kBufSize];
- if (should_symbolize)
- symbolization_table.Symbolize();
- for (int i = 0; i < to_report; i++) {
- const Entry& e = entries[i];
- base::RawPrinter printer(buffer, kBufSize);
- printer.Printf("Leak of %d bytes in %d objects allocated from:\n",
- e.bytes, e.count);
- for (int j = 0; j < e.bucket->depth; j++) {
- const void* pc = e.bucket->stack[j];
- printer.Printf("\t@ %" PRIxPTR " %s\n",
- reinterpret_cast<uintptr_t>(pc), symbolization_table.GetSymbol(pc));
- }
- RAW_LOG(ERROR, "%s", buffer);
- }
-
- if (to_report < n) {
- RAW_LOG(ERROR, "Skipping leaks numbered %d..%d",
- to_report, n-1);
- }
- delete[] entries;
-
- // TODO: Dump the sorted Entry list instead of dumping raw data?
- // (should be much shorter)
- if (!HeapProfileTable::WriteProfile(filename, total_, &map_)) {
- RAW_LOG(ERROR, "Could not write pprof profile to %s", filename);
- }
-}
-
-void HeapProfileTable::Snapshot::ReportObject(const void* ptr,
- AllocValue* v,
- char* unused) {
- // Perhaps also log the allocation stack trace (unsymbolized)
- // on this line in case somebody finds it useful.
- RAW_LOG(ERROR, "leaked %" PRIuS " byte object %p", v->bytes, ptr);
-}
-
-void HeapProfileTable::Snapshot::ReportIndividualObjects() {
- char unused;
- map_.Iterate(ReportObject, &unused);
-}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/heap-profile-table.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/heap-profile-table.h b/third_party/gperftools/src/heap-profile-table.h
deleted file mode 100644
index 3c62847..0000000
--- a/third_party/gperftools/src/heap-profile-table.h
+++ /dev/null
@@ -1,399 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2006, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-// Maxim Lifantsev (refactoring)
-//
-
-#ifndef BASE_HEAP_PROFILE_TABLE_H_
-#define BASE_HEAP_PROFILE_TABLE_H_
-
-#include "addressmap-inl.h"
-#include "base/basictypes.h"
-#include "base/logging.h" // for RawFD
-#include "heap-profile-stats.h"
-
-// Table to maintain a heap profile data inside,
-// i.e. the set of currently active heap memory allocations.
-// thread-unsafe and non-reentrant code:
-// each instance object must be used by one thread
-// at a time w/o self-recursion.
-//
-// TODO(maxim): add a unittest for this class.
-class HeapProfileTable {
- public:
-
- // Extension to be used for heap pforile files.
- static const char kFileExt[];
-
- // Longest stack trace we record.
- static const int kMaxStackDepth = 32;
-
- // data types ----------------------------
-
- // Profile stats.
- typedef HeapProfileStats Stats;
-
- // Info we can return about an allocation.
- struct AllocInfo {
- size_t object_size; // size of the allocation
- const void* const* call_stack; // call stack that made the allocation call
- int stack_depth; // depth of call_stack
- bool live;
- bool ignored;
- };
-
- // Info we return about an allocation context.
- // An allocation context is a unique caller stack trace
- // of an allocation operation.
- struct AllocContextInfo : public Stats {
- int stack_depth; // Depth of stack trace
- const void* const* call_stack; // Stack trace
- };
-
- // Memory (de)allocator interface we'll use.
- typedef void* (*Allocator)(size_t size);
- typedef void (*DeAllocator)(void* ptr);
-
- // interface ---------------------------
-
- HeapProfileTable(Allocator alloc, DeAllocator dealloc, bool profile_mmap);
- ~HeapProfileTable();
-
- // Collect the stack trace for the function that asked to do the
- // allocation for passing to RecordAlloc() below.
- //
- // The stack trace is stored in 'stack'. The stack depth is returned.
- //
- // 'skip_count' gives the number of stack frames between this call
- // and the memory allocation function.
- static int GetCallerStackTrace(int skip_count, void* stack[kMaxStackDepth]);
-
- // Record an allocation at 'ptr' of 'bytes' bytes. 'stack_depth'
- // and 'call_stack' identifying the function that requested the
- // allocation. They can be generated using GetCallerStackTrace() above.
- void RecordAlloc(const void* ptr, size_t bytes,
- int stack_depth, const void* const call_stack[]);
-
- // Record the deallocation of memory at 'ptr'.
- void RecordFree(const void* ptr);
-
- // Return true iff we have recorded an allocation at 'ptr'.
- // If yes, fill *object_size with the allocation byte size.
- bool FindAlloc(const void* ptr, size_t* object_size) const;
- // Same as FindAlloc, but fills all of *info.
- bool FindAllocDetails(const void* ptr, AllocInfo* info) const;
-
- // Return true iff "ptr" points into a recorded allocation
- // If yes, fill *object_ptr with the actual allocation address
- // and *object_size with the allocation byte size.
- // max_size specifies largest currently possible allocation size.
- bool FindInsideAlloc(const void* ptr, size_t max_size,
- const void** object_ptr, size_t* object_size) const;
-
- // If "ptr" points to a recorded allocation and it's not marked as live
- // mark it as live and return true. Else return false.
- // All allocations start as non-live.
- bool MarkAsLive(const void* ptr);
-
- // If "ptr" points to a recorded allocation, mark it as "ignored".
- // Ignored objects are treated like other objects, except that they
- // are skipped in heap checking reports.
- void MarkAsIgnored(const void* ptr);
-
- // Return current total (de)allocation statistics. It doesn't contain
- // mmap'ed regions.
- const Stats& total() const { return total_; }
-
- // Allocation data iteration callback: gets passed object pointer and
- // fully-filled AllocInfo.
- typedef void (*AllocIterator)(const void* ptr, const AllocInfo& info);
-
- // Iterate over the allocation profile data calling "callback"
- // for every allocation.
- void IterateAllocs(AllocIterator callback) const {
- address_map_->Iterate(MapArgsAllocIterator, callback);
- }
-
- // Allocation context profile data iteration callback
- typedef void (*AllocContextIterator)(const AllocContextInfo& info);
-
- // Iterate over the allocation context profile data calling "callback"
- // for every allocation context. Allocation contexts are ordered by the
- // size of allocated space.
- void IterateOrderedAllocContexts(AllocContextIterator callback) const;
-
- // Fill profile data into buffer 'buf' of size 'size'
- // and return the actual size occupied by the dump in 'buf'.
- // The profile buckets are dumped in the decreasing order
- // of currently allocated bytes.
- // We do not provision for 0-terminating 'buf'.
- int FillOrderedProfile(char buf[], int size) const;
-
- // Cleanup any old profile files matching prefix + ".*" + kFileExt.
- static void CleanupOldProfiles(const char* prefix);
-
- // Return a snapshot of the current contents of *this.
- // Caller must call ReleaseSnapshot() on result when no longer needed.
- // The result is only valid while this exists and until
- // the snapshot is discarded by calling ReleaseSnapshot().
- class Snapshot;
- Snapshot* TakeSnapshot();
-
- // Release a previously taken snapshot. snapshot must not
- // be used after this call.
- void ReleaseSnapshot(Snapshot* snapshot);
-
- // Return a snapshot of every non-live, non-ignored object in *this.
- // If "base" is non-NULL, skip any objects present in "base".
- // As a side-effect, clears the "live" bit on every live object in *this.
- // Caller must call ReleaseSnapshot() on result when no longer needed.
- Snapshot* NonLiveSnapshot(Snapshot* base);
-
- private:
-
- // data types ----------------------------
-
- // Hash table bucket to hold (de)allocation stats
- // for a given allocation call stack trace.
- typedef HeapProfileBucket Bucket;
-
- // Info stored in the address map
- struct AllocValue {
- // Access to the stack-trace bucket
- Bucket* bucket() const {
- return reinterpret_cast<Bucket*>(bucket_rep & ~uintptr_t(kMask));
- }
- // This also does set_live(false).
- void set_bucket(Bucket* b) { bucket_rep = reinterpret_cast<uintptr_t>(b); }
- size_t bytes; // Number of bytes in this allocation
-
- // Access to the allocation liveness flag (for leak checking)
- bool live() const { return bucket_rep & kLive; }
- void set_live(bool l) {
- bucket_rep = (bucket_rep & ~uintptr_t(kLive)) | (l ? kLive : 0);
- }
-
- // Should this allocation be ignored if it looks like a leak?
- bool ignore() const { return bucket_rep & kIgnore; }
- void set_ignore(bool r) {
- bucket_rep = (bucket_rep & ~uintptr_t(kIgnore)) | (r ? kIgnore : 0);
- }
-
- private:
- // We store a few bits in the bottom bits of bucket_rep.
- // (Alignment is at least four, so we have at least two bits.)
- static const int kLive = 1;
- static const int kIgnore = 2;
- static const int kMask = kLive | kIgnore;
-
- uintptr_t bucket_rep;
- };
-
- // helper for FindInsideAlloc
- static size_t AllocValueSize(const AllocValue& v) { return v.bytes; }
-
- typedef AddressMap<AllocValue> AllocationMap;
-
- // Arguments that need to be passed DumpBucketIterator callback below.
- struct BufferArgs {
- BufferArgs(char* buf_arg, int buflen_arg, int bufsize_arg)
- : buf(buf_arg),
- buflen(buflen_arg),
- bufsize(bufsize_arg) {
- }
-
- char* buf;
- int buflen;
- int bufsize;
-
- DISALLOW_COPY_AND_ASSIGN(BufferArgs);
- };
-
- // Arguments that need to be passed DumpNonLiveIterator callback below.
- struct DumpArgs {
- DumpArgs(RawFD fd_arg, Stats* profile_stats_arg)
- : fd(fd_arg),
- profile_stats(profile_stats_arg) {
- }
-
- RawFD fd; // file to write to
- Stats* profile_stats; // stats to update (may be NULL)
- };
-
- // helpers ----------------------------
-
- // Unparse bucket b and print its portion of profile dump into buf.
- // We return the amount of space in buf that we use. We start printing
- // at buf + buflen, and promise not to go beyond buf + bufsize.
- // We do not provision for 0-terminating 'buf'.
- //
- // If profile_stats is non-NULL, we update *profile_stats by
- // counting bucket b.
- //
- // "extra" is appended to the unparsed bucket. Typically it is empty,
- // but may be set to something like " heapprofile" for the total
- // bucket to indicate the type of the profile.
- static int UnparseBucket(const Bucket& b,
- char* buf, int buflen, int bufsize,
- const char* extra,
- Stats* profile_stats);
-
- // Get the bucket for the caller stack trace 'key' of depth 'depth'
- // creating the bucket if needed.
- Bucket* GetBucket(int depth, const void* const key[]);
-
- // Helper for IterateAllocs to do callback signature conversion
- // from AllocationMap::Iterate to AllocIterator.
- static void MapArgsAllocIterator(const void* ptr, AllocValue* v,
- AllocIterator callback) {
- AllocInfo info;
- info.object_size = v->bytes;
- info.call_stack = v->bucket()->stack;
- info.stack_depth = v->bucket()->depth;
- info.live = v->live();
- info.ignored = v->ignore();
- callback(ptr, info);
- }
-
- // Helper to dump a bucket.
- inline static void DumpBucketIterator(const Bucket* bucket,
- BufferArgs* args);
-
- // Helper for DumpNonLiveProfile to do object-granularity
- // heap profile dumping. It gets passed to AllocationMap::Iterate.
- inline static void DumpNonLiveIterator(const void* ptr, AllocValue* v,
- const DumpArgs& args);
-
- // Helper for IterateOrderedAllocContexts and FillOrderedProfile.
- // Creates a sorted list of Buckets whose length is num_buckets_.
- // The caller is responsible for deallocating the returned list.
- Bucket** MakeSortedBucketList() const;
-
- // Helper for TakeSnapshot. Saves object to snapshot.
- static void AddToSnapshot(const void* ptr, AllocValue* v, Snapshot* s);
-
- // Arguments passed to AddIfNonLive
- struct AddNonLiveArgs {
- Snapshot* dest;
- Snapshot* base;
- };
-
- // Helper for NonLiveSnapshot. Adds the object to the destination
- // snapshot if it is non-live.
- static void AddIfNonLive(const void* ptr, AllocValue* v,
- AddNonLiveArgs* arg);
-
- // Write contents of "*allocations" as a heap profile to
- // "file_name". "total" must contain the total of all entries in
- // "*allocations".
- static bool WriteProfile(const char* file_name,
- const Bucket& total,
- AllocationMap* allocations);
-
- // data ----------------------------
-
- // Memory (de)allocator that we use.
- Allocator alloc_;
- DeAllocator dealloc_;
-
- // Overall profile stats; we use only the Stats part,
- // but make it a Bucket to pass to UnparseBucket.
- Bucket total_;
-
- bool profile_mmap_;
-
- // Bucket hash table for malloc.
- // We hand-craft one instead of using one of the pre-written
- // ones because we do not want to use malloc when operating on the table.
- // It is only few lines of code, so no big deal.
- Bucket** bucket_table_;
- int num_buckets_;
-
- // Map of all currently allocated objects and mapped regions we know about.
- AllocationMap* address_map_;
-
- DISALLOW_COPY_AND_ASSIGN(HeapProfileTable);
-};
-
-class HeapProfileTable::Snapshot {
- public:
- const Stats& total() const { return total_; }
-
- // Report anything in this snapshot as a leak.
- // May use new/delete for temporary storage.
- // If should_symbolize is true, will fork (which is not threadsafe)
- // to turn addresses into symbol names. Set to false for maximum safety.
- // Also writes a heap profile to "filename" that contains
- // all of the objects in this snapshot.
- void ReportLeaks(const char* checker_name, const char* filename,
- bool should_symbolize);
-
- // Report the addresses of all leaked objects.
- // May use new/delete for temporary storage.
- void ReportIndividualObjects();
-
- bool Empty() const {
- return (total_.allocs == 0) && (total_.alloc_size == 0);
- }
-
- private:
- friend class HeapProfileTable;
-
- // Total count/size are stored in a Bucket so we can reuse UnparseBucket
- Bucket total_;
-
- // We share the Buckets managed by the parent table, but have our
- // own object->bucket map.
- AllocationMap map_;
-
- Snapshot(Allocator alloc, DeAllocator dealloc) : map_(alloc, dealloc) {
- memset(&total_, 0, sizeof(total_));
- }
-
- // Callback used to populate a Snapshot object with entries found
- // in another allocation map.
- inline void Add(const void* ptr, const AllocValue& v) {
- map_.Insert(ptr, v);
- total_.allocs++;
- total_.alloc_size += v.bytes;
- }
-
- // Helpers for sorting and generating leak reports
- struct Entry;
- struct ReportState;
- static void ReportCallback(const void* ptr, AllocValue* v, ReportState*);
- static void ReportObject(const void* ptr, AllocValue* v, char*);
-
- DISALLOW_COPY_AND_ASSIGN(Snapshot);
-};
-
-#endif // BASE_HEAP_PROFILE_TABLE_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/heap-profiler.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/heap-profiler.cc b/third_party/gperftools/src/heap-profiler.cc
deleted file mode 100755
index 17d8697..0000000
--- a/third_party/gperftools/src/heap-profiler.cc
+++ /dev/null
@@ -1,620 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-//
-// TODO: Log large allocations
-
-#include <config.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h> // for open()
-#endif
-#ifdef HAVE_MMAP
-#include <sys/mman.h>
-#endif
-#include <errno.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <signal.h>
-
-#include <algorithm>
-#include <string>
-
-#include <gperftools/heap-profiler.h>
-
-#include "base/logging.h"
-#include "base/basictypes.h" // for PRId64, among other things
-#include "base/googleinit.h"
-#include "base/commandlineflags.h"
-#include "malloc_hook-inl.h"
-#include "tcmalloc_guard.h"
-#include <gperftools/malloc_hook.h>
-#include <gperftools/malloc_extension.h>
-#include "base/spinlock.h"
-#include "base/low_level_alloc.h"
-#include "base/sysinfo.h" // for GetUniquePathFromEnv()
-#include "heap-profile-table.h"
-#include "memory_region_map.h"
-
-
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX MAXPATHLEN
-#else
-#define PATH_MAX 4096 // seems conservative for max filename len!
-#endif
-#endif
-
-using STL_NAMESPACE::string;
-using STL_NAMESPACE::sort;
-
-//----------------------------------------------------------------------
-// Flags that control heap-profiling
-//
-// The thread-safety of the profiler depends on these being immutable
-// after main starts, so don't change them.
-//----------------------------------------------------------------------
-
-DEFINE_int64(heap_profile_allocation_interval,
- EnvToInt64("HEAP_PROFILE_ALLOCATION_INTERVAL", 1 << 30 /*1GB*/),
- "If non-zero, dump heap profiling information once every "
- "specified number of bytes allocated by the program since "
- "the last dump.");
-DEFINE_int64(heap_profile_deallocation_interval,
- EnvToInt64("HEAP_PROFILE_DEALLOCATION_INTERVAL", 0),
- "If non-zero, dump heap profiling information once every "
- "specified number of bytes deallocated by the program "
- "since the last dump.");
-// We could also add flags that report whenever inuse_bytes changes by
-// X or -X, but there hasn't been a need for that yet, so we haven't.
-DEFINE_int64(heap_profile_inuse_interval,
- EnvToInt64("HEAP_PROFILE_INUSE_INTERVAL", 100 << 20 /*100MB*/),
- "If non-zero, dump heap profiling information whenever "
- "the high-water memory usage mark increases by the specified "
- "number of bytes.");
-DEFINE_int64(heap_profile_time_interval,
- EnvToInt64("HEAP_PROFILE_TIME_INTERVAL", 0),
- "If non-zero, dump heap profiling information once every "
- "specified number of seconds since the last dump.");
-DEFINE_bool(mmap_log,
- EnvToBool("HEAP_PROFILE_MMAP_LOG", false),
- "Should mmap/munmap calls be logged?");
-DEFINE_bool(mmap_profile,
- EnvToBool("HEAP_PROFILE_MMAP", false),
- "If heap-profiling is on, also profile mmap, mremap, and sbrk)");
-DEFINE_bool(only_mmap_profile,
- EnvToBool("HEAP_PROFILE_ONLY_MMAP", false),
- "If heap-profiling is on, only profile mmap, mremap, and sbrk; "
- "do not profile malloc/new/etc");
-
-
-//----------------------------------------------------------------------
-// Locking
-//----------------------------------------------------------------------
-
-// A pthread_mutex has way too much lock contention to be used here.
-//
-// I would like to use Mutex, but it can call malloc(),
-// which can cause us to fall into an infinite recursion.
-//
-// So we use a simple spinlock.
-static SpinLock heap_lock(SpinLock::LINKER_INITIALIZED);
-
-//----------------------------------------------------------------------
-// Simple allocator for heap profiler's internal memory
-//----------------------------------------------------------------------
-
-static LowLevelAlloc::Arena *heap_profiler_memory;
-
-static void* ProfilerMalloc(size_t bytes) {
- return LowLevelAlloc::AllocWithArena(bytes, heap_profiler_memory);
-}
-static void ProfilerFree(void* p) {
- LowLevelAlloc::Free(p);
-}
-
-// We use buffers of this size in DoGetHeapProfile.
-static const int kProfileBufferSize = 1 << 20;
-
-// This is a last-ditch buffer we use in DumpProfileLocked in case we
-// can't allocate more memory from ProfilerMalloc. We expect this
-// will be used by HeapProfileEndWriter when the application has to
-// exit due to out-of-memory. This buffer is allocated in
-// HeapProfilerStart. Access to this must be protected by heap_lock.
-static char* global_profiler_buffer = NULL;
-
-
-//----------------------------------------------------------------------
-// Profiling control/state data
-//----------------------------------------------------------------------
-
-// Access to all of these is protected by heap_lock.
-static bool is_on = false; // If are on as a subsytem.
-static bool dumping = false; // Dumping status to prevent recursion
-static char* filename_prefix = NULL; // Prefix used for profile file names
- // (NULL if no need for dumping yet)
-static int dump_count = 0; // How many dumps so far
-static int64 last_dump_alloc = 0; // alloc_size when did we last dump
-static int64 last_dump_free = 0; // free_size when did we last dump
-static int64 high_water_mark = 0; // In-use-bytes at last high-water dump
-static int64 last_dump_time = 0; // The time of the last dump
-
-static HeapProfileTable* heap_profile = NULL; // the heap profile table
-
-//----------------------------------------------------------------------
-// Profile generation
-//----------------------------------------------------------------------
-
-// Input must be a buffer of size at least 1MB.
-static char* DoGetHeapProfileLocked(char* buf, int buflen) {
- // We used to be smarter about estimating the required memory and
- // then capping it to 1MB and generating the profile into that.
- if (buf == NULL || buflen < 1)
- return NULL;
-
- RAW_DCHECK(heap_lock.IsHeld(), "");
- int bytes_written = 0;
- if (is_on) {
- HeapProfileTable::Stats const stats = heap_profile->total();
- (void)stats; // avoid an unused-variable warning in non-debug mode.
- bytes_written = heap_profile->FillOrderedProfile(buf, buflen - 1);
- // FillOrderedProfile should not reduce the set of active mmap-ed regions,
- // hence MemoryRegionMap will let us remove everything we've added above:
- RAW_DCHECK(stats.Equivalent(heap_profile->total()), "");
- // if this fails, we somehow removed by FillOrderedProfile
- // more than we have added.
- }
- buf[bytes_written] = '\0';
- RAW_DCHECK(bytes_written == strlen(buf), "");
-
- return buf;
-}
-
-extern "C" char* GetHeapProfile() {
- // Use normal malloc: we return the profile to the user to free it:
- char* buffer = reinterpret_cast<char*>(malloc(kProfileBufferSize));
- SpinLockHolder l(&heap_lock);
- return DoGetHeapProfileLocked(buffer, kProfileBufferSize);
-}
-
-// defined below
-static void NewHook(const void* ptr, size_t size);
-static void DeleteHook(const void* ptr);
-
-// Helper for HeapProfilerDump.
-static void DumpProfileLocked(const char* reason) {
- RAW_DCHECK(heap_lock.IsHeld(), "");
- RAW_DCHECK(is_on, "");
- RAW_DCHECK(!dumping, "");
-
- if (filename_prefix == NULL) return; // we do not yet need dumping
-
- dumping = true;
-
- // Make file name
- char file_name[1000];
- dump_count++;
- snprintf(file_name, sizeof(file_name), "%s.%04d%s",
- filename_prefix, dump_count, HeapProfileTable::kFileExt);
-
- // Dump the profile
- RAW_VLOG(0, "Dumping heap profile to %s (%s)", file_name, reason);
- // We must use file routines that don't access memory, since we hold
- // a memory lock now.
- RawFD fd = RawOpenForWriting(file_name);
- if (fd == kIllegalRawFD) {
- RAW_LOG(ERROR, "Failed dumping heap profile to %s", file_name);
- dumping = false;
- return;
- }
-
- // This case may be impossible, but it's best to be safe.
- // It's safe to use the global buffer: we're protected by heap_lock.
- if (global_profiler_buffer == NULL) {
- global_profiler_buffer =
- reinterpret_cast<char*>(ProfilerMalloc(kProfileBufferSize));
- }
-
- char* profile = DoGetHeapProfileLocked(global_profiler_buffer,
- kProfileBufferSize);
- RawWrite(fd, profile, strlen(profile));
- RawClose(fd);
-
- dumping = false;
-}
-
-//----------------------------------------------------------------------
-// Profile collection
-//----------------------------------------------------------------------
-
-// Dump a profile after either an allocation or deallocation, if
-// the memory use has changed enough since the last dump.
-static void MaybeDumpProfileLocked() {
- if (!dumping) {
- const HeapProfileTable::Stats& total = heap_profile->total();
- const int64 inuse_bytes = total.alloc_size - total.free_size;
- bool need_to_dump = false;
- char buf[128];
- int64 current_time = time(NULL);
- if (FLAGS_heap_profile_allocation_interval > 0 &&
- total.alloc_size >=
- last_dump_alloc + FLAGS_heap_profile_allocation_interval) {
- snprintf(buf, sizeof(buf), ("%" PRId64 " MB allocated cumulatively, "
- "%" PRId64 " MB currently in use"),
- total.alloc_size >> 20, inuse_bytes >> 20);
- need_to_dump = true;
- } else if (FLAGS_heap_profile_deallocation_interval > 0 &&
- total.free_size >=
- last_dump_free + FLAGS_heap_profile_deallocation_interval) {
- snprintf(buf, sizeof(buf), ("%" PRId64 " MB freed cumulatively, "
- "%" PRId64 " MB currently in use"),
- total.free_size >> 20, inuse_bytes >> 20);
- need_to_dump = true;
- } else if (FLAGS_heap_profile_inuse_interval > 0 &&
- inuse_bytes >
- high_water_mark + FLAGS_heap_profile_inuse_interval) {
- snprintf(buf, sizeof(buf), "%" PRId64 " MB currently in use",
- inuse_bytes >> 20);
- need_to_dump = true;
- } else if (FLAGS_heap_profile_time_interval > 0 &&
- current_time - last_dump_time >=
- FLAGS_heap_profile_time_interval) {
- snprintf(buf, sizeof(buf), "%" PRId64 " sec since the last dump",
- current_time - last_dump_time);
- need_to_dump = true;
- last_dump_time = current_time;
- }
- if (need_to_dump) {
- DumpProfileLocked(buf);
-
- last_dump_alloc = total.alloc_size;
- last_dump_free = total.free_size;
- if (inuse_bytes > high_water_mark)
- high_water_mark = inuse_bytes;
- }
- }
-}
-
-// Record an allocation in the profile.
-static void RecordAlloc(const void* ptr, size_t bytes, int skip_count) {
- // Take the stack trace outside the critical section.
- void* stack[HeapProfileTable::kMaxStackDepth];
- int depth = HeapProfileTable::GetCallerStackTrace(skip_count + 1, stack);
- SpinLockHolder l(&heap_lock);
- if (is_on) {
- heap_profile->RecordAlloc(ptr, bytes, depth, stack);
- MaybeDumpProfileLocked();
- }
-}
-
-// Record a deallocation in the profile.
-static void RecordFree(const void* ptr) {
- SpinLockHolder l(&heap_lock);
- if (is_on) {
- heap_profile->RecordFree(ptr);
- MaybeDumpProfileLocked();
- }
-}
-
-//----------------------------------------------------------------------
-// Allocation/deallocation hooks for MallocHook
-//----------------------------------------------------------------------
-
-// static
-void NewHook(const void* ptr, size_t size) {
- if (ptr != NULL) RecordAlloc(ptr, size, 0);
-}
-
-// static
-void DeleteHook(const void* ptr) {
- if (ptr != NULL) RecordFree(ptr);
-}
-
-// TODO(jandrews): Re-enable stack tracing
-#ifdef TODO_REENABLE_STACK_TRACING
-static void RawInfoStackDumper(const char* message, void*) {
- RAW_LOG(INFO, "%.*s", static_cast<int>(strlen(message) - 1), message);
- // -1 is to chop the \n which will be added by RAW_LOG
-}
-#endif
-
-static void MmapHook(const void* result, const void* start, size_t size,
- int prot, int flags, int fd, off_t offset) {
- if (FLAGS_mmap_log) { // log it
- // We use PRIxS not just '%p' to avoid deadlocks
- // in pretty-printing of NULL as "nil".
- // TODO(maxim): instead should use a safe snprintf reimplementation
- RAW_LOG(INFO,
- "mmap(start=0x%" PRIxPTR ", len=%" PRIuS ", prot=0x%x, flags=0x%x, "
- "fd=%d, offset=0x%x) = 0x%" PRIxPTR "",
- (uintptr_t) start, size, prot, flags, fd, (unsigned int) offset,
- (uintptr_t) result);
-#ifdef TODO_REENABLE_STACK_TRACING
- DumpStackTrace(1, RawInfoStackDumper, NULL);
-#endif
- }
-}
-
-static void MremapHook(const void* result, const void* old_addr,
- size_t old_size, size_t new_size,
- int flags, const void* new_addr) {
- if (FLAGS_mmap_log) { // log it
- // We use PRIxS not just '%p' to avoid deadlocks
- // in pretty-printing of NULL as "nil".
- // TODO(maxim): instead should use a safe snprintf reimplementation
- RAW_LOG(INFO,
- "mremap(old_addr=0x%" PRIxPTR ", old_size=%" PRIuS ", "
- "new_size=%" PRIuS ", flags=0x%x, new_addr=0x%" PRIxPTR ") = "
- "0x%" PRIxPTR "",
- (uintptr_t) old_addr, old_size, new_size, flags,
- (uintptr_t) new_addr, (uintptr_t) result);
-#ifdef TODO_REENABLE_STACK_TRACING
- DumpStackTrace(1, RawInfoStackDumper, NULL);
-#endif
- }
-}
-
-static void MunmapHook(const void* ptr, size_t size) {
- if (FLAGS_mmap_log) { // log it
- // We use PRIxS not just '%p' to avoid deadlocks
- // in pretty-printing of NULL as "nil".
- // TODO(maxim): instead should use a safe snprintf reimplementation
- RAW_LOG(INFO, "munmap(start=0x%" PRIxPTR ", len=%" PRIuS ")",
- (uintptr_t) ptr, size);
-#ifdef TODO_REENABLE_STACK_TRACING
- DumpStackTrace(1, RawInfoStackDumper, NULL);
-#endif
- }
-}
-
-static void SbrkHook(const void* result, ptrdiff_t increment) {
- if (FLAGS_mmap_log) { // log it
- RAW_LOG(INFO, "sbrk(inc=%" PRIdS ") = 0x%" PRIxPTR "",
- increment, (uintptr_t) result);
-#ifdef TODO_REENABLE_STACK_TRACING
- DumpStackTrace(1, RawInfoStackDumper, NULL);
-#endif
- }
-}
-
-//----------------------------------------------------------------------
-// Starting/stopping/dumping
-//----------------------------------------------------------------------
-
-extern "C" void HeapProfilerStart(const char* prefix) {
- SpinLockHolder l(&heap_lock);
-
- if (is_on) return;
-
- is_on = true;
-
- RAW_VLOG(0, "Starting tracking the heap");
-
- // This should be done before the hooks are set up, since it should
- // call new, and we want that to be accounted for correctly.
- MallocExtension::Initialize();
-
- if (FLAGS_only_mmap_profile) {
- FLAGS_mmap_profile = true;
- }
-
- if (FLAGS_mmap_profile) {
- // Ask MemoryRegionMap to record all mmap, mremap, and sbrk
- // call stack traces of at least size kMaxStackDepth:
- MemoryRegionMap::Init(HeapProfileTable::kMaxStackDepth,
- /* use_buckets */ true);
- }
-
- if (FLAGS_mmap_log) {
- // Install our hooks to do the logging:
- RAW_CHECK(MallocHook::AddMmapHook(&MmapHook), "");
- RAW_CHECK(MallocHook::AddMremapHook(&MremapHook), "");
- RAW_CHECK(MallocHook::AddMunmapHook(&MunmapHook), "");
- RAW_CHECK(MallocHook::AddSbrkHook(&SbrkHook), "");
- }
-
- heap_profiler_memory =
- LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena());
-
- // Reserve space now for the heap profiler, so we can still write a
- // heap profile even if the application runs out of memory.
- global_profiler_buffer =
- reinterpret_cast<char*>(ProfilerMalloc(kProfileBufferSize));
-
- heap_profile = new(ProfilerMalloc(sizeof(HeapProfileTable)))
- HeapProfileTable(ProfilerMalloc, ProfilerFree, FLAGS_mmap_profile);
-
- last_dump_alloc = 0;
- last_dump_free = 0;
- high_water_mark = 0;
- last_dump_time = 0;
-
- // We do not reset dump_count so if the user does a sequence of
- // HeapProfilerStart/HeapProfileStop, we will get a continuous
- // sequence of profiles.
-
- if (FLAGS_only_mmap_profile == false) {
- // Now set the hooks that capture new/delete and malloc/free.
- RAW_CHECK(MallocHook::AddNewHook(&NewHook), "");
- RAW_CHECK(MallocHook::AddDeleteHook(&DeleteHook), "");
- }
-
- // Copy filename prefix
- RAW_DCHECK(filename_prefix == NULL, "");
- const int prefix_length = strlen(prefix);
- filename_prefix = reinterpret_cast<char*>(ProfilerMalloc(prefix_length + 1));
- memcpy(filename_prefix, prefix, prefix_length);
- filename_prefix[prefix_length] = '\0';
-}
-
-extern "C" int IsHeapProfilerRunning() {
- SpinLockHolder l(&heap_lock);
- return is_on ? 1 : 0; // return an int, because C code doesn't have bool
-}
-
-extern "C" void HeapProfilerStop() {
- SpinLockHolder l(&heap_lock);
-
- if (!is_on) return;
-
- if (FLAGS_only_mmap_profile == false) {
- // Unset our new/delete hooks, checking they were set:
- RAW_CHECK(MallocHook::RemoveNewHook(&NewHook), "");
- RAW_CHECK(MallocHook::RemoveDeleteHook(&DeleteHook), "");
- }
- if (FLAGS_mmap_log) {
- // Restore mmap/sbrk hooks, checking that our hooks were set:
- RAW_CHECK(MallocHook::RemoveMmapHook(&MmapHook), "");
- RAW_CHECK(MallocHook::RemoveMremapHook(&MremapHook), "");
- RAW_CHECK(MallocHook::RemoveSbrkHook(&SbrkHook), "");
- RAW_CHECK(MallocHook::RemoveMunmapHook(&MunmapHook), "");
- }
-
- // free profile
- heap_profile->~HeapProfileTable();
- ProfilerFree(heap_profile);
- heap_profile = NULL;
-
- // free output-buffer memory
- ProfilerFree(global_profiler_buffer);
-
- // free prefix
- ProfilerFree(filename_prefix);
- filename_prefix = NULL;
-
- if (!LowLevelAlloc::DeleteArena(heap_profiler_memory)) {
- RAW_LOG(FATAL, "Memory leak in HeapProfiler:");
- }
-
- if (FLAGS_mmap_profile) {
- MemoryRegionMap::Shutdown();
- }
-
- is_on = false;
-}
-
-extern "C" void HeapProfilerDump(const char *reason) {
- SpinLockHolder l(&heap_lock);
- if (is_on && !dumping) {
- DumpProfileLocked(reason);
- }
-}
-
-// Signal handler that is registered when a user selectable signal
-// number is defined in the environment variable HEAPPROFILESIGNAL.
-static void HeapProfilerDumpSignal(int signal_number) {
- (void)signal_number;
- if (!heap_lock.TryLock()) {
- return;
- }
- if (is_on && !dumping) {
- DumpProfileLocked("signal");
- }
- heap_lock.Unlock();
-}
-
-
-//----------------------------------------------------------------------
-// Initialization/finalization code
-//----------------------------------------------------------------------
-
-// Initialization code
-static void HeapProfilerInit() {
- // Everything after this point is for setting up the profiler based on envvar
- char fname[PATH_MAX];
- if (!GetUniquePathFromEnv("HEAPPROFILE", fname)) {
- return;
- }
- // We do a uid check so we don't write out files in a setuid executable.
-#ifdef HAVE_GETEUID
- if (getuid() != geteuid()) {
- RAW_LOG(WARNING, ("HeapProfiler: ignoring HEAPPROFILE because "
- "program seems to be setuid\n"));
- return;
- }
-#endif
-
- char *signal_number_str = getenv("HEAPPROFILESIGNAL");
- if (signal_number_str != NULL) {
- long int signal_number = strtol(signal_number_str, NULL, 10);
- intptr_t old_signal_handler = reinterpret_cast<intptr_t>(signal(signal_number, HeapProfilerDumpSignal));
- if (old_signal_handler == reinterpret_cast<intptr_t>(SIG_ERR)) {
- RAW_LOG(FATAL, "Failed to set signal. Perhaps signal number %s is invalid\n", signal_number_str);
- } else if (old_signal_handler == 0) {
- RAW_LOG(INFO,"Using signal %d as heap profiling switch", signal_number);
- } else {
- RAW_LOG(FATAL, "Signal %d already in use\n", signal_number);
- }
- }
-
- HeapProfileTable::CleanupOldProfiles(fname);
-
- HeapProfilerStart(fname);
-}
-
-// class used for finalization -- dumps the heap-profile at program exit
-struct HeapProfileEndWriter {
- ~HeapProfileEndWriter() {
- char buf[128];
- if (heap_profile) {
- const HeapProfileTable::Stats& total = heap_profile->total();
- const int64 inuse_bytes = total.alloc_size - total.free_size;
-
- if ((inuse_bytes >> 20) > 0) {
- snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " MB in use"),
- inuse_bytes >> 20);
- } else if ((inuse_bytes >> 10) > 0) {
- snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " kB in use"),
- inuse_bytes >> 10);
- } else {
- snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " bytes in use"),
- inuse_bytes);
- }
- } else {
- snprintf(buf, sizeof(buf), ("Exiting"));
- }
- HeapProfilerDump(buf);
- }
-};
-
-// We want to make sure tcmalloc is up and running before starting the profiler
-static const TCMallocGuard tcmalloc_initializer;
-REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit());
-static HeapProfileEndWriter heap_profile_end_writer;
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/internal_logging.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/internal_logging.cc b/third_party/gperftools/src/internal_logging.cc
deleted file mode 100644
index 4e7fc87..0000000
--- a/third_party/gperftools/src/internal_logging.cc
+++ /dev/null
@@ -1,194 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Sanjay Ghemawat <op...@google.com>
-
-#include <config.h>
-#include "internal_logging.h"
-#include <stdarg.h> // for va_end, va_start
-#include <stdio.h> // for vsnprintf, va_list, etc
-#include <stdlib.h> // for abort
-#include <string.h> // for strlen, memcpy
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> // for write()
-#endif
-
-#include <gperftools/malloc_extension.h>
-#include "base/logging.h" // for perftools_vsnprintf
-#include "base/spinlock.h" // for SpinLockHolder, SpinLock
-
-static const int kLogBufSize = 800;
-
-// Variables for storing crash output. Allocated statically since we
-// may not be able to heap-allocate while crashing.
-static SpinLock crash_lock(base::LINKER_INITIALIZED);
-static bool crashed = false;
-static const int kStatsBufferSize = 16 << 10;
-static char stats_buffer[kStatsBufferSize] = { 0 };
-
-namespace tcmalloc {
-
-static void WriteMessage(const char* msg, int length) {
- write(STDERR_FILENO, msg, length);
-}
-
-void (*log_message_writer)(const char* msg, int length) = WriteMessage;
-
-
-class Logger {
- public:
- bool Add(const LogItem& item);
- bool AddStr(const char* str, int n);
- bool AddNum(uint64_t num, int base); // base must be 10 or 16.
-
- static const int kBufSize = 200;
- char* p_;
- char* end_;
- char buf_[kBufSize];
-};
-
-void Log(LogMode mode, const char* filename, int line,
- LogItem a, LogItem b, LogItem c, LogItem d) {
- Logger state;
- state.p_ = state.buf_;
- state.end_ = state.buf_ + sizeof(state.buf_);
- state.AddStr(filename, strlen(filename))
- && state.AddStr(":", 1)
- && state.AddNum(line, 10)
- && state.AddStr("]", 1)
- && state.Add(a)
- && state.Add(b)
- && state.Add(c)
- && state.Add(d);
-
- // Teminate with newline
- if (state.p_ >= state.end_) {
- state.p_ = state.end_ - 1;
- }
- *state.p_ = '\n';
- state.p_++;
-
- int msglen = state.p_ - state.buf_;
- if (mode == kLog) {
- (*log_message_writer)(state.buf_, msglen);
- return;
- }
-
- bool first_crash = false;
- {
- SpinLockHolder l(&crash_lock);
- if (!crashed) {
- crashed = true;
- first_crash = true;
- }
- }
-
- (*log_message_writer)(state.buf_, msglen);
- if (first_crash && mode == kCrashWithStats) {
- MallocExtension::instance()->GetStats(stats_buffer, kStatsBufferSize);
- (*log_message_writer)(stats_buffer, strlen(stats_buffer));
- }
-
- abort();
-}
-
-bool Logger::Add(const LogItem& item) {
- // Separate items with spaces
- if (p_ < end_) {
- *p_ = ' ';
- p_++;
- }
-
- switch (item.tag_) {
- case LogItem::kStr:
- return AddStr(item.u_.str, strlen(item.u_.str));
- case LogItem::kUnsigned:
- return AddNum(item.u_.unum, 10);
- case LogItem::kSigned:
- if (item.u_.snum < 0) {
- // The cast to uint64_t is intentionally before the negation
- // so that we do not attempt to negate -2^63.
- return AddStr("-", 1)
- && AddNum(- static_cast<uint64_t>(item.u_.snum), 10);
- } else {
- return AddNum(static_cast<uint64_t>(item.u_.snum), 10);
- }
- case LogItem::kPtr:
- return AddStr("0x", 2)
- && AddNum(reinterpret_cast<uintptr_t>(item.u_.ptr), 16);
- default:
- return false;
- }
-}
-
-bool Logger::AddStr(const char* str, int n) {
- if (end_ - p_ < n) {
- return false;
- } else {
- memcpy(p_, str, n);
- p_ += n;
- return true;
- }
-}
-
-bool Logger::AddNum(uint64_t num, int base) {
- static const char kDigits[] = "0123456789abcdef";
- char space[22]; // more than enough for 2^64 in smallest supported base (10)
- char* end = space + sizeof(space);
- char* pos = end;
- do {
- pos--;
- *pos = kDigits[num % base];
- num /= base;
- } while (num > 0 && pos > space);
- return AddStr(pos, end - pos);
-}
-
-} // end tcmalloc namespace
-
-void TCMalloc_Printer::printf(const char* format, ...) {
- if (left_ > 0) {
- va_list ap;
- va_start(ap, format);
- const int r = perftools_vsnprintf(buf_, left_, format, ap);
- va_end(ap);
- if (r < 0) {
- // Perhaps an old glibc that returns -1 on truncation?
- left_ = 0;
- } else if (r > left_) {
- // Truncation
- left_ = 0;
- } else {
- left_ -= r;
- buf_ += r;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/internal_logging.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/internal_logging.h b/third_party/gperftools/src/internal_logging.h
deleted file mode 100644
index 0c300c3..0000000
--- a/third_party/gperftools/src/internal_logging.h
+++ /dev/null
@@ -1,144 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat <op...@google.com>
-//
-// Internal logging and related utility routines.
-
-#ifndef TCMALLOC_INTERNAL_LOGGING_H_
-#define TCMALLOC_INTERNAL_LOGGING_H_
-
-#include <config.h>
-#include <stddef.h> // for size_t
-#if defined HAVE_STDINT_H
-#include <stdint.h>
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>
-#else
-#include <sys/types.h>
-#endif
-
-//-------------------------------------------------------------------
-// Utility routines
-//-------------------------------------------------------------------
-
-// Safe logging helper: we write directly to the stderr file
-// descriptor and avoid FILE buffering because that may invoke
-// malloc().
-//
-// Example:
-// Log(kLog, __FILE__, __LINE__, "error", bytes);
-
-namespace tcmalloc {
-enum LogMode {
- kLog, // Just print the message
- kCrash, // Print the message and crash
- kCrashWithStats // Print the message, some stats, and crash
-};
-
-class Logger;
-
-// A LogItem holds any of the argument types that can be passed to Log()
-class LogItem {
- public:
- LogItem() : tag_(kEnd) { }
- LogItem(const char* v) : tag_(kStr) { u_.str = v; }
- LogItem(int v) : tag_(kSigned) { u_.snum = v; }
- LogItem(long v) : tag_(kSigned) { u_.snum = v; }
- LogItem(long long v) : tag_(kSigned) { u_.snum = v; }
- LogItem(unsigned int v) : tag_(kUnsigned) { u_.unum = v; }
- LogItem(unsigned long v) : tag_(kUnsigned) { u_.unum = v; }
- LogItem(unsigned long long v) : tag_(kUnsigned) { u_.unum = v; }
- LogItem(const void* v) : tag_(kPtr) { u_.ptr = v; }
- private:
- friend class Logger;
- enum Tag {
- kStr,
- kSigned,
- kUnsigned,
- kPtr,
- kEnd
- };
- Tag tag_;
- union {
- const char* str;
- const void* ptr;
- int64_t snum;
- uint64_t unum;
- } u_;
-};
-
-extern PERFTOOLS_DLL_DECL void Log(LogMode mode, const char* filename, int line,
- LogItem a, LogItem b = LogItem(),
- LogItem c = LogItem(), LogItem d = LogItem());
-
-// Tests can override this function to collect logging messages.
-extern PERFTOOLS_DLL_DECL void (*log_message_writer)(const char* msg, int length);
-
-} // end tcmalloc namespace
-
-// Like assert(), but executed even in NDEBUG mode
-#undef CHECK_CONDITION
-#define CHECK_CONDITION(cond) \
-do { \
- if (!(cond)) { \
- ::tcmalloc::Log(::tcmalloc::kCrash, __FILE__, __LINE__, #cond); \
- } \
-} while (0)
-
-// Our own version of assert() so we can avoid hanging by trying to do
-// all kinds of goofy printing while holding the malloc lock.
-#ifndef NDEBUG
-#define ASSERT(cond) CHECK_CONDITION(cond)
-#else
-#define ASSERT(cond) ((void) 0)
-#endif
-
-// Print into buffer
-class TCMalloc_Printer {
- private:
- char* buf_; // Where should we write next
- int left_; // Space left in buffer (including space for \0)
-
- public:
- // REQUIRES: "length > 0"
- TCMalloc_Printer(char* buf, int length) : buf_(buf), left_(length) {
- buf[0] = '\0';
- }
-
- void printf(const char* format, ...)
-#ifdef HAVE___ATTRIBUTE__
- __attribute__ ((__format__ (__printf__, 2, 3)))
-#endif
-;
-};
-
-#endif // TCMALLOC_INTERNAL_LOGGING_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/libc_override.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/libc_override.h b/third_party/gperftools/src/libc_override.h
deleted file mode 100644
index c01a97c..0000000
--- a/third_party/gperftools/src/libc_override.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2011, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Craig Silverstein <op...@google.com>
-//
-// This .h file imports the code that causes tcmalloc to override libc
-// versions of malloc/free/new/delete/etc. That is, it provides the
-// logic that makes it so calls to malloc(10) go through tcmalloc,
-// rather than the default (libc) malloc.
-//
-// This file also provides a method: ReplaceSystemAlloc(), that every
-// libc_override_*.h file it #includes is required to provide. This
-// is called when first setting up tcmalloc -- that is, when a global
-// constructor in tcmalloc.cc is executed -- to do any initialization
-// work that may be required for this OS. (Note we cannot entirely
-// control when tcmalloc is initialized, and the system may do some
-// mallocs and frees before this routine is called.) It may be a
-// noop.
-//
-// Every libc has its own way of doing this, and sometimes the compiler
-// matters too, so we have a different file for each libc, and often
-// for different compilers and OS's.
-
-#ifndef TCMALLOC_LIBC_OVERRIDE_INL_H_
-#define TCMALLOC_LIBC_OVERRIDE_INL_H_
-
-#include <config.h>
-#ifdef HAVE_FEATURES_H
-#include <features.h> // for __GLIBC__
-#endif
-#include <gperftools/tcmalloc.h>
-
-static void ReplaceSystemAlloc(); // defined in the .h files below
-
-// For windows, there are two ways to get tcmalloc. If we're
-// patching, then src/windows/patch_function.cc will do the necessary
-// overriding here. Otherwise, we doing the 'redefine' trick, where
-// we remove malloc/new/etc from mscvcrt.dll, and just need to define
-// them now.
-#if defined(_WIN32) && defined(WIN32_DO_PATCHING)
-void PatchWindowsFunctions(); // in src/windows/patch_function.cc
-static void ReplaceSystemAlloc() { PatchWindowsFunctions(); }
-
-#elif defined(_WIN32) && !defined(WIN32_DO_PATCHING)
-#include "libc_override_redefine.h"
-
-#elif defined(__APPLE__)
-#include "libc_override_osx.h"
-
-#elif defined(__GLIBC__)
-#include "libc_override_glibc.h"
-
-// Not all gcc systems necessarily support weak symbols, but all the
-// ones I know of do, so for now just assume they all do.
-#elif defined(__GNUC__)
-#include "libc_override_gcc_and_weak.h"
-
-#else
-#error Need to add support for your libc/OS here
-
-#endif
-
-#endif // TCMALLOC_LIBC_OVERRIDE_INL_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/bb3371c3/third_party/gperftools/src/libc_override_gcc_and_weak.h
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/libc_override_gcc_and_weak.h b/third_party/gperftools/src/libc_override_gcc_and_weak.h
deleted file mode 100644
index 818e43d..0000000
--- a/third_party/gperftools/src/libc_override_gcc_and_weak.h
+++ /dev/null
@@ -1,107 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2011, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Craig Silverstein <op...@google.com>
-//
-// Used to override malloc routines on systems that define the
-// memory allocation routines to be weak symbols in their libc
-// (almost all unix-based systems are like this), on gcc, which
-// suppports the 'alias' attribute.
-
-#ifndef TCMALLOC_LIBC_OVERRIDE_GCC_AND_WEAK_INL_H_
-#define TCMALLOC_LIBC_OVERRIDE_GCC_AND_WEAK_INL_H_
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h> // for __THROW
-#endif
-#include <gperftools/tcmalloc.h>
-
-#ifndef __THROW // I guess we're not on a glibc-like system
-# define __THROW // __THROW is just an optimization, so ok to make it ""
-#endif
-
-#ifndef __GNUC__
-# error libc_override_gcc_and_weak.h is for gcc distributions only.
-#endif
-
-#define ALIAS(tc_fn) __attribute__ ((alias (#tc_fn)))
-
-void* operator new(size_t size) throw (std::bad_alloc)
- ALIAS(tc_new);
-void operator delete(void* p) __THROW
- ALIAS(tc_delete);
-void* operator new[](size_t size) throw (std::bad_alloc)
- ALIAS(tc_newarray);
-void operator delete[](void* p) __THROW
- ALIAS(tc_deletearray);
-void* operator new(size_t size, const std::nothrow_t& nt) __THROW
- ALIAS(tc_new_nothrow);
-void* operator new[](size_t size, const std::nothrow_t& nt) __THROW
- ALIAS(tc_newarray_nothrow);
-void operator delete(void* p, const std::nothrow_t& nt) __THROW
- ALIAS(tc_delete_nothrow);
-void operator delete[](void* p, const std::nothrow_t& nt) __THROW
- ALIAS(tc_deletearray_nothrow);
-
-extern "C" {
- void* malloc(size_t size) __THROW ALIAS(tc_malloc);
- void free(void* ptr) __THROW ALIAS(tc_free);
- void* realloc(void* ptr, size_t size) __THROW ALIAS(tc_realloc);
- void* calloc(size_t n, size_t size) __THROW ALIAS(tc_calloc);
- void cfree(void* ptr) __THROW ALIAS(tc_cfree);
- void* memalign(size_t align, size_t s) __THROW ALIAS(tc_memalign);
- void* valloc(size_t size) __THROW ALIAS(tc_valloc);
- void* pvalloc(size_t size) __THROW ALIAS(tc_pvalloc);
- int posix_memalign(void** r, size_t a, size_t s) __THROW
- ALIAS(tc_posix_memalign);
-#ifndef __UCLIBC__
- void malloc_stats(void) __THROW ALIAS(tc_malloc_stats);
-#endif
- int mallopt(int cmd, int value) __THROW ALIAS(tc_mallopt);
-#ifdef HAVE_STRUCT_MALLINFO
- struct mallinfo mallinfo(void) __THROW ALIAS(tc_mallinfo);
-#endif
- size_t malloc_size(void* p) __THROW ALIAS(tc_malloc_size);
-#if defined(__ANDROID__)
- size_t malloc_usable_size(const void* p) __THROW
- ALIAS(tc_malloc_size);
-#else
- size_t malloc_usable_size(void* p) __THROW ALIAS(tc_malloc_size);
-#endif
-} // extern "C"
-
-#undef ALIAS
-
-// No need to do anything at tcmalloc-registration time: we do it all
-// via overriding weak symbols (at link time).
-static void ReplaceSystemAlloc() { }
-
-#endif // TCMALLOC_LIBC_OVERRIDE_GCC_AND_WEAK_INL_H_