在AIX上的C++中,有没有什么AIX运行时库调用可以用来监视与正在运行的进程相关的线程的状态?我正在尝试解决一个关机时崩溃的问题,我认为这个问题是由程序在所有线程都加入之前退出造成的。
我意识到,在多线程环境中,准确记录线程的状态并不容易,因为它们很可能在读取状态和显示状态之间发生了变化,但任何东西-无论多么粗糙-都将是跟踪这一点的第一步。
发布于 2012-06-13 12:31:58
你说“关机时崩溃”……你的意思是系统崩溃和崩溃转储吗?如果是这样,那么你有大量的数据。如果你需要,我会用一个大的缓冲区启动系统跟踪。在系统崩溃和重启之后,你可以使用trcdead从转储中吸取跟踪缓冲区。另外,你还有系统的状态。
不应该是愚蠢的线程导致系统崩溃。
发布于 2012-06-13 21:09:42
首先,有一个系统跟踪工具。我没怎么用过它(有吗?)但它是线程安全的。
http://pic.dhe.ibm.com/infocenter/aix/v6r1/topic/com.ibm.aix.genprogc/doc/genprogc/trace_facility.htm#yg3100thri
和
http://pic.dhe.ibm.com/infocenter/aix/v6r1/topic/com.ibm.aix.genprogc/doc/genprogc/tracing.htm?resultof=%22%61%70%70%6c%69%63%61%74%69%6f%6e%22%20%22%61%70%70%6c%69%63%22%20%22%74%72%61%63%65%22%20
如果这是一个非常复杂的应用程序,我会连接真正的跟踪钩子并开发一个跟踪格式文件。这将是值得花费的时间。下面是一个更粗糙的方法。
我可能会追踪到这一点的方法是连接一个自己开发的跟踪或日志工具。在代码中,分散对日志例程的调用。然后返回并检查core文件,挖掘出日志缓冲区,这将告诉您命中的日志点的顺序。
这可能是一个迭代过程,您添加几个点,然后计算出您需要在代码的特定部分中更多的点,并在那里添加日志点。再试试。重复一遍。
日志例程实际上非常简单,并且利用了一个原子操作。我使用的是fetch_and_add。
long array[4096]; /* some power of 2 in size is my preference */
unsigned int index; /* int -- not a long */
/* trace 5 words each time. */
void log(long *a, long b, long c, long d, long e)
{
/*
* the 5 equals the number of args. The 4095 is one less than the
* size of the array. You can use mod if you want. Also, note that
* there are flavors of fetch_and_add for different sized
* variables. Pick the one that matches the size of index.
*/
int i = fetch_and_add(&indx, 5) & 4095;
/*
* at this point, array[i] ... array[i+4] have been effectively
* reserved. The time taken between the fetch_and_add and updating
* the array does not need to be atomic or locked. The only
* possible exception is you don't want the log to wrap within this
* time but that would be very unlikely.
*/
array[i] = *a;
array[i+1] = b;
array[i+2] = c;
array[i+3] = d;
array[i+4] = e;
}
/* your original code spinkle calls to log */
int whatever(long arg1, int arg2)
{
log("WHT1", arg1, arg2, 0, 0);
foo = apple + pie;
bar = whisky + good;
dog = nice + pet;
cat = meow;
log("WHT2", foo, bar, log, dog);
/* ... */
}第一个参数的诀窍是,当您获取核心文件并转储数组时,您可以将其转储为十六进制和文本。从文本输出中,您可以快速看到正在调用哪些日志点。如果您有一个64位的应用程序,您可以使用8个字符,而不是将自己限制为4个字符。
请注意,index的值是core文件中的key。它会告诉您命中的最后一个日志点。然后向后遍历日志数组,以查看以前的日志点。
https://stackoverflow.com/questions/8992013
复制相似问题