ipc/chromium/src/base/tracked.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/tracked.h"
michael@0 6
michael@0 7 #include "base/string_util.h"
michael@0 8 #include "base/tracked_objects.h"
michael@0 9
michael@0 10 using base::Time;
michael@0 11
michael@0 12 namespace tracked_objects {
michael@0 13
michael@0 14 //------------------------------------------------------------------------------
michael@0 15 void Location::Write(bool display_filename, bool display_function_name,
michael@0 16 std::string* output) const {
michael@0 17 StringAppendF(output, "%s[%d] ",
michael@0 18 display_filename ? file_name_ : "line",
michael@0 19 line_number_);
michael@0 20
michael@0 21 if (display_function_name) {
michael@0 22 WriteFunctionName(output);
michael@0 23 output->push_back(' ');
michael@0 24 }
michael@0 25 }
michael@0 26
michael@0 27 void Location::WriteFunctionName(std::string* output) const {
michael@0 28 // Translate "<" to "&lt;" for HTML safety.
michael@0 29 // TODO(jar): Support ASCII or html for logging in ASCII.
michael@0 30 for (const char *p = function_name_; *p; p++) {
michael@0 31 switch (*p) {
michael@0 32 case '<':
michael@0 33 output->append("&lt;");
michael@0 34 break;
michael@0 35
michael@0 36 case '>':
michael@0 37 output->append("&gt;");
michael@0 38 break;
michael@0 39
michael@0 40 default:
michael@0 41 output->push_back(*p);
michael@0 42 break;
michael@0 43 }
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 //------------------------------------------------------------------------------
michael@0 48
michael@0 49 #ifndef TRACK_ALL_TASK_OBJECTS
michael@0 50
michael@0 51 Tracked::Tracked() {}
michael@0 52 Tracked::~Tracked() {}
michael@0 53 void Tracked::SetBirthPlace(const Location& from_here) {}
michael@0 54 bool Tracked::MissingBirthplace() const { return false; }
michael@0 55 void Tracked::ResetBirthTime() {}
michael@0 56
michael@0 57 #else
michael@0 58
michael@0 59 Tracked::Tracked() : tracked_births_(NULL), tracked_birth_time_(Time::Now()) {
michael@0 60 if (!ThreadData::IsActive())
michael@0 61 return;
michael@0 62 SetBirthPlace(Location("NoFunctionName", "NeedToSetBirthPlace", -1));
michael@0 63 }
michael@0 64
michael@0 65 Tracked::~Tracked() {
michael@0 66 if (!ThreadData::IsActive() || !tracked_births_)
michael@0 67 return;
michael@0 68 ThreadData::current()->TallyADeath(*tracked_births_,
michael@0 69 Time::Now() - tracked_birth_time_);
michael@0 70 }
michael@0 71
michael@0 72 void Tracked::SetBirthPlace(const Location& from_here) {
michael@0 73 if (!ThreadData::IsActive())
michael@0 74 return;
michael@0 75 if (tracked_births_)
michael@0 76 tracked_births_->ForgetBirth();
michael@0 77 ThreadData* current_thread_data = ThreadData::current();
michael@0 78 if (!current_thread_data)
michael@0 79 return; // Shutdown started, and this thread wasn't registered.
michael@0 80 tracked_births_ = current_thread_data->FindLifetime(from_here);
michael@0 81 tracked_births_->RecordBirth();
michael@0 82 }
michael@0 83
michael@0 84 void Tracked::ResetBirthTime() {
michael@0 85 tracked_birth_time_ = Time::Now();
michael@0 86 }
michael@0 87
michael@0 88 bool Tracked::MissingBirthplace() const {
michael@0 89 return -1 == tracked_births_->location().line_number();
michael@0 90 }
michael@0 91
michael@0 92 #endif // NDEBUG
michael@0 93
michael@0 94 } // namespace tracked_objects

mercurial