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

Side by Side Diff: net/spdy/spdy_session_pool_unittest.cc

Issue 2565523002: Instrument SpdySessionPool using MemoryDumpProvider (Closed)
Patch Set: Address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/spdy/spdy_session_pool.h" 5 #include "net/spdy/spdy_session_pool.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/trace_event/memory_allocator_dump.h"
16 #include "base/trace_event/process_memory_dump.h"
17 #include "base/trace_event/trace_event_argument.h"
15 #include "net/dns/host_cache.h" 18 #include "net/dns/host_cache.h"
16 #include "net/http/http_network_session.h" 19 #include "net/http/http_network_session.h"
17 #include "net/log/net_log_with_source.h" 20 #include "net/log/net_log_with_source.h"
18 #include "net/socket/client_socket_handle.h" 21 #include "net/socket/client_socket_handle.h"
19 #include "net/socket/transport_client_socket_pool.h" 22 #include "net/socket/transport_client_socket_pool.h"
20 #include "net/spdy/spdy_session.h" 23 #include "net/spdy/spdy_session.h"
21 #include "net/spdy/spdy_stream_test_util.h" 24 #include "net/spdy/spdy_stream_test_util.h"
22 #include "net/spdy/spdy_test_util_common.h" 25 #include "net/spdy/spdy_test_util_common.h"
23 #include "net/test/cert_test_util.h" 26 #include "net/test/cert_test_util.h"
24 #include "net/test/gtest_util.h" 27 #include "net/test/gtest_util.h"
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 // FindAvailableSession should return |session| if called with |url| for which 664 // FindAvailableSession should return |session| if called with |url| for which
662 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. 665 // there is no pushed stream on any sessions owned by |spdy_session_pool_|.
663 base::WeakPtr<SpdySession> session2 = 666 base::WeakPtr<SpdySession> session2 =
664 spdy_session_pool_->FindAvailableSession( 667 spdy_session_pool_->FindAvailableSession(
665 key, GURL("http://news.example.org/foo.html"), NetLogWithSource()); 668 key, GURL("http://news.example.org/foo.html"), NetLogWithSource());
666 EXPECT_EQ(session.get(), session2.get()); 669 EXPECT_EQ(session.get(), session2.get());
667 670
668 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 671 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
669 } 672 }
670 673
674 TEST_F(SpdySessionPoolTest, DumpMemoryStats) {
675 SpdySessionKey key(HostPortPair("https://www.example.org", 443),
676 ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
677
678 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)};
679 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0);
680 data.set_connect_data(MockConnect(SYNCHRONOUS, OK));
681 session_deps_.socket_factory->AddSocketDataProvider(&data);
682
683 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
684 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
685
686 CreateNetworkSession();
687
688 base::WeakPtr<SpdySession> session =
689 CreateSecureSpdySession(http_session_.get(), key, NetLogWithSource());
690
691 // Flush the SpdySession::OnReadComplete() task.
692 base::RunLoop().RunUntilIdle();
693
694 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key));
695 base::trace_event::MemoryDumpArgs dump_args = {
696 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
697 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
698 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
699 base::trace_event::MemoryAllocatorDump* parent_dump =
700 process_memory_dump->CreateAllocatorDump("parent");
701 spdy_session_pool_->DumpMemoryStats(process_memory_dump.get(),
702 parent_dump->absolute_name());
703
704 // Whether SpdySession::DumpMemoryStats() is invoked.
705 bool did_dump = false;
706 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
707 allocator_dumps = process_memory_dump->allocator_dumps();
708 for (const auto& pair : allocator_dumps) {
709 const std::string& dump_name = pair.first;
710 if (dump_name.find("spdy_session_pool/session") == std::string::npos)
711 continue;
712 std::unique_ptr<base::Value> raw_attrs =
713 pair.second->attributes_for_testing()->ToBaseValue();
714 base::DictionaryValue* attrs;
715 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
716 base::DictionaryValue* is_active_attrs;
717 ASSERT_TRUE(attrs->GetDictionary("active", &is_active_attrs));
718 std::string is_active;
719 ASSERT_TRUE(is_active_attrs->GetString("value", &is_active));
720 // No created stream so the session should be idle.
721 ASSERT_EQ("0", is_active);
722 did_dump = true;
723 }
724 EXPECT_TRUE(did_dump);
725 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
726 }
727
671 } // namespace net 728 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698