|
Packit |
1fb8d4 |
/**
|
|
Packit |
1fb8d4 |
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
Packit |
1fb8d4 |
* Profiler Utils
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Copyright 2011 Stephen Erisman
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
1fb8d4 |
* you may not use this file except in compliance with the License.
|
|
Packit |
1fb8d4 |
* You may obtain a copy of the License at
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
1fb8d4 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
1fb8d4 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
1fb8d4 |
* See the License for the specific language governing permissions and
|
|
Packit |
1fb8d4 |
* limitations under the License.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
1fb8d4 |
#include "config.h"
|
|
Packit |
1fb8d4 |
#endif
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <stdio.h>
|
|
Packit |
1fb8d4 |
#include <stdlib.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <freerdp/utils/profiler.h>
|
|
Packit |
1fb8d4 |
#include <freerdp/log.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define TAG FREERDP_TAG("utils")
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
struct _PROFILER
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
char* name;
|
|
Packit |
1fb8d4 |
STOPWATCH* stopwatch;
|
|
Packit |
1fb8d4 |
};
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
PROFILER* profiler_create(const char* name)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
PROFILER* profiler = (PROFILER*) calloc(1, sizeof(PROFILER));
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (!profiler)
|
|
Packit |
1fb8d4 |
return NULL;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
profiler->name = _strdup(name);
|
|
Packit |
1fb8d4 |
profiler->stopwatch = stopwatch_create();
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (!profiler->name || !profiler->stopwatch)
|
|
Packit |
1fb8d4 |
goto fail;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
return profiler;
|
|
Packit |
1fb8d4 |
fail:
|
|
Packit |
1fb8d4 |
profiler_free(profiler);
|
|
Packit |
1fb8d4 |
return NULL;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void profiler_free(PROFILER* profiler)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
if (profiler)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
free(profiler->name);
|
|
Packit |
1fb8d4 |
stopwatch_free(profiler->stopwatch);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
free(profiler);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void profiler_enter(PROFILER* profiler)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
stopwatch_start(profiler->stopwatch);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void profiler_exit(PROFILER* profiler)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
stopwatch_stop(profiler->stopwatch);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void profiler_print_header(void)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
WLog_INFO(TAG, "-------------------------------+------------+-------------+-----------+-------");
|
|
Packit |
1fb8d4 |
WLog_INFO(TAG, "PROFILER NAME | COUNT | TOTAL | AVG | IPS");
|
|
Packit |
1fb8d4 |
WLog_INFO(TAG, "-------------------------------+------------+-------------+-----------+-------");
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void profiler_print(PROFILER* profiler)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
double s = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
|
|
Packit |
1fb8d4 |
double avg = profiler->stopwatch->count == 0 ? 0 : s / profiler->stopwatch->count;
|
|
Packit |
1fb8d4 |
WLog_INFO(TAG, "%-30s | %10u | %10.4fs | %8.6fs | %6.0f",
|
|
Packit |
1fb8d4 |
profiler->name, profiler->stopwatch->count, s, avg, profiler->stopwatch->count / s);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void profiler_print_footer(void)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
WLog_INFO(TAG, "-------------------------------+------------+-------------+-----------+-------");
|
|
Packit |
1fb8d4 |
}
|