Пример #1
0
int ProcessListLinux::initProccessList()
{
    // Получение списка процессов
    sProccess proc;
    QMap<QString,sProccess> result;

    QRegExp rx_digit("^\\d+$");

    QDir dir = QDir("/proc");
    dir.setFilter(QDir::AllDirs);
    QFileInfoList pidList = dir.entryInfoList();
    for (int i=0;i<pidList.size();i++)
    {
        QString pid = pidList.at(i).fileName();

        if (!rx_digit.exactMatch(pid))
        {
            continue;
        }

        proc.pid = pid;
        proc.sockets = getSockets(pid);
        proc.program = getProgram(pid);
        proc.cmdline = getCmdline(pid);

        result[pid] = proc;
    }

    proclist=result;

    return 1;
}
Пример #2
0
// jitProfileInitialize
//
static int jitProfileInitialize(AMDTJitProfileEnv* pEnv)
{
    int             ret = 0;
    std::wstring    profileDataDir;

    if (true == gAMDTJitProfileInitialized)
    {
        return AMDT_JITPROFILE_SUCCESS;
    }

    gJitPID = (NULL == pEnv) ? _getpid() : pEnv->processId;

    // Get the command-line to obtain the Application name;
    // gJitCmd will contain the name of JIT Application;
    ret = getCmdline(pEnv);

    if (AMDT_JITPROFILE_SUCCESS != ret)
    {
        jitError(pEnv, "Could not get the command line");
        return ret;
    }

    if (gJitVerbose)
    {
        wprintf(L"Command Line: %s\n", gJitCmd.c_str());
    }

    // Get the dir path in which the JIT profile data files will be written
    // Note: getProfileDataDir gives gSampleDir and profileDataDir
    ret = getProfileDataDir(profileDataDir);

    if (AMDT_JITPROFILE_SUCCESS != ret)
    {
        jitError(pEnv, "Could not get profile data dir for JIT application");
        return ret;
    }

    if (gJitVerbose)
    {
        wprintf(L"The JIT Profile data dir is " STR_FORMAT L".\n",
                profileDataDir.c_str());
    }

    // Save the profileDataDir for future use..
    gProfileDataDir = profileDataDir;

#if AMDT_BUILD_TARGET == AMDT_WINDOWS_OS
    // The directory access right is 771
    int j = recursiveMkdir(profileDataDir.c_str());

    if (0 != j)
    {
        wprintf(L"The sample directory " STR_FORMAT L" was not able to be created\n",
                profileDataDir.c_str());
        return AMDT_JITPROFILE_FAILED;
    }

    profileDataDir = gProfileDataDir;
#else
    // Linux
    struct stat buf;
    string tmpStr(profileDataDir.begin(), profileDataDir.end());

    if (stat(tmpStr.c_str(), &buf) != 0)
    {
        if (mkdir(tmpStr.c_str(), 0x01fd) != 0)
        {
            jitError(pEnv, "Cannot create directory %s",
                     profileDataDir.c_str());
            return AMDT_JITPROFILE_FAILED;
        }
    }

#endif

    // Save the profileDataDir for future use..
    gProfileDataDir = profileDataDir;

    // Construct the JCL filename
    wchar_t jclFile[OS_MAX_PATH] = { L'\0' };

    swprintf(jclFile, OS_MAX_PATH - 1, STR_FORMAT PATH_SEPARATOR L"%d.jcl", profileDataDir.c_str(), gJitPID);

    // Initialize JCLWriter
    gJCLWriter = new JclWriter(jclFile, gJitCmd.c_str(), gJitPID);

    if (NULL == gJCLWriter)
    {
        jitError(pEnv, "Error: Out of Memory");
        return AMDT_JITPROFILE_FAILED;
    }

    // This just writes the header record
    gJCLWriter->Initialize();

    return AMDT_JITPROFILE_SUCCESS;
} // jitProfileInitialize