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

Side by Side Diff: chrome/common/profiling/memlog_sender_pipe_win.cc

Issue 2940003002: Add pipe implementation for OOP memory logging (Closed)
Patch Set: Comment Created 3 years, 6 months 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/profiling/memlog_sender_pipe_win.h"
6
7 #include "base/logging.h"
8 #include "chrome/common/profiling/memlog_stream.h"
9
10 namespace profiling {
11
12 MemlogSenderPipe::MemlogSenderPipe(const base::string16& pipe_id)
13 : pipe_id_(pipe_id), handle_(INVALID_HANDLE_VALUE) {}
14
15 MemlogSenderPipe::~MemlogSenderPipe() {
16 if (handle_ != INVALID_HANDLE_VALUE)
17 ::CloseHandle(handle_);
18 }
19
20 bool MemlogSenderPipe::Connect() {
21 DCHECK(handle_ == INVALID_HANDLE_VALUE);
22
23 base::string16 pipe_name = kWindowsPipePrefix;
24 pipe_name.append(pipe_id_);
25
26 const int kMaxWaitMS = 30000;
27 ULONGLONG timeout_ticks = ::GetTickCount64() + kMaxWaitMS;
28 do {
29 if (!::WaitNamedPipe(pipe_name.c_str(), kMaxWaitMS)) {
30 // Since it will wait "forever", the only time WaitNamedPipe should fail
31 // is if the pipe doesn't exist.
32 return false;
33 }
34 // This is a single-direction pipe so we don't specify GENERIC_READ, but
35 // MSDN says we need FILE_READ_ATTRIBUTES.
36 handle_ = ::CreateFile(pipe_name.c_str(),
37 FILE_READ_ATTRIBUTES | GENERIC_WRITE, 0,
38 NULL, OPEN_EXISTING, 0, NULL);
39 // Need to loop since there is a race condition waiting for a connection to
40 // be available and actually connecting to it.
41 } while (handle_ == INVALID_HANDLE_VALUE &&
42 ::GetTickCount64() < timeout_ticks);
43
44 return handle_ != INVALID_HANDLE_VALUE;
45 }
46
47 bool MemlogSenderPipe::Send(const void* data, size_t sz) {
48 // The pipe uses a blocking wait mode (it doesn't specify PIPE_NOWAIT) so
49 // WriteFile should do only complete writes.
50 //
51 // Note: don't use logging here (CHECK, DCHECK) because they will allocate,
52 // and this function is called from within a malloc hook.
53 DWORD bytes_written = 0;
54 if (!::WriteFile(handle_, data, static_cast<DWORD>(sz), &bytes_written, NULL))
55 return false;
56 return true;
57 }
58
59 } // namespace profiling
OLDNEW
« no previous file with comments | « chrome/common/profiling/memlog_sender_pipe_win.h ('k') | chrome/common/profiling/memlog_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698