summaryrefslogtreecommitdiffstats
path: root/libvncserver/stats.c
blob: cd1bd40bd8151c475189202c80a0da6c43fd3d9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * stats.c
 */

/*
 *  Copyright (C) 2002 RealVNC Ltd.
 *  OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
 *  Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.  
 *  All Rights Reserved.
 *
 *  This is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This software is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this software; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 *  USA.
 */

#include <rfb/rfb.h>

static const char* encNames[] = {
    "raw", "copyRect", "RRE", "[encoding 3]", "CoRRE", "hextile",
    "zlib", "tight", "[encoding 8]", "[encoding 9]", "[encoding 10]",
    "[encoding 11]", "[encoding 12]", "[encoding 13]", "[encoding 14]",
#ifdef LIBVNCSERVER_BACKCHANNEL
    "BackChannel",
#else
    "[encoding 15]",
#endif
    "ZRLE", "[encoding 17]", "[encoding 18]", "[encoding 19]", "[encoding 20]"
};


void
rfbResetStats(rfbClientPtr cl)
{
    int i;
    for (i = 0; i < MAX_ENCODINGS; i++) {
        cl->bytesSent[i] = 0;
        cl->rectanglesSent[i] = 0;
    }
    cl->lastRectMarkersSent = 0;
    cl->lastRectBytesSent = 0;
    cl->cursorShapeBytesSent = 0;
    cl->cursorShapeUpdatesSent = 0;
    cl->cursorPosBytesSent = 0;
    cl->cursorPosUpdatesSent = 0;
    cl->framebufferUpdateMessagesSent = 0;
    cl->rawBytesEquivalent = 0;
    cl->keyEventsRcvd = 0;
    cl->pointerEventsRcvd = 0;
}

void
rfbPrintStats(rfbClientPtr cl)
{
    int i;
    int totalRectanglesSent = 0;
    int totalBytesSent = 0;

    rfbLog("Statistics:\n");

    if ((cl->keyEventsRcvd != 0) || (cl->pointerEventsRcvd != 0))
        rfbLog("  key events received %d, pointer events %d\n",
                cl->keyEventsRcvd, cl->pointerEventsRcvd);

    for (i = 0; i < MAX_ENCODINGS; i++) {
        totalRectanglesSent += cl->rectanglesSent[i];
        totalBytesSent += cl->bytesSent[i];
    }

    totalRectanglesSent += (cl->cursorShapeUpdatesSent +
                            cl->cursorPosUpdatesSent +
			    cl->lastRectMarkersSent);
    totalBytesSent += (cl->cursorShapeBytesSent +
                       cl->cursorPosBytesSent +
                       cl->lastRectBytesSent);

    rfbLog("  framebuffer updates %d, rectangles %d, bytes %d\n",
            cl->framebufferUpdateMessagesSent, totalRectanglesSent,
            totalBytesSent);

    if (cl->lastRectMarkersSent != 0)
	rfbLog("    LastRect and NewFBSize markers %d, bytes %d\n",
		cl->lastRectMarkersSent, cl->lastRectBytesSent);

    if (cl->cursorShapeUpdatesSent != 0)
	rfbLog("    cursor shape updates %d, bytes %d\n",
		cl->cursorShapeUpdatesSent, cl->cursorShapeBytesSent);

    if (cl->cursorPosUpdatesSent != 0)
	rfbLog("    cursor position updates %d, bytes %d\n",
		cl->cursorPosUpdatesSent, cl->cursorPosBytesSent);

    for (i = 0; i < MAX_ENCODINGS; i++) {
        if (cl->rectanglesSent[i] != 0)
            rfbLog("    %s rectangles %d, bytes %d\n",
                   encNames[i], cl->rectanglesSent[i], cl->bytesSent[i]);
    }

    if ((totalBytesSent - cl->bytesSent[rfbEncodingCopyRect]) != 0) {
        rfbLog("  raw bytes equivalent %d, compression ratio %f\n",
                cl->rawBytesEquivalent,
                (double)cl->rawBytesEquivalent
                / (double)(totalBytesSent
                           - cl->bytesSent[rfbEncodingCopyRect]-
			   cl->cursorShapeBytesSent -
                           cl->cursorPosBytesSent -
			   cl->lastRectBytesSent));
    }
}