/src/FreeRDP/libfreerdp/core/metrics.c
Line  | Count  | Source  | 
1  |  | /**  | 
2  |  |  * FreeRDP: A Remote Desktop Protocol Implementation  | 
3  |  |  * Protocol Metrics  | 
4  |  |  *  | 
5  |  |  * Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>  | 
6  |  |  *  | 
7  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
8  |  |  * you may not use this file except in compliance with the License.  | 
9  |  |  * You may obtain a copy of the License at  | 
10  |  |  *  | 
11  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
12  |  |  *  | 
13  |  |  * Unless required by applicable law or agreed to in writing, software  | 
14  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
15  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
16  |  |  * See the License for the specific language governing permissions and  | 
17  |  |  * limitations under the License.  | 
18  |  |  */  | 
19  |  |  | 
20  |  | #include <freerdp/config.h>  | 
21  |  |  | 
22  |  | #include "rdp.h"  | 
23  |  |  | 
24  |  | double metrics_write_bytes(rdpMetrics* metrics, UINT32 UncompressedBytes, UINT32 CompressedBytes)  | 
25  | 678  | { | 
26  | 678  |   double CompressionRatio = 0.0;  | 
27  |  |  | 
28  | 678  |   metrics->TotalUncompressedBytes += UncompressedBytes;  | 
29  | 678  |   metrics->TotalCompressedBytes += CompressedBytes;  | 
30  |  |  | 
31  | 678  |   if (UncompressedBytes != 0)  | 
32  | 673  |     CompressionRatio = ((double)CompressedBytes) / ((double)UncompressedBytes);  | 
33  | 678  |   if (metrics->TotalUncompressedBytes != 0)  | 
34  | 673  |     metrics->TotalCompressionRatio =  | 
35  | 673  |         ((double)metrics->TotalCompressedBytes) / ((double)metrics->TotalUncompressedBytes);  | 
36  |  |  | 
37  | 678  |   return CompressionRatio;  | 
38  | 678  | }  | 
39  |  |  | 
40  |  | rdpMetrics* metrics_new(rdpContext* context)  | 
41  | 13.2k  | { | 
42  | 13.2k  |   rdpMetrics* metrics = NULL;  | 
43  |  |  | 
44  | 13.2k  |   metrics = (rdpMetrics*)calloc(1, sizeof(rdpMetrics));  | 
45  |  |  | 
46  | 13.2k  |   if (metrics)  | 
47  | 13.2k  |   { | 
48  | 13.2k  |     metrics->context = context;  | 
49  | 13.2k  |   }  | 
50  |  |  | 
51  | 13.2k  |   return metrics;  | 
52  | 13.2k  | }  | 
53  |  |  | 
54  |  | void metrics_free(rdpMetrics* metrics)  | 
55  | 13.2k  | { | 
56  | 13.2k  |   free(metrics);  | 
57  | 13.2k  | }  |