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

Side by Side Diff: src/procfs_byte_counter.h

Issue 5180003: cashew: add local byte counters (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Address jglasgow and zelidrag (offline) code review comments Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/policy.cc ('k') | src/procfs_byte_counter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS 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 #ifndef SRC_PROCFS_BYTE_COUNTER_H_
6 #define SRC_PROCFS_BYTE_COUNTER_H_
7
8 #include <stdio.h>
9
10 #include <glib.h>
11 #include <sys/socket.h>
12 #include <linux/netdevice.h>
13
14 #include <string>
15
16 #include <base/basictypes.h> // NOLINT
17
18 #include "src/byte_counter.h"
19
20 namespace cashew {
21
22 // a procfs-based implementation of the ByteCounter interface
23 class ProcfsByteCounter: public ByteCounter {
24 public:
25 explicit ProcfsByteCounter(const std::string& interface);
26 virtual ~ProcfsByteCounter();
27 virtual const std::string& GetInterface() const;
28 virtual uint64 GetRxBytes() const;
29 virtual uint64 GetTxBytes() const;
30 virtual void SetDelegate(ByteCounterDelegate *delegate);
31
32 private:
33 // interface name
34 const std::string interface_;
35
36 // file pointer for open /proc/net/dev virtual file
37 // can be NULL
38 FILE *proc_net_dev_fp_;
39
40 // ReadStats timer glib source id
41 guint read_stats_source_id_;
42
43 // counter: received bytes
44 uint64 counter_rx_bytes_;
45
46 // counter: transmitted byes
47 uint64 counter_tx_bytes_;
48
49 // baseline stats against which we'll compare our next update
50 // updated with each sample so as to better handle wraparound
51 //
52 // these stats are maintained by the device driver starting from kernel boot
53 // or module load time and have aribitrary values relative to when our
54 // logical |counter_rx_bytes_| and |counter_tx_bytes_| counters were started
55 struct net_device_stats baseline_stats_;
56
57 // have our baseline device stats been initialized?
58 // this becomes true after the first call to OnStatsUpdate
59 bool baseline_initialized_;
60
61 // delegate
62 ByteCounterDelegate *delegate_;
63
64 // open /proc/net/dev
65 // stores resulting fp in |proc_net_dev_fp_|
66 // returns true on success and false on failure
67 bool OpenProcNetDev();
68
69 // close /proc/net/dev
70 // clears |proc_net_dev_fp_|
71 // ok to call even if file isn't open
72 void CloseProcNetDev();
73
74 // glib integration: static wrapper for ReadStats
75 // takes object ptr as data and invokes object->ReadStats
76 static gboolean StaticReadStatsCallback(gpointer data);
77
78 // read stats for |interface_| from /proc/net/dev
79 // returns true on success and false on failure
80 bool ReadStats();
81
82 // new stats are available, update counter
83 void OnStatsUpdate(const struct net_device_stats& stats);
84
85 DISALLOW_COPY_AND_ASSIGN(ProcfsByteCounter);
86 };
87
88 } // namespace cashew
89
90 #endif // SRC_PROCFS_BYTE_COUNTER_H_
OLDNEW
« no previous file with comments | « src/policy.cc ('k') | src/procfs_byte_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698