libfreerdp-core: add new protocol metrics module

This commit is contained in:
Marc-André Moreau 2014-05-26 12:30:58 -04:00
parent 8c7fbe3394
commit 830659fc5c
8 changed files with 130 additions and 33 deletions

View File

@ -26,6 +26,7 @@ typedef struct rdp_rail rdpRail;
typedef struct rdp_cache rdpCache;
typedef struct rdp_channels rdpChannels;
typedef struct rdp_graphics rdpGraphics;
typedef struct rdp_metrics rdpMetrics;
typedef struct rdp_freerdp freerdp;
typedef struct rdp_context rdpContext;
@ -39,6 +40,7 @@ typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS;
#include <freerdp/types.h>
#include <freerdp/error.h>
#include <freerdp/event.h>
#include <freerdp/metrics.h>
#include <freerdp/settings.h>
#include <freerdp/extension.h>
@ -117,7 +119,8 @@ struct rdp_context
ALIGN64 rdpInput* input; /* 38 */
ALIGN64 rdpUpdate* update; /* 39 */
ALIGN64 rdpSettings* settings; /* 40 */
UINT64 paddingC[64 - 41]; /* 41 */
ALIGN64 rdpMetrics* metrics; /* 41 */
UINT64 paddingC[64 - 42]; /* 42 */
UINT64 paddingD[96 - 64]; /* 64 */
UINT64 paddingE[128 - 96]; /* 96 */

40
include/freerdp/metrics.h Normal file
View File

@ -0,0 +1,40 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Protocol Metrics
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FREERDP_METRICS_H
#define FREERDP_METRICS_H
#include <freerdp/api.h>
struct rdp_metrics
{
rdpContext* context;
UINT64 TotalCompressedBytes;
UINT64 TotalUncompressedBytes;
double TotalCompressionRatio;
};
FREERDP_API double metrics_write_bytes(rdpMetrics* metrics, UINT32 UncompressedBytes, UINT32 CompressedBytes);
FREERDP_API rdpMetrics* metrics_new(rdpContext* context);
FREERDP_API void metrics_free(rdpMetrics* metrics);
#endif /* FREERDP_METRICS_H */

View File

@ -79,6 +79,8 @@ set(${MODULE_PREFIX}_SRCS
client.h
server.c
server.h
metrics.c
metrics.h
capabilities.c
capabilities.h
certificate.c

View File

@ -23,7 +23,7 @@
#include "bulk.h"
#define WITH_BULK_DEBUG 1
//#define WITH_BULK_DEBUG 1
const char* bulk_get_compression_flags_string(UINT32 flags)
{
@ -117,8 +117,12 @@ int bulk_decompress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstD
{
UINT32 type;
int status = -1;
rdpMetrics* metrics;
UINT32 CompressedBytes;
UINT32 UncompressedBytes;
double CompressionRatio;
metrics = bulk->context->metrics;
bulk_compression_max_size(bulk);
type = flags & BULK_COMPRESSION_TYPE_MASK;
@ -162,21 +166,15 @@ int bulk_decompress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstD
CompressedBytes = SrcSize;
UncompressedBytes = *pDstSize;
bulk->TotalUncompressedBytes += UncompressedBytes;
bulk->TotalCompressedBytes += CompressedBytes;
CompressionRatio = metrics_write_bytes(metrics, UncompressedBytes, CompressedBytes);
#ifdef WITH_BULK_DEBUG
{
double CompressionRatio;
double TotalCompressionRatio;
CompressionRatio = ((double) CompressedBytes) / ((double) UncompressedBytes);
TotalCompressionRatio = ((double) bulk->TotalCompressedBytes) / ((double) bulk->TotalUncompressedBytes);
printf("Decompress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%d / %d)\n",
printf("Decompress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%u / %u)\n",
type, bulk_get_compression_flags_string(flags), flags,
CompressionRatio, CompressedBytes, UncompressedBytes,
TotalCompressionRatio, bulk->TotalCompressedBytes, bulk->TotalUncompressedBytes);
metrics->TotalCompressionRatio, (UINT32) metrics->TotalCompressedBytes,
(UINT32) metrics->TotalUncompressedBytes);
}
#endif
}
@ -191,8 +189,12 @@ int bulk_decompress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstD
int bulk_compress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32* pFlags)
{
int status = -1;
rdpMetrics* metrics;
UINT32 CompressedBytes;
UINT32 UncompressedBytes;
double CompressionRatio;
metrics = bulk->context->metrics;
if ((SrcSize <= 50) || (SrcSize >= 16384))
{
@ -231,24 +233,15 @@ int bulk_compress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstDat
CompressedBytes = *pDstSize;
UncompressedBytes = SrcSize;
bulk->TotalUncompressedBytes += UncompressedBytes;
bulk->TotalCompressedBytes += CompressedBytes;
CompressionRatio = metrics_write_bytes(metrics, UncompressedBytes, CompressedBytes);
#ifdef WITH_BULK_DEBUG
{
UINT32 type;
double CompressionRatio;
double TotalCompressionRatio;
type = bulk->CompressionLevel;
CompressionRatio = ((double) CompressedBytes) / ((double) UncompressedBytes);
TotalCompressionRatio = ((double) bulk->TotalCompressedBytes) / ((double) bulk->TotalUncompressedBytes);
printf("Compress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%d / %d)\n",
type, bulk_get_compression_flags_string(*pFlags), *pFlags,
printf("Compress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%u / %u)\n",
bulk->CompressionLevel, bulk_get_compression_flags_string(*pFlags), *pFlags,
CompressionRatio, CompressedBytes, UncompressedBytes,
TotalCompressionRatio, bulk->TotalCompressedBytes, bulk->TotalUncompressedBytes);
metrics->TotalCompressionRatio, (UINT32) metrics->TotalCompressedBytes,
(UINT32) metrics->TotalUncompressedBytes);
}
#endif
}
@ -293,9 +286,6 @@ rdpBulk* bulk_new(rdpContext* context)
bulk->xcrushSend = xcrush_context_new(TRUE);
bulk->CompressionLevel = context->settings->CompressionLevel;
bulk->TotalCompressedBytes = 0;
bulk->TotalUncompressedBytes = 0;
}
return bulk;

View File

@ -40,8 +40,6 @@ struct rdp_bulk
XCRUSH_CONTEXT* xcrushRecv;
XCRUSH_CONTEXT* xcrushSend;
BYTE OutputBuffer[65536];
UINT64 TotalCompressedBytes;
UINT64 TotalUncompressedBytes;
};
#define BULK_COMPRESSION_FLAGS_MASK 0xE0

View File

@ -405,6 +405,8 @@ int freerdp_context_new(freerdp* instance)
context->pubSub = PubSub_New(TRUE);
PubSub_AddEventTypes(context->pubSub, FreeRDP_Events, sizeof(FreeRDP_Events) / sizeof(wEventType));
context->metrics = metrics_new(context);
rdp = rdp_new(context);
instance->input = rdp->input;
instance->update = rdp->update;
@ -458,6 +460,8 @@ void freerdp_context_free(freerdp* instance)
PubSub_Free(instance->context->pubSub);
metrics_free(instance->context->metrics);
free(instance->context);
instance->context = NULL;
}

59
libfreerdp/core/metrics.c Normal file
View File

@ -0,0 +1,59 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Protocol Metrics
*
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "rdp.h"
double metrics_write_bytes(rdpMetrics* metrics, UINT32 UncompressedBytes, UINT32 CompressedBytes)
{
double CompressionRatio;
metrics->TotalUncompressedBytes += UncompressedBytes;
metrics->TotalCompressedBytes += CompressedBytes;
CompressionRatio = ((double) CompressedBytes) / ((double) UncompressedBytes);
metrics->TotalCompressionRatio = ((double) metrics->TotalCompressedBytes) / ((double) metrics->TotalUncompressedBytes);
return CompressionRatio;
}
rdpMetrics* metrics_new(rdpContext* context)
{
rdpMetrics* metrics;
metrics = (rdpMetrics*) calloc(1, sizeof(rdpMetrics));
if (metrics)
{
metrics->context = context;
}
return metrics;
}
void metrics_free(rdpMetrics* metrics)
{
if (!metrics)
return;
free(metrics);
}

View File

@ -436,6 +436,8 @@ void freerdp_peer_context_new(freerdp_peer* client)
client->context->ServerMode = TRUE;
client->context->metrics = metrics_new(client->context);
rdp = rdp_new(client->context);
client->input = rdp->input;
@ -474,8 +476,7 @@ freerdp_peer* freerdp_peer_new(int sockfd)
{
freerdp_peer* client;
client = (freerdp_peer*) malloc(sizeof(freerdp_peer));
ZeroMemory(client, sizeof(freerdp_peer));
client = (freerdp_peer*) calloc(1, sizeof(freerdp_peer));
freerdp_tcp_set_no_delay(sockfd, TRUE);