strongswan/src/libstrongswan/threading/lock_profiler.h

103 lines
2.5 KiB
C
Raw Normal View History

2009-12-07 16:26:39 +00:00
/*
* Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2008 Martin Willi
* HSR Hochschule fuer Technik Rapperswil
2009-12-07 16:26:39 +00:00
*
* This program 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. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* 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.
*/
#ifndef THREADING_LOCK_PROFILER_H_
#define THREADING_LOCK_PROFILER_H_
#ifdef LOCK_PROFILER
#include <time.h>
/**
* Do not report mutexes with an overall waiting time smaller than this (in us)
*/
Spelling fixes * accumulating * acquire * alignment * appropriate * argument * assign * attribute * authenticate * authentication * authenticator * authority * auxiliary * brackets * callback * camellia * can't * cancelability * certificate * choinyambuu * chunk * collector * collision * communicating * compares * compatibility * compressed * confidentiality * configuration * connection * consistency * constraint * construction * constructor * database * decapsulated * declaration * decrypt * derivative * destination * destroyed * details * devised * dynamic * ecapsulation * encoded * encoding * encrypted * enforcing * enumerator * establishment * excluded * exclusively * exited * expecting * expire * extension * filter * firewall * foundation * fulfillment * gateways * hashing * hashtable * heartbeats * identifier * identifiers * identities * identity * implementers * indicating * initialize * initiate * initiation * initiator * inner * instantiate * legitimate * libraries * libstrongswan * logger * malloc * manager * manually * measurement * mechanism * message * network * nonexistent * object * occurrence * optional * outgoing * packages * packets * padding * particular * passphrase * payload * periodically * policies * possible * previously * priority * proposal * protocol * provide * provider * pseudo * pseudonym * public * qualifier * quantum * quintuplets * reached * reading * recommendation to * recommendation * recursive * reestablish * referencing * registered * rekeying * reliable * replacing * representing * represents * request * request * resolver * result * resulting * resynchronization * retriable * revocation * right * rollback * rule * rules * runtime * scenario * scheduled * security * segment * service * setting * signature * specific * specified * speed * started * steffen * strongswan * subjectaltname * supported * threadsafe * traffic * tremendously * treshold * unique * uniqueness * unknown * until * upper * using * validator * verification * version * version * warrior Closes strongswan/strongswan#164.
2020-02-05 04:30:52 +00:00
#define PROFILE_WAIT_TRESHOLD 10000
/**
* Do not report mutexes with an overall lock count smaller than this
*/
Spelling fixes * accumulating * acquire * alignment * appropriate * argument * assign * attribute * authenticate * authentication * authenticator * authority * auxiliary * brackets * callback * camellia * can't * cancelability * certificate * choinyambuu * chunk * collector * collision * communicating * compares * compatibility * compressed * confidentiality * configuration * connection * consistency * constraint * construction * constructor * database * decapsulated * declaration * decrypt * derivative * destination * destroyed * details * devised * dynamic * ecapsulation * encoded * encoding * encrypted * enforcing * enumerator * establishment * excluded * exclusively * exited * expecting * expire * extension * filter * firewall * foundation * fulfillment * gateways * hashing * hashtable * heartbeats * identifier * identifiers * identities * identity * implementers * indicating * initialize * initiate * initiation * initiator * inner * instantiate * legitimate * libraries * libstrongswan * logger * malloc * manager * manually * measurement * mechanism * message * network * nonexistent * object * occurrence * optional * outgoing * packages * packets * padding * particular * passphrase * payload * periodically * policies * possible * previously * priority * proposal * protocol * provide * provider * pseudo * pseudonym * public * qualifier * quantum * quintuplets * reached * reading * recommendation to * recommendation * recursive * reestablish * referencing * registered * rekeying * reliable * replacing * representing * represents * request * request * resolver * result * resulting * resynchronization * retriable * revocation * right * rollback * rule * rules * runtime * scenario * scheduled * security * segment * service * setting * signature * specific * specified * speed * started * steffen * strongswan * subjectaltname * supported * threadsafe * traffic * tremendously * treshold * unique * uniqueness * unknown * until * upper * using * validator * verification * version * version * warrior Closes strongswan/strongswan#164.
2020-02-05 04:30:52 +00:00
#define PROFILE_LOCK_TRESHOLD 1000
2009-12-07 16:26:39 +00:00
#include <utils/backtrace.h>
typedef struct lock_profile_t lock_profile_t;
struct lock_profile_t {
/**
* how long threads have waited for the lock in this mutex so far
*/
timeval_t waited;
/**
* How many times the lock has been invoked
*/
u_int locked;
2009-12-07 16:26:39 +00:00
/**
* backtrace where mutex has been created
*/
backtrace_t *backtrace;
};
/**
* Print and cleanup mutex profiler
*/
static inline void profiler_cleanup(lock_profile_t *profile)
{
if (profile->waited.tv_sec > 0 ||
Spelling fixes * accumulating * acquire * alignment * appropriate * argument * assign * attribute * authenticate * authentication * authenticator * authority * auxiliary * brackets * callback * camellia * can't * cancelability * certificate * choinyambuu * chunk * collector * collision * communicating * compares * compatibility * compressed * confidentiality * configuration * connection * consistency * constraint * construction * constructor * database * decapsulated * declaration * decrypt * derivative * destination * destroyed * details * devised * dynamic * ecapsulation * encoded * encoding * encrypted * enforcing * enumerator * establishment * excluded * exclusively * exited * expecting * expire * extension * filter * firewall * foundation * fulfillment * gateways * hashing * hashtable * heartbeats * identifier * identifiers * identities * identity * implementers * indicating * initialize * initiate * initiation * initiator * inner * instantiate * legitimate * libraries * libstrongswan * logger * malloc * manager * manually * measurement * mechanism * message * network * nonexistent * object * occurrence * optional * outgoing * packages * packets * padding * particular * passphrase * payload * periodically * policies * possible * previously * priority * proposal * protocol * provide * provider * pseudo * pseudonym * public * qualifier * quantum * quintuplets * reached * reading * recommendation to * recommendation * recursive * reestablish * referencing * registered * rekeying * reliable * replacing * representing * represents * request * request * resolver * result * resulting * resynchronization * retriable * revocation * right * rollback * rule * rules * runtime * scenario * scheduled * security * segment * service * setting * signature * specific * specified * speed * started * steffen * strongswan * subjectaltname * supported * threadsafe * traffic * tremendously * treshold * unique * uniqueness * unknown * until * upper * using * validator * verification * version * version * warrior Closes strongswan/strongswan#164.
2020-02-05 04:30:52 +00:00
profile->waited.tv_usec > PROFILE_WAIT_TRESHOLD ||
profile->locked > PROFILE_LOCK_TRESHOLD)
2009-12-07 16:26:39 +00:00
{
fprintf(stderr, "%d.%03ds / %d times in lock created at:",
profile->waited.tv_sec, profile->waited.tv_usec, profile->locked);
profile->backtrace->log(profile->backtrace, stderr, TRUE);
2009-12-07 16:26:39 +00:00
}
profile->backtrace->destroy(profile->backtrace);
}
/**
* Initialize mutex profiler
*/
static inline void profiler_init(lock_profile_t *profile)
{
profile->backtrace = backtrace_create(2);
timerclear(&profile->waited);
profile->locked = 0;
2009-12-07 16:26:39 +00:00
}
#define profiler_start(profile) { \
struct timeval _start, _end, _diff; \
(profile)->locked++; \
2009-12-07 16:26:39 +00:00
time_monotonic(&_start);
#define profiler_end(profile) \
time_monotonic(&_end); \
timersub(&_end, &_start, &_diff); \
timeradd(&(profile)->waited, &_diff, &(profile)->waited); }
#else /* !LOCK_PROFILER */
#define lock_profile_t struct {}
#define profiler_cleanup(...) {}
#define profiler_init(...) {}
#define profiler_start(...) {}
#define profiler_end(...) {}
#endif /* LOCK_PROFILER */
#endif /* THREADING_LOCK_PROFILER_H_ */