跟踪“记忆增长”一个过程 [英] Tracking the "memory growth" of a process

查看:72
本文介绍了跟踪“记忆增长”一个过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了一种非常简单的跟踪内存增长的方法。运行时的进程。它涉及一个头文件和一个

shell脚本。


这里是头文件:

//// //////头文件开始///////////////

#ifndef _VIRTMEMINFO_H_

#define _VIRTMEMINFO_H_


#include< stdio.h>

#include< stdlib.h>

#include< sys / types.h>

#include< unistd.h>


#define VMEM_BUF_SIZE 200

#define VMEM_ENV_VAR" VMEM_ENV_VAR"

#define CHK_SIZE \

{\

if(char * envVar = getenv(VMEM_ENV_VAR))\

{\

char buf [VMEM_BUF_SIZE]; \\ b
sprintf(buf,"%s%s%d%d%d%d",envVar,\

__FILE __,_ _ _ 3,\

getpid(),getppid(),getpagesize()); \

system(buf); \

} \

}


#endif // _ VIRTMEMINFO_H_

/// ///////头文件结束///////////////

这里是shell脚本:

/ ///////// Shell-script开始///////////////

#!/ bin / ksh



#$ 1:文件名

#$ 2:Linenumber

#$ 3:流程ID

#$ 4:家长进程ID

#$ 5:页面大小


echo"文件:$ 1,行:$ 2"

echo"页面大小为5美元

ps -elf |头-1; ps -elf | grep -w $ 3 | grep -w $ 4

echo" \ n\ n"

////////// Shell-script End ////// /////////

通过在我的代码中穿插上面的符号定义,我能够正确跟踪内存增长,但是我我无法看到内存收缩,如下面的编码示例所示。可以

有人解释原因吗?


////////// Code-snippet开始/////////// ////

#include" virtmeminfo.h"


main()

{

CHK_SIZE

char * buf = new char [100000];

CHK_SIZE

delete [] buf;

CHK_SIZE

}

////////// Code-snippet End ///////////////


问候,

Bhat

解决方案

1:文件名


2:Linenumber


3:流程ID


I have worked out a very simple method for tracking the "memory
growth" of a process at run time. It involves a header file and a
shell script.

Here''s the header file:
////////// Header File Begin ///////////////
#ifndef _VIRTMEMINFO_H_
#define _VIRTMEMINFO_H_

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#define VMEM_BUF_SIZE 200
#define VMEM_ENV_VAR "VMEM_ENV_VAR"
#define CHK_SIZE \
{ \
if(char* envVar=getenv(VMEM_ENV_VAR)) \
{ \
char buf[VMEM_BUF_SIZE]; \
sprintf(buf, "%s %s %d %d %d %d", envVar, \
__FILE__, __LINE__, \
getpid(), getppid(), getpagesize()); \
system(buf); \
} \
}

#endif //_VIRTMEMINFO_H_
////////// Header File End ///////////////
Here''s the shell script:
////////// Shell-script Begin ///////////////
#!/bin/ksh
#
# $1: Filename
# $2: Linenumber
# $3: Process id
# $4: Parent process id
# $5: Page Size

echo "File: $1, Line: $2"
echo "Page size is $5"
ps -elf | head -1; ps -elf | grep -w $3 | grep -w $4
echo "\n\n"
////////// Shell-script End ///////////////
By interspersing the above symbolic definition within my code, I am
able to correctly track the memory "growth", but I am not able to see
the memory "shrinkage", as the following coding example shows. Can
someone explain why?

////////// Code-snippet Begin ///////////////
#include "virtmeminfo.h"

main()
{
CHK_SIZE
char *buf = new char[100000];
CHK_SIZE
delete [] buf;
CHK_SIZE
}
////////// Code-snippet End ///////////////

Regards,
Bhat

解决方案

1: Filename
#


2: Linenumber
#


3: Process id
#


这篇关于跟踪“记忆增长”一个过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆