OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "base/trace_event/memory_allocator_dump.h" | |
21 #include "base/trace_event/process_memory_dump.h" | |
19 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
20 #include "base/values.h" | 23 #include "base/values.h" |
21 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
22 #include "net/log/net_log.h" | 25 #include "net/log/net_log.h" |
23 #include "net/log/net_log_event_type.h" | 26 #include "net/log/net_log_event_type.h" |
24 #include "net/log/net_log_source.h" | 27 #include "net/log/net_log_source.h" |
25 | 28 |
26 using base::TimeDelta; | 29 using base::TimeDelta; |
27 | 30 |
28 namespace net { | 31 namespace net { |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 max_sockets_per_group_)); | 693 max_sockets_per_group_)); |
691 group_dict->SetBoolean("backup_job_timer_is_running", | 694 group_dict->SetBoolean("backup_job_timer_is_running", |
692 group->BackupJobTimerIsRunning()); | 695 group->BackupJobTimerIsRunning()); |
693 | 696 |
694 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); | 697 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); |
695 } | 698 } |
696 dict->Set("groups", all_groups_dict); | 699 dict->Set("groups", all_groups_dict); |
697 return dict; | 700 return dict; |
698 } | 701 } |
699 | 702 |
703 void ClientSocketPoolBaseHelper::DumpMemoryStats( | |
704 base::trace_event::MemoryAllocatorDump* parent_dump) const { | |
705 base::trace_event::MemoryAllocatorDump* socket_pool_dump = nullptr; | |
706 size_t socket_count = 0; | |
707 for (GroupMap::const_iterator it = group_map_.begin(); it != group_map_.end(); | |
708 ++it) { | |
709 const std::list<IdleSocket> sockets = it->second->idle_sockets(); | |
eroman
2016/12/02 00:27:24
Looks like there are some unnecessary copies here.
xunjieli
2016/12/02 15:31:34
oops, sorry. Done.
| |
710 for (auto socket : sockets) { | |
711 // Only create a MemoryAllocatorDump if there is at least one idle socket | |
712 if (!socket_pool_dump) { | |
713 socket_pool_dump = | |
714 parent_dump->process_memory_dump()->CreateAllocatorDump( | |
715 base::StringPrintf("%s/socket_pool", | |
716 parent_dump->absolute_name().c_str())); | |
717 } | |
718 socket.socket->DumpMemoryStats(socket_pool_dump); | |
719 ++socket_count; | |
720 } | |
721 } | |
722 if (socket_pool_dump) { | |
723 socket_pool_dump->AddScalar( | |
724 base::trace_event::MemoryAllocatorDump::kNameObjectCount, | |
725 base::trace_event::MemoryAllocatorDump::kUnitsObjects, socket_count); | |
726 } | |
727 } | |
728 | |
700 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { | 729 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { |
701 if (socket->WasEverUsed()) | 730 if (socket->WasEverUsed()) |
702 return socket->IsConnectedAndIdle(); | 731 return socket->IsConnectedAndIdle(); |
703 return socket->IsConnected(); | 732 return socket->IsConnected(); |
704 } | 733 } |
705 | 734 |
706 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { | 735 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { |
707 if (idle_socket_count_ == 0) | 736 if (idle_socket_count_ == 0) |
708 return; | 737 return; |
709 | 738 |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 // If there are no more requests, kill the backup timer. | 1410 // If there are no more requests, kill the backup timer. |
1382 if (pending_requests_.empty()) | 1411 if (pending_requests_.empty()) |
1383 backup_job_timer_.Stop(); | 1412 backup_job_timer_.Stop(); |
1384 request->CrashIfInvalid(); | 1413 request->CrashIfInvalid(); |
1385 return request; | 1414 return request; |
1386 } | 1415 } |
1387 | 1416 |
1388 } // namespace internal | 1417 } // namespace internal |
1389 | 1418 |
1390 } // namespace net | 1419 } // namespace net |
OLD | NEW |