19 #include "JackProfiler.h"    20 #include "JackServerGlobals.h"    21 #include "JackEngineControl.h"    22 #include "JackLockedEngine.h"    23 #include "JackArgParser.h"    30     JackProfilerClient::JackProfilerClient(jack_client_t* client, 
const char* name)
    33         char port_name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
    34         fRefNum = JackServerGlobals::fInstance->GetEngine()->GetClientRefNum(name);
    36         snprintf(port_name, 
sizeof(port_name) - 1, 
"%s:scheduling", name);
    37         fSchedulingPort = 
jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    39         snprintf(port_name, 
sizeof(port_name) - 1, 
"%s:duration", name);
    40         fDurationPort = 
jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    43     JackProfilerClient::~JackProfilerClient()
    50     JackProfiler::JackProfiler(jack_client_t* client, 
const JSList* params)
    51         :fClient(client), fLastMeasure(NULL)
    57         jack_log(
"JackProfiler::JackProfiler");
    59         fCPULoadPort = fDriverPeriodPort = fDriverEndPort = NULL;
    63         for (node = params; node; node = jack_slist_next(node)) {
    66             switch (param->character) {
    68                     fCPULoadPort = 
jack_port_register(client, 
"cpu_load", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    72                     fDriverPeriodPort = 
jack_port_register(client, 
"driver_period", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    76                     fDriverEndPort = 
jack_port_register(client, 
"driver_end_time", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    84             for (
int i = 0; ports[i]; ++i) {
    85                 std::string str = std::string(ports[i]);
    86                 ClientRegistration(str.substr(0, str.find_first_of(
':')).c_str(), 1, 
this);
    96     JackProfiler::~JackProfiler()
    98         jack_log(
"JackProfiler::~JackProfiler");
   101     void JackProfiler::ClientRegistration(
const char* name, 
int val, 
void *arg)
   110         profiler->fMutex.Lock();
   112             std::map<std::string, JackProfilerClient*>::iterator it = profiler->fClientTable.find(name);
   113             if (it == profiler->fClientTable.end()) {
   118             std::map<std::string, JackProfilerClient*>::iterator it = profiler->fClientTable.find(name);
   119             if (it != profiler->fClientTable.end()) {
   120                 jack_log(
"Client %s removed", name);
   121                 profiler->fClientTable.erase(it);
   122                 delete((*it).second);
   125         profiler->fMutex.Unlock();
   129     int JackProfiler::Process(jack_nframes_t nframes, 
void* arg)
   133         if (profiler->fCPULoadPort) {
   136             for (
unsigned int i = 0; i < nframes; i++) {
   137                 buffer_cpu_load[i] = cpu_load / 100.f;
   147        if (profiler->fLastMeasure && profiler->fMutex.Trylock()) {
   149             if (profiler->fDriverPeriodPort) {
   150                 float* buffer_driver_period = (
float*)
jack_port_get_buffer(profiler->fDriverPeriodPort, nframes);
   151                 float value1 = (float(measure->fPeriodUsecs) - float(measure->fCurCycleBegin - profiler->fLastMeasure->fCurCycleBegin)) / 
float(measure->fPeriodUsecs);
   152                 for (
unsigned int i = 0; i < nframes; i++) {
   153                     buffer_driver_period[i] = value1;
   157             if (profiler->fDriverEndPort) {
   158                 float* buffer_driver_end_time = (
float*)
jack_port_get_buffer(profiler->fDriverEndPort, nframes);
   159                 float value2 = (float(measure->fPrevCycleEnd - profiler->fLastMeasure->fCurCycleBegin)) / 
float(measure->fPeriodUsecs);
   160                 for (
unsigned int i = 0; i < nframes; i++) {
   161                     buffer_driver_end_time[i] = value2;
   165             std::map<std::string, JackProfilerClient*>::iterator it;
   166             for (it = profiler->fClientTable.begin(); it != profiler->fClientTable.end(); it++) {
   167                 int ref = (*it).second->fRefNum;
   168                 long d5 = long(measure->fClientTable[ref].fSignaledAt - profiler->fLastMeasure->fCurCycleBegin);
   169                 long d6 = long(measure->fClientTable[ref].fAwakeAt - profiler->fLastMeasure->fCurCycleBegin);
   170                 long d7 = long(measure->fClientTable[ref].fFinishedAt - profiler->fLastMeasure->fCurCycleBegin);
   172                 float* buffer_scheduling = (
float*)
jack_port_get_buffer((*it).second->fSchedulingPort, nframes);
   173                 float value3 = float(d6 - d5) / float(measure->fPeriodUsecs);
   175                 for (
unsigned int i = 0; i < nframes; i++) {
   176                     buffer_scheduling[i] = value3;
   180                 float value4 = float(d7 - d6) / float(measure->fPeriodUsecs);
   182                 for (
unsigned int i = 0; i < nframes; i++) {
   183                     buffer_duration[i] = value4;
   187             profiler->fMutex.Unlock();
   189         profiler->fLastMeasure = measure;
   201 #include "driver_interface.h"   203     using namespace Jack;
   213         desc = jack_driver_descriptor_construct(
"profiler", JackDriverNone, 
"real-time server profiling", &filler);
   216         jack_driver_descriptor_add_parameter(desc, &filler, 
"cpu-load", 
'c', JackDriverParamBool, &value, NULL, 
"Show DSP CPU load", NULL);
   217         jack_driver_descriptor_add_parameter(desc, &filler, 
"driver-period", 
'p', JackDriverParamBool, &value, NULL, 
"Show driver period", NULL);
   218         jack_driver_descriptor_add_parameter(desc, &filler, 
"driver-end-time", 
'e', JackDriverParamBool, &value, NULL, 
"Show driver end time", NULL);
   223     SERVER_EXPORT 
int jack_internal_initialize(jack_client_t* jack_client, 
const JSList* params)
   240     SERVER_EXPORT 
int jack_initialize(jack_client_t* jack_client, 
const char* load_init)
   243         bool parse_params = 
true;
   248         if ( parser.GetArgc() > 0 )
   249             parse_params = parser.ParseParams ( desc, ¶ms );
   252             res = jack_internal_initialize ( jack_client, params );
   253             parser.FreeParams ( params );
   258     SERVER_EXPORT 
void jack_finish(
void* arg)
 LIB_EXPORT int jack_set_client_registration_callback(jack_client_t *, JackClientRegistrationCallback registration_callback, void *arg)
LIB_EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *)
LIB_EXPORT int jack_set_process_callback(jack_client_t *client, JackProcessCallback process_callback, void *arg)
LIB_EXPORT int jack_activate(jack_client_t *client)
LIB_EXPORT jack_port_t * jack_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size)
SERVER_EXPORT void jack_info(const char *fmt,...)
LIB_EXPORT char * jack_get_client_name(jack_client_t *client)
LIB_EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t)
Timing stucture for a table of clients. 
LIB_EXPORT float jack_cpu_load(jack_client_t *client)
Engine control in shared memory. 
LIB_EXPORT const char ** jack_get_ports(jack_client_t *, const char *port_name_pattern, const char *type_name_pattern, unsigned long flags)
SERVER_EXPORT void jack_log(const char *fmt,...)
Server real-time monitoring.