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

Side by Side Diff: chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h

Issue 2905403002: plumb network upload into the task manager (Closed)
Patch Set: fixed negative byte totals 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_ 5 #ifndef CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_
6 #define CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_ 6 #define CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 14
15 namespace net { 15 namespace net {
16 class URLRequest; 16 class URLRequest;
17 } // namespace net 17 } // namespace net
18 18
19 namespace task_manager { 19 namespace task_manager {
20 20
21 // Defines a wrapper of values that will be sent from IO to UI thread upon 21 // Defines a wrapper of values that will be sent from IO to UI thread upon
22 // reception of bytes read notifications. 22 // reception of bytes read notifications.
23 struct BytesReadParam { 23 struct BytesTransferedParam {
24 // The PID of the originating process of the URLRequest, if the request is 24 // The PID of the originating process of the URLRequest, if the request is
25 // sent on behalf of another process. Otherwise it's 0. 25 // sent on behalf of another process. Otherwise it's 0.
26 int origin_pid; 26 int origin_pid;
27 27
28 // The unique ID of the host of the child process requestor. 28 // The unique ID of the host of the child process requestor.
29 int child_id; 29 int child_id;
30 30
31 // The ID of the IPC route for the URLRequest (this identifies the 31 // The ID of the IPC route for the URLRequest (this identifies the
32 // RenderView or like-thing in the renderer that the request gets routed 32 // RenderView or like-thing in the renderer that the request gets routed
33 // to). 33 // to).
34 int route_id; 34 int route_id;
35 35
36 // The number of bytes read. 36 // The number of bytes read.
37 int64_t byte_count; 37 int64_t byte_count;
38 38
39 BytesReadParam(int origin_pid, 39 BytesTransferedParam(int origin_pid,
40 int child_id, 40 int child_id,
41 int route_id, 41 int route_id,
42 int64_t byte_count) 42 int64_t byte_count)
43 : origin_pid(origin_pid), 43 : origin_pid(origin_pid),
44 child_id(child_id), 44 child_id(child_id),
45 route_id(route_id), 45 route_id(route_id),
46 byte_count(byte_count) { 46 byte_count(byte_count) {}
47 }
48 }; 47 };
49 48
50 // Defines a utility class used to schedule the creation and removal of the 49 // Defines a utility class used to schedule the creation and removal of the
51 // TaskManagerIoThreadHelper on the IO thread. 50 // TaskManagerIoThreadHelper on the IO thread.
52 class IoThreadHelperManager { 51 class IoThreadHelperManager {
53 public: 52 public:
54 IoThreadHelperManager(); 53 IoThreadHelperManager();
55 ~IoThreadHelperManager(); 54 ~IoThreadHelperManager();
56 55
57 private: 56 private:
58 DISALLOW_COPY_AND_ASSIGN(IoThreadHelperManager); 57 DISALLOW_COPY_AND_ASSIGN(IoThreadHelperManager);
59 }; 58 };
60 59
61 // Defines a class used by the task manager to receive notifications of the 60 // Defines a class used by the task manager to receive notifications of the
62 // network bytes read by the various tasks. 61 // network bytes read by the various tasks.
63 // This object lives entirely only on the IO thread. 62 // This object lives entirely only on the IO thread.
64 class TaskManagerIoThreadHelper { 63 class TaskManagerIoThreadHelper {
65 public: 64 public:
66 // Create and delete the instance of this class. They must be called on the IO 65 // Create and delete the instance of this class. They must be called on the IO
67 // thread. 66 // thread.
68 static void CreateInstance(); 67 static void CreateInstance();
69 static void DeleteInstance(); 68 static void DeleteInstance();
70 69
71 // This is used to forward the call to update the network bytes from the 70 // This is used to forward the call to update the network bytes with read
72 // TaskManagerInterface if the new task manager is enabled. 71 // bytes from the TaskManagerInterface if the new task manager is enabled.
73 static void OnRawBytesRead(const net::URLRequest& request, 72 static void OnRawBytesRead(const net::URLRequest& request,
74 int64_t bytes_read); 73 int64_t bytes_read);
75 74
75 // This is used to forward the call to update the network bytes with sent
76 // bytes from the TaskManagerInterface if the new task manager is enabled.
77 static void OnRawBytesSent(const net::URLRequest& request,
78 int64_t bytes_sent);
79
76 private: 80 private:
77 TaskManagerIoThreadHelper(); 81 TaskManagerIoThreadHelper();
78 ~TaskManagerIoThreadHelper(); 82 ~TaskManagerIoThreadHelper();
79 83
80 // We gather multiple notifications on the IO thread in one second before a 84 // We gather multiple notifications on the IO thread in one second before a
81 // call is made to the following function to start the processing. 85 // call is made to the following function to start the processing for read
86 // bytes.
82 void OnMultipleBytesReadIO(); 87 void OnMultipleBytesReadIO();
83 88
84 // This will update the task manager with the network bytes read. 89 // This will update the task manager with the network bytes read.
85 void OnNetworkBytesRead(const net::URLRequest& request, int64_t bytes_read); 90 void OnNetworkBytesRead(const net::URLRequest& request, int64_t bytes_read);
86 91
92 // We gather multiple notifications on the IO thread in one second before a
93 // call is made to the following function to start the processing for sent
94 // bytes.
95 void OnMultipleBytesSentIO();
96
97 // This will update the task manager with the network bytes sent.
98 void OnNetworkBytesSent(const net::URLRequest& request, int64_t bytes_sent);
99
87 // This buffer will be filled on IO thread with information about the number 100 // This buffer will be filled on IO thread with information about the number
88 // of bytes read from URLRequests. 101 // of bytes read from URLRequests.
89 std::vector<BytesReadParam> bytes_read_buffer_; 102 std::vector<BytesTransferedParam> bytes_read_buffer_;
103
104 // This buffer will be filled on IO thread with information about the number
105 // of bytes read from URLRequests.
106 std::vector<BytesTransferedParam> bytes_sent_buffer_;
90 107
91 base::WeakPtrFactory<TaskManagerIoThreadHelper> weak_factory_; 108 base::WeakPtrFactory<TaskManagerIoThreadHelper> weak_factory_;
92 109
93 DISALLOW_COPY_AND_ASSIGN(TaskManagerIoThreadHelper); 110 DISALLOW_COPY_AND_ASSIGN(TaskManagerIoThreadHelper);
94 }; 111 };
95 112
96 } // namespace task_manager 113 } // namespace task_manager
97 114
98 #endif // CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_ 115 #endif // CHROME_BROWSER_TASK_MANAGER_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698