git-svn-id: svn://db.shs.com.ru/pip@185 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
94
src/system/piintrospection.cpp
Normal file
94
src/system/piintrospection.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piintrospection.h"
|
||||
|
||||
|
||||
PIIntrospectionContainers::PIIntrospectionContainers() {
|
||||
count = 0;
|
||||
bytes_allocated = bytes_used = 0;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionThreads::PIIntrospectionThreads() {
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionContainers * __PIIntrospectionContainers__::p = 0;
|
||||
PIIntrospectionThreads * __PIIntrospectionThreads__::p = 0;
|
||||
|
||||
|
||||
void PIIntrospectionThreads::registerThread(int id, short prior, const PIString & name) {
|
||||
mutex.lock();
|
||||
ThreadInfo & ti(threads[id]);
|
||||
ti.id = id;
|
||||
ti.priority = prior;
|
||||
ti.name = name;
|
||||
//piCout << "register thread" << id << name;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionThreads::unregisterThread(int id) {
|
||||
mutex.lock();
|
||||
threads.remove(id);
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerNew() {
|
||||
mutex.lock();
|
||||
count++;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerDelete() {
|
||||
mutex.lock();
|
||||
count--;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerAlloc(ullong cnt) {
|
||||
mutex.lock();
|
||||
bytes_allocated += cnt;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerFree(ullong cnt) {
|
||||
mutex.lock();
|
||||
bytes_allocated -= cnt;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerUsed(ullong cnt) {
|
||||
mutex.lock();
|
||||
bytes_used += cnt;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerUnused(ullong cnt) {
|
||||
mutex.lock();
|
||||
bytes_used -= cnt;
|
||||
mutex.unlock();
|
||||
}
|
||||
90
src/system/piintrospection.h
Normal file
90
src/system/piintrospection.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_H
|
||||
#define PIINTROSPECTION_H
|
||||
|
||||
#include "pistring.h"
|
||||
#include "pimutex.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PIIntrospectionThreads
|
||||
{
|
||||
friend class __PIIntrospectionThreads__;
|
||||
PIIntrospectionThreads();
|
||||
public:
|
||||
struct ThreadInfo {
|
||||
ThreadInfo() {id = 0; priority = 0;}
|
||||
PIString name;
|
||||
int id;
|
||||
short priority;
|
||||
};
|
||||
|
||||
void registerThread(int id, short prior, const PIString & name);
|
||||
void unregisterThread(int id);
|
||||
|
||||
PIMap<int, ThreadInfo> threads;
|
||||
PIMutex mutex;
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT PIIntrospectionContainers
|
||||
{
|
||||
friend class __PIIntrospectionContainers__;
|
||||
PIIntrospectionContainers();
|
||||
public:
|
||||
void containerNew();
|
||||
void containerDelete();
|
||||
void containerAlloc(ullong cnt);
|
||||
void containerFree(ullong cnt);
|
||||
void containerUsed(ullong cnt);
|
||||
void containerUnused(ullong cnt);
|
||||
|
||||
uint count;
|
||||
ullong bytes_allocated;
|
||||
ullong bytes_used;
|
||||
PIMutex mutex;
|
||||
};
|
||||
|
||||
|
||||
class __PIIntrospectionContainers__ {
|
||||
public:
|
||||
__PIIntrospectionContainers__() {if (!p) p = new PIIntrospectionContainers();}
|
||||
static PIIntrospectionContainers * get() {static __PIIntrospectionContainers__ * r = new __PIIntrospectionContainers__(); return r->p;}
|
||||
static PIIntrospectionContainers * p;
|
||||
};
|
||||
|
||||
|
||||
class __PIIntrospectionThreads__ {
|
||||
public:
|
||||
__PIIntrospectionThreads__() {if (!p) p = new PIIntrospectionThreads();}
|
||||
static PIIntrospectionThreads * get() {static __PIIntrospectionThreads__ * r = new __PIIntrospectionThreads__(); return r->p;}
|
||||
static PIIntrospectionThreads * p;
|
||||
};
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionContainers & v) {b << v.count << v.bytes_allocated << v.bytes_used; return b;}
|
||||
inline PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v) {b << v.id << v.priority << v.name; return b;}
|
||||
|
||||
inline PIByteArray & operator >>(PIByteArray & b, PIIntrospectionContainers & v) {b >> v.count >> v.bytes_allocated >> v.bytes_used; return b;}
|
||||
inline PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v) {b >> v.id >> v.priority >> v.name; return b;}
|
||||
|
||||
#define PIINTROSPECTION_CONTAINERS __PIIntrospectionContainers__::get()
|
||||
#define PIINTROSPECTION_THREADS __PIIntrospectionThreads__::get()
|
||||
|
||||
#endif // PIINTROSPECTION_H
|
||||
30
src/system/piintrospection_proxy.cpp
Normal file
30
src/system/piintrospection_proxy.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piintrospection_proxy.h"
|
||||
#include "piintrospection.h"
|
||||
|
||||
void __PIIntrospection__registerThread(int id, short prior, const PIString & name) {PIINTROSPECTION_THREADS->registerThread(id, prior, name);}
|
||||
void __PIIntrospection__unregisterThread(int id) {PIINTROSPECTION_THREADS->unregisterThread(id);}
|
||||
void __PIIntrospection__containerNew() {PIINTROSPECTION_CONTAINERS->containerNew();}
|
||||
void __PIIntrospection__containerDelete() {PIINTROSPECTION_CONTAINERS->containerDelete();}
|
||||
void __PIIntrospection__containerAlloc(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerAlloc(cnt);}
|
||||
void __PIIntrospection__containerFree(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerFree(cnt);}
|
||||
void __PIIntrospection__containerUsed(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUsed(cnt);}
|
||||
void __PIIntrospection__containerUnused(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUnused(cnt);}
|
||||
56
src/system/piintrospection_proxy.h
Normal file
56
src/system/piintrospection_proxy.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_PROXY_H
|
||||
#define PIINTROSPECTION_PROXY_H
|
||||
|
||||
#include "pibase.h"
|
||||
|
||||
class PIString;
|
||||
|
||||
void __PIIntrospection__registerThread(int id, short prior, const PIString & name);
|
||||
void __PIIntrospection__unregisterThread(int id);
|
||||
void __PIIntrospection__containerNew();
|
||||
void __PIIntrospection__containerDelete();
|
||||
void __PIIntrospection__containerAlloc(ullong cnt);
|
||||
void __PIIntrospection__containerFree(ullong cnt);
|
||||
void __PIIntrospection__containerUsed(ullong cnt);
|
||||
void __PIIntrospection__containerUnused(ullong cnt);
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
# define PIINTROSPECTION_CONTAINER_NEW() __PIIntrospection__containerNew();
|
||||
# define PIINTROSPECTION_CONTAINER_DELETE() __PIIntrospection__containerDelete();
|
||||
# define PIINTROSPECTION_CONTAINER_USED(cnt) __PIIntrospection__containerUsed(cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_UNUSED(cnt) __PIIntrospection__containerUnused(cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_ALLOC(cnt) __PIIntrospection__containerAlloc(cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_FREE(cnt) __PIIntrospection__containerFree(cnt);
|
||||
# define PIINTROSPECTION_REGISTER_THREAD(id, pr, name) __PIIntrospection__registerThread(id, pr, name);
|
||||
# define PIINTROSPECTION_UNREGISTER_THREAD(id) __PIIntrospection__unregisterThread(id);
|
||||
#else
|
||||
# define PIINTROSPECTION_CONTAINER_NEW()
|
||||
# define PIINTROSPECTION_CONTAINER_DELETE()
|
||||
# define PIINTROSPECTION_CONTAINER_USED(tcnt)
|
||||
# define PIINTROSPECTION_CONTAINER_UNUSED(cnt)
|
||||
# define PIINTROSPECTION_CONTAINER_ALLOC(cnt)
|
||||
# define PIINTROSPECTION_CONTAINER_FREE(cnt)
|
||||
# define PIINTROSPECTION_REGISTER_THREAD(id, pr, name)
|
||||
# define PIINTROSPECTION_UNREGISTER_THREAD(id)
|
||||
#endif
|
||||
|
||||
#endif // PIINTROSPECTION_PROXY_H
|
||||
Reference in New Issue
Block a user