Znav |
---|
next | Location Transparency |
---|
prev | C++ Logger Utility Classes |
---|
|
The Ice run time uses the Ice::Stats
interface to report the number of bytes sent and received over the wire on every operation invocation:
Wiki Markup |
---|
{zcode:slice}
module Ice {
local interface Stats {
void bytesSent(string protocol, int num);
void bytesReceived(string protocol, int num);
};
local interface Communicator {
Stats getStats();
// ...
};
};
{zcode} |
The Ice run time calls bytesReceived
as it reads data from the network and bytesSent
as it writes data to the network. A very simple implementation of the Stats
interface could look as follows:
Wiki Markup |
---|
{zcode:cpp}
class MyStats : public virtual Ice::Stats {
public:
virtual void bytesSent(const string& prot, Ice::Int num)
{
cerr << prot << ": sent " << num << " bytes" << endl;
}
virtual void bytesReceived(const string& prot, Ice::Int)
{
cerr << prot << ": received " << num << " bytes" << endl;
}
};
{zcode} |
To register your implementation, you must pass it in an InitializationData
parameter when you initialize a communicator:
Wiki Markup |
---|
{zcode:cpp}
Ice::InitializationData id;
id.stats = new MyStats;
Ice::CommunicatorPtr ic = Ice::initialize(id);
{zcode} |
You can install a Stats
object on either the client or the server side (or both). Here is some example output produced by installing a MyStats
object in a simple server:
Wiki Markup |
---|
{zcode}
tcp: received 14 bytes
tcp: received 32 bytes
tcp: sent 26 bytes
tcp: received 14 bytes
tcp: received 33 bytes
tcp: sent 25 bytes
...
{zcode} |
In practice, your Stats
implementation will probably be a bit more sophisticated: for example, the object can accumulate statistics in member variables and make the accumulated statistics available via member functions, instead of simply printing everything to the standard error output.
See Also
Znav |
---|
next | Location Transparency |
---|
prev | C++ Logger Utility Classes |
---|
|