forked from DirectFB/directfb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
366 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/* | ||
(c) Copyright 2012-2013 DirectFB integrated media GmbH | ||
(c) Copyright 2001-2013 The world wide DirectFB Open Source Community (directfb.org) | ||
(c) Copyright 2000-2004 Convergence (integrated media) GmbH | ||
All rights reserved. | ||
Written by Denis Oliver Kropp <[email protected]>, | ||
Andreas Shimokawa <[email protected]>, | ||
Marek Pikarski <[email protected]>, | ||
Sven Neumann <[email protected]>, | ||
Ville Syrjälä <[email protected]> and | ||
Claudio Ciccani <[email protected]>. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2 of the License, or (at your option) any later version. | ||
This library 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 | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the | ||
Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
|
||
|
||
#include <config.h> | ||
|
||
#include <direct/EvLog.h> | ||
#include <direct/Mutex.h> | ||
|
||
extern "C" { | ||
#include <direct/log.h> | ||
#include <direct/system.h> | ||
#include <direct/thread.h> | ||
} | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
/**********************************************************************************************************************/ | ||
|
||
namespace Direct { | ||
|
||
class EvLog { | ||
public: | ||
class Entry { | ||
public: | ||
void *ctx; | ||
std::string event; | ||
std::string info; | ||
std::string function; | ||
std::string file; | ||
unsigned int line; | ||
long long micros; | ||
std::string thread_name; | ||
|
||
Entry( void *ctx, | ||
std::string event, | ||
std::string info, | ||
std::string function, | ||
std::string file, | ||
unsigned int line ) | ||
: | ||
ctx( ctx ), | ||
event( event ), | ||
info( info ), | ||
function( function ), | ||
file( file ), | ||
line( line ) | ||
{ | ||
micros = direct_clock_get_time( DIRECT_CLOCK_MONOTONIC ); | ||
thread_name = direct_thread_self_name(); | ||
} | ||
|
||
void dump( size_t n ) | ||
{ | ||
long long millis = micros / 1000LL; | ||
|
||
direct_log_printf( NULL, | ||
"(=) [%-16.16s %3lld.%03lld,%03lld] (%5d) [%2zu] %-40s | %s\n", | ||
thread_name.c_str(), millis / 1000LL, millis % 1000LL, micros % 1000LL, | ||
direct_gettid(), n, event.c_str(), info.c_str() ); | ||
} | ||
}; | ||
|
||
std::map<void*,std::vector<Entry>> map; | ||
|
||
void log( void *ctx, | ||
const char *event, | ||
const char *info, | ||
const char *function, | ||
const char *file, | ||
unsigned int line ) | ||
{ | ||
map[ctx].push_back( Entry( ctx, event, info, function, file, line ) ); | ||
} | ||
|
||
void dump( void *ctx, | ||
const char *event ) | ||
{ | ||
if (ctx) { | ||
dump( map[ctx], event ); | ||
} | ||
else { | ||
for (auto it = map.begin(); it != map.end(); it++) | ||
dump( (*it).second, event ); | ||
} | ||
} | ||
|
||
void dump( std::vector<Entry> &entries, | ||
const char *event ) | ||
{ | ||
long long micros = direct_clock_get_time( DIRECT_CLOCK_MONOTONIC ); | ||
long long millis = micros / 1000LL; | ||
DirectThread *thread = direct_thread_self(); | ||
const char *name = thread ? thread->name : " NO NAME"; | ||
|
||
direct_log_printf( NULL, | ||
"(=) [%-16.16s %3lld.%03lld,%03lld] (%5d) ============================== Event Log | %s | %p =====\n", | ||
name, millis / 1000LL, millis % 1000LL, micros % 1000LL, | ||
direct_gettid(), "", entries[0].ctx ); // FIXME: add name | ||
|
||
size_t n = 0; | ||
|
||
for (auto it2 = entries.begin(); it2 != entries.end(); it2++) { | ||
Entry &entry = *it2; | ||
|
||
if (!event || entry.event == event) | ||
entry.dump( n ); | ||
|
||
n++; | ||
} | ||
} | ||
}; | ||
|
||
class EvLogs { | ||
public: | ||
std::map<std::string,EvLog> map; | ||
Direct::Mutex lock; | ||
}; | ||
|
||
static EvLogs logs; | ||
|
||
|
||
extern "C" { | ||
|
||
void direct_evlog_log( const char *evlog, | ||
void *ctx, | ||
const char *event, | ||
const char *info, | ||
const char *function, | ||
const char *file, | ||
unsigned int line ) | ||
{ | ||
Direct::Mutex::Lock l1( logs.lock ); | ||
|
||
logs.map[evlog].log( ctx, event, info, function, file, line ); | ||
} | ||
|
||
void direct_evlog_dump( const char *evlog, | ||
void *ctx, | ||
const char *event ) | ||
{ | ||
Direct::Mutex::Lock l1( logs.lock ); | ||
|
||
if (evlog) { | ||
logs.map[evlog].dump( ctx, event ); | ||
} | ||
else { | ||
for (auto it = logs.map.begin(); it != logs.map.end(); it++) { | ||
EvLog &log = (*it).second; | ||
|
||
log.dump( ctx, event ); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
(c) Copyright 2001-2012 The world wide DirectFB Open Source Community (directfb.org) | ||
(c) Copyright 2000-2004 Convergence (integrated media) GmbH | ||
All rights reserved. | ||
Written by Denis Oliver Kropp <[email protected]>, | ||
Andreas Hundt <[email protected]>, | ||
Sven Neumann <[email protected]>, | ||
Ville Syrjälä <[email protected]> and | ||
Claudio Ciccani <[email protected]>. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2 of the License, or (at your option) any later version. | ||
This library 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 | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the | ||
Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
#ifndef ___Direct__EvLog__H___ | ||
#define ___Direct__EvLog__H___ | ||
|
||
#ifdef __cplusplus | ||
#include <direct/Types++.h> | ||
|
||
extern "C" { | ||
#endif | ||
|
||
#include <direct/debug.h> | ||
|
||
|
||
void direct_evlog_log ( const char *evlog, | ||
void *ctx, | ||
const char *event, | ||
const char *info, | ||
const char *function, | ||
const char *file, | ||
unsigned int line ); | ||
|
||
void direct_evlog_dump( const char *evlog, | ||
void *ctx, | ||
const char *event ); | ||
|
||
static inline void | ||
direct_evlog_dump_all( void ) | ||
{ | ||
direct_evlog_dump( NULL, NULL, NULL ); | ||
|
||
// FIXME: add cleanup | ||
} | ||
|
||
|
||
#if D_DEBUG_ENABLED | ||
|
||
#define D_EVLOG( evlog, ctx, event, info ) \ | ||
do { \ | ||
direct_evlog_log( evlog, ctx, event, info, __FUNCTION__, __FILE__, __LINE__ ); \ | ||
} while (0) | ||
|
||
#else | ||
|
||
#define D_EVLOG( evlog, ctx, event, info ) \ | ||
do { \ | ||
} while (0) | ||
|
||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
|
||
|
||
namespace Direct { | ||
|
||
|
||
} | ||
|
||
|
||
#endif // __cplusplus | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
#include <config.h> | ||
|
||
#if 0 | ||
|
||
extern "C" { | ||
#include <direct/mem.h> | ||
#include <direct/messages.h> | ||
#include <direct/trace.h> | ||
} | ||
|
||
#include <string> | ||
|
||
|
||
//pair 1 | ||
void* operator new(std::size_t size) throw(std::bad_alloc) | ||
{ | ||
void *ptr; | ||
|
||
ptr = D_MALLOC( size ); | ||
// D_INFO( "new %zu -> %p\n", size, ptr ); | ||
//D_INFO( "new %zu -> %p (%p)\n", size, ptr, | ||
// direct_trace_get_caller() ); | ||
//D_INFO( "new %zu -> %p (%s)\n", size, ptr, | ||
// direct_trace_lookup_symbol_at( __builtin_return_address(1)/*direct_trace_get_caller()*/ ) ); | ||
|
||
return ptr; | ||
} | ||
void operator delete(void* ptr) throw() | ||
{ | ||
// D_INFO( "free %p\n", ptr ); | ||
D_FREE( ptr ); | ||
} | ||
|
||
//pair 2 | ||
void* operator new (std::size_t size, const std::nothrow_t&) throw() | ||
{ | ||
void *ptr; | ||
|
||
ptr = D_MALLOC( size ); | ||
// D_INFO( "new %zu -> %p\n", size, ptr ); | ||
|
||
return ptr; | ||
} | ||
void operator delete (void* ptr, const std::nothrow_t&) throw() | ||
{ | ||
// D_INFO( "free %p\n", ptr ); | ||
D_FREE( ptr ); | ||
} | ||
|
||
//pair 3 | ||
void* operator new [](std::size_t size) throw(std::bad_alloc) | ||
{ | ||
void *ptr; | ||
|
||
ptr = D_MALLOC( size ); | ||
// D_INFO( "new %zu -> %p\n", size, ptr ); | ||
|
||
return ptr; | ||
} | ||
void operator delete[](void* ptr) throw() | ||
{ | ||
// D_INFO( "free %p\n", ptr ); | ||
D_FREE( ptr ); | ||
} | ||
|
||
//pair 4 | ||
void* operator new [](std::size_t size, const std::nothrow_t&) throw() | ||
{ | ||
void *ptr; | ||
|
||
ptr = D_MALLOC( size ); | ||
// D_INFO( "new %zu -> %p\n", size, ptr ); | ||
|
||
return ptr; | ||
} | ||
void operator delete[](void* ptr, const std::nothrow_t&) throw() | ||
{ | ||
// D_INFO( "free %p\n", ptr ); | ||
D_FREE( ptr ); | ||
} | ||
|
||
#endif | ||
|