Addition rtdsc for tracing purposes

This commit is contained in:
Mark Riddoch 2014-09-23 22:09:36 +01:00
parent d561ccb089
commit 7562d49a95
3 changed files with 86 additions and 0 deletions

View File

@ -31,6 +31,12 @@
#include <config.h>
#include <housekeeper.h>
#define PROFILE_POLL 1
#if PROFILE_POLL
#include <rdtsc.h>
#endif
extern int lm_enabled_logfiles_bitmask;
/**
@ -343,6 +349,9 @@ int thread_id = (int)arg;
bool no_op = false;
static bool process_zombies_only = false; /*< flag for all threads */
DCB *zombies = NULL;
#if PROFILE_POLL
CYCLES cycles[2];
#endif
/** Add this thread to the bitmask of running polling threads */
bitmask_set(&poll_mask, thread_id);
@ -456,6 +465,18 @@ DCB *zombies = NULL;
DCB *dcb = (DCB *)events[i].data.ptr;
__uint32_t ev = events[i].events;
#if PROFILE_POLL
if (i > 0)
{
LOGIF(LT, (skygw_log_write(
LOGFILE_TRACE,
"Delayed behind event that "
"took %ld cycles",
cycles[1] - cycles[0])));
}
cycles[0] = rdtsc();
#endif
CHK_DCB(dcb);
if (thread_data)
{
@ -657,6 +678,9 @@ DCB *zombies = NULL;
else
spinlock_release(&dcb->dcb_initlock);
}
#if PROFILE_POLL
cycles[1] = rdtsc();
#endif
} /*< for */
no_op = FALSE;
}

61
server/include/rdtsc.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef _RDTSC_H
#define _RDTSC_H
/*
* This file is distributed as part of the SkySQL Gateway. It 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,
* version 2.
*
* This program 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 program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright SkySQL Ab 2014
*/
/**
* @file rdtsc.h Access the process time-stamp counter
*
* This is an Intel only facilty that is used to access an accurate time
* value, the granularity of which is related to the processor clock speed
* and the overhead for access is much lower than using any system call
* mechanism.
*
*
* @verbatim
* Revision History
*
* Date Who Description
* 19/09/2014 Mark Riddoch Initial implementation
*
* @endverbatim
*/
typedef unsigned long long CYCLES;
/**
* Get the current time-stamp counter value from the processor. This is the
* count of CPU cyceles as a 64 bit value.
*
* The value returned is related to the clock speed, to obtian a value in
* seconds divide the returned value by the clock frequency for the processor.
*
* Note, on multi-processsor systems care much be taken to avoid the thread
* moving to a different processor when taken succsive value of RDTSC to
* obtian accurate timing. This may be done by setting pocessor affinity for
* the thread. See sched_setaffinity/sched_getaffinity.
*
* @return CPU cycle count
*/
static __inline__ CYCLES rdtsc(void)
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
#endif

View File

@ -194,6 +194,7 @@ typedef struct router_instance {
char *uuid; /*< UUID for the router to use w/master */
int masterid; /*< Server ID of the master */
int serverid; /*< Server ID to use with master */
int initbinlog; /*< Initial binlog file number */
char *user; /*< User name to use with master */
char *password; /*< Password to use with master */
char *fileroot; /*< Root of binlog filename */