OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <functional> | 9 #include <functional> |
10 #include <iomanip> | 10 #include <iomanip> |
11 #include <iterator> | 11 #include <iterator> |
12 #include <limits> | 12 #include <limits> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/debug/trace_event.h" | |
16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
17 #include "base/file_util.h" | 18 #include "base/file_util.h" |
18 #include "base/hash_tables.h" | 19 #include "base/hash_tables.h" |
19 #include "base/location.h" | 20 #include "base/location.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
22 #include "base/perftimer.h" | 23 #include "base/perftimer.h" |
23 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
24 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
25 #include "base/string_util.h" | 26 #include "base/string_util.h" |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1121 // ScopedKernelLock | 1122 // ScopedKernelLock |
1122 | 1123 |
1123 ScopedKernelLock::ScopedKernelLock(const Directory* dir) | 1124 ScopedKernelLock::ScopedKernelLock(const Directory* dir) |
1124 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { | 1125 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { |
1125 } | 1126 } |
1126 | 1127 |
1127 /////////////////////////////////////////////////////////////////////////// | 1128 /////////////////////////////////////////////////////////////////////////// |
1128 // Transactions | 1129 // Transactions |
1129 | 1130 |
1130 void BaseTransaction::Lock() { | 1131 void BaseTransaction::Lock() { |
1131 base::TimeTicks start_time = base::TimeTicks::Now(); | 1132 TRACE_EVENT2("sync_lock_contention", "AcquireLock", |
1133 "src_file", from_here_.file_name(), | |
1134 "src_func", from_here_.function_name()); | |
1132 | 1135 |
1133 dirkernel_->transaction_mutex.Acquire(); | 1136 dirkernel_->transaction_mutex.Acquire(); |
1134 | |
1135 time_acquired_ = base::TimeTicks::Now(); | |
1136 const base::TimeDelta elapsed = time_acquired_ - start_time; | |
1137 VLOG_LOC(from_here_, 2) | |
1138 << name_ << " transaction waited " | |
1139 << elapsed.InSecondsF() << " seconds."; | |
1140 } | 1137 } |
1141 | 1138 |
1142 void BaseTransaction::Unlock() { | 1139 void BaseTransaction::Unlock() { |
1143 dirkernel_->transaction_mutex.Release(); | 1140 dirkernel_->transaction_mutex.Release(); |
1144 const base::TimeDelta elapsed = base::TimeTicks::Now() - time_acquired_; | |
1145 VLOG_LOC(from_here_, 2) | |
1146 << name_ << " transaction completed in " << elapsed.InSecondsF() | |
1147 << " seconds."; | |
1148 } | 1141 } |
1149 | 1142 |
1150 BaseTransaction::BaseTransaction(const tracked_objects::Location& from_here, | 1143 BaseTransaction::BaseTransaction(const tracked_objects::Location& from_here, |
1151 const char* name, | 1144 const char* name, |
1152 WriterTag writer, | 1145 WriterTag writer, |
1153 Directory* directory) | 1146 Directory* directory) |
1154 : from_here_(from_here), name_(name), writer_(writer), | 1147 : from_here_(from_here), name_(name), writer_(writer), |
1155 directory_(directory), dirkernel_(directory->kernel_) { | 1148 directory_(directory), dirkernel_(directory->kernel_) { |
1149 TRACE_EVENT_BEGIN2("sync", name_, | |
1150 "src_file", from_here_.file_name(), | |
1151 "src_func", from_here_.function_name()); | |
1156 dirkernel_->observers->Notify( | 1152 dirkernel_->observers->Notify( |
1157 &TransactionObserver::OnTransactionStart, from_here_, writer_); | 1153 &TransactionObserver::OnTransactionStart, from_here_, writer_); |
1158 } | 1154 } |
1159 | 1155 |
1160 BaseTransaction::~BaseTransaction() { | 1156 BaseTransaction::~BaseTransaction() { |
1161 if (writer_ != INVALID) { | 1157 if (writer_ != INVALID) { |
1162 dirkernel_->observers->Notify( | 1158 dirkernel_->observers->Notify( |
1163 &TransactionObserver::OnTransactionEnd, from_here_, writer_); | 1159 &TransactionObserver::OnTransactionEnd, from_here_, writer_); |
1164 } | 1160 } |
1161 TRACE_EVENT_END0("sync", "ReadTransaction"); | |
akalin
2011/11/19 00:32:13
"ReadTransaction" -> name_
| |
1165 } | 1162 } |
1166 | 1163 |
1167 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, | 1164 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, |
1168 Directory* directory) | 1165 Directory* directory) |
1169 : BaseTransaction(location, "Read", INVALID, directory) { | 1166 : BaseTransaction(location, "ReadTransaction", INVALID, directory) { |
1170 Lock(); | 1167 Lock(); |
1171 } | 1168 } |
1172 | 1169 |
1173 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, | 1170 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, |
1174 const ScopedDirLookup& scoped_dir) | 1171 const ScopedDirLookup& scoped_dir) |
1175 : BaseTransaction(location, "Read", INVALID, scoped_dir.operator->()) { | 1172 : BaseTransaction(location, "ReadTransaction", INVALID, scoped_dir.operator- >()) { |
1176 Lock(); | 1173 Lock(); |
1177 } | 1174 } |
1178 | 1175 |
1179 ReadTransaction::~ReadTransaction() { | 1176 ReadTransaction::~ReadTransaction() { |
1180 Unlock(); | 1177 Unlock(); |
1181 } | 1178 } |
1182 | 1179 |
1183 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, | 1180 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, |
1184 WriterTag writer, Directory* directory) | 1181 WriterTag writer, Directory* directory) |
1185 : BaseTransaction(location, "Write", writer, directory) { | 1182 : BaseTransaction(location, "WriteTransaction", writer, directory) { |
1186 Lock(); | 1183 Lock(); |
1187 } | 1184 } |
1188 | 1185 |
1189 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, | 1186 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, |
1190 WriterTag writer, | 1187 WriterTag writer, |
1191 const ScopedDirLookup& scoped_dir) | 1188 const ScopedDirLookup& scoped_dir) |
1192 : BaseTransaction(location, "Write", writer, scoped_dir.operator->()) { | 1189 : BaseTransaction(location, "WriteTransaction", writer, scoped_dir.operator- >()) { |
1193 Lock(); | 1190 Lock(); |
1194 } | 1191 } |
1195 | 1192 |
1196 void WriteTransaction::SaveOriginal(const EntryKernel* entry) { | 1193 void WriteTransaction::SaveOriginal(const EntryKernel* entry) { |
1197 if (!entry) { | 1194 if (!entry) { |
1198 return; | 1195 return; |
1199 } | 1196 } |
1200 // Insert only if it's not already there. | 1197 // Insert only if it's not already there. |
1201 const int64 handle = entry->ref(META_HANDLE); | 1198 const int64 handle = entry->ref(META_HANDLE); |
1202 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); | 1199 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2021 if (entry->ref(NEXT_ID).IsRoot() || | 2018 if (entry->ref(NEXT_ID).IsRoot() || |
2022 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { | 2019 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { |
2023 return entry; | 2020 return entry; |
2024 } | 2021 } |
2025 } | 2022 } |
2026 // There were no children in the linked list. | 2023 // There were no children in the linked list. |
2027 return NULL; | 2024 return NULL; |
2028 } | 2025 } |
2029 | 2026 |
2030 } // namespace syncable | 2027 } // namespace syncable |
OLD | NEW |