1   2   3   4   5   6
Ім'я файлу: Курсова.docx
Розширення: docx
Розмір: 588кб.
Дата: 25.10.2021
скачати
Пов'язані файли:
Варикозна хвороба вен нижніх кінцівок.docx
ВАРІАНТ №5.docx

ВИСНОВКИ



В процесі виконання курсової роботи було виконано наступне:

1. Ознайомлення з різноманітними методами та засобами профілювання. Дослідження вбудованих засобів профілювання в операційної системи Windows, ознайомлення з функціями ОС Windows для зняття показників продуктивності

2. Cтворено та протестовано профайлер операційної системи Windows призначений для дослідження поведінки процесів.

Дана курсова робота носить навчальний характер, тому багато можливих функцій не було реалізовано, як наприклад точки переривання, можливість зміни контексту подій профілювання. Проте дана програма наглядно демонструє використання функцій профілювання, а також має простий та зрозумілий користувацький інтерфейс.


СПИСОК ЛІТЕРАТУРИ



1. Randy Kath – «The Debugging Application Programming Interface» [Електронний ресурс]: Microsoft Developer Network Technology Group – 1992 р. Режим доступу: http://msdn.microsoft.com/en-us/library/ms809754.aspx - Назва з екрану.

2. Xu, Jack. Practical C# Charts and Graphics – Advanced Chart and Graphics Programming for Real-World .NET Applications / Jack Xu. – 1st ed. p.cm. ISBN 978-0-9793725-0-6

3. Городієв А. В. Системне програмне забезпечення / А. В. Городієв, А. Ю. Молчанов. – СПб: Питер, 2001. – 736 с.

4. Bock Jason, «CIL Programming: Under the Hood of .NET», 2002, Apress.

5. Шефферд Дж. Программирование на Microsoft Visual C++ .NET – Русская редакция; СПБ: Питер 2007 – 928 с.

6. Шилдт Г. - C# 4.0 полное руководство – 2011 р.

7. Зіборов В. Visual C# 2010 на прикладах / Віктор Зіборов., 2011. – 432 с.

8. Троелсен Е. Мова програмування C# 2010 і платформа .NET 4 / Ендрю Троелсен., 2011. – 1392 с. – (5-те видання).

9. Донован Д. Системне програмування / Джон Донован., 1975. – 540 с.

10. Жилін В.А. Класифікація сучасного програмного забезпечення системного рівня, рекомендованого для організації робочого місця студентів комп’ютерних спеціальностей / В.А. Жилін, Д.П. Панасенко // Збірник наукових праць ХУПС. – Х.: ХУ ПС, 2014. – Вип. 2(39). – С. 249-255.

ДОДАТОК 3. Код програми
Файл stdafx.h

// stdafx.h : include file for standard system include files,

// or project specific include files that are used frequently, but

// are changed infrequently

#pragma once

// TODO: reference additional headers your program requires here

#ifndef stdafx_H

#define stdafx_H

#include

#include

#include

#include

#include


#include

#include

#include

#include

#include

#include


#include

#include

#include
#pragma comment(lib, "psapi")

#pragma comment(lib, "advapi32")
#define BUFSIZE 512
using namespace std;
typedef std::basic_string TString;
wchar_t* CMS(System::String^ managedString);
class BufferInfo

{

public:

BufferInfo()

{

IsRunning = false;

TimeOut = 30;

Count = 300;

EventStrings = new list();

CPUglobalUsage = new deque();

CPUprocUsage = new deque();

MemoryGlobalUsage = new deque();

MemoryProcUsage = new deque();

}
DWORD ProcId;

TString FileName;

TString CmdLine;
bool IsRunning;
list* EventStrings;

deque* CPUglobalUsage;

deque* CPUprocUsage;

deque* MemoryGlobalUsage;

deque* MemoryProcUsage;
int TimeOut;

int Count;

};
#endif
Файл stdafx.cpp

// stdafx.cpp : source file that includes just the standard includes

// kursec.pch will be the pre-compiled header

// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

#include "Debugger.h"
BufferInfo msg ;
wchar_t* CMS(System::String^ managedString)

{

wchar_t* str;

System::Text::StringBuilder^ bld = gcnew System::Text::StringBuilder(managedString);

wchar_t* outString = new wchar_t[512];

int i;

for( i = 0; i < bld->Length; i++)

outString[i] = (wchar_t)bld[i];

outString[i] = 0;
return outString;

}
Файл Debugger.h

#include "stdafx.h"
class CDebug

{

public:

CDebug();

CDebug();
void MainLoop();

bool StartProcess(const TString& FileName,const TString& CmdLine);

bool AttachProcess(DWORD ProcId);

bool GetFileNameFromHandle(HANDLE hFile, TString& FileName);

list m_Buffer;
protected:

virtual void OnCreateThreadEvent(DEBUG_EVENT DebugEvent);

virtual void OnExitThreadEvent(DEBUG_EVENT DebugEvent);

virtual void OnLoadModuleEvent(DEBUG_EVENT DebugEvent);

virtual void OnUnloadModuleEvent(DEBUG_EVENT DebugEvent);

virtual void OnCreateProcessEvent(DEBUG_EVENT DebugEvent);

virtual void OnExitProcessEvent(DEBUG_EVENT DebugEvent);

virtual void OnExceptionEvent(DEBUG_EVENT DebugEvent);

HANDLE m_hProcess;

std::map m_Modules;

};
Файл Debugger.cpp

#include "stdafx.h"

#include "Debugger.h"
extern BufferInfo msg;
void CDebug::OnLoadModuleEvent(DEBUG_EVENT DebugEvent)

{

TString ModuleName = L"<невідомий>";
GetFileNameFromHandle(DebugEvent.u.LoadDll.hFile,ModuleName);

m_Modules[DebugEvent.u.LoadDll.lpBaseOfDll] = ModuleName;

msg.EventStrings->push_front(CMS(System::String::Format("Завантажено модуль: 0x{0:X} файл: {1}",

(unsigned)DebugEvent.u.LoadDll.lpBaseOfDll,

gcnew System::String(ModuleName.c_str()))));

}
void CDebug::OnUnloadModuleEvent(DEBUG_EVENT DebugEvent)

{

TString ModuleName = m_Modules[DebugEvent.u.UnloadDll.lpBaseOfDll];
msg.EventStrings->push_front(CMS(System::String::Format("Вивантажено модуль: 0x{0,-8:X} файл: {1}",

(unsigned)DebugEvent.u.LoadDll.lpBaseOfDll,

gcnew System::String(ModuleName.c_str()))));
m_Modules[DebugEvent.u.UnloadDll.lpBaseOfDll].erase();

}
bool CDebug::AttachProcess(DWORD ProcId)

{

DebugActiveProcess( ProcId ) ;

m_hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,ProcId);

if(m_hProcess == INVALID_HANDLE_VALUE || m_hProcess == NULL)

{

return false;

}

return true;

}
bool CDebug::StartProcess(const TString& FileName, const TString& CmdLine)

{

LPCTSTR lpFileName = FileName.empty() ? 0 : FileName.c_str();

LPTSTR lpCmdLine = 0;

bool IsOk;

if( CmdLine.length() > 0 )

{

lpCmdLine = (LPTSTR)_alloca( ( CmdLine.length() + 1 ) * sizeof(TCHAR) );

_tcscpy( lpCmdLine, CmdLine.c_str() );

}
STARTUPINFO si = { sizeof(si) };

PROCESS_INFORMATION pi = { NULL, NULL, 0, 0 };
if( !CreateProcess( lpFileName, lpCmdLine, NULL, NULL, FALSE,

CREATE_NEW_CONSOLE | DEBUG_ONLY_THIS_PROCESS , NULL, NULL, &si, &pi ) )

{

return false;

}

msg.ProcId = pi.dwProcessId;

IsOk = AttachProcess(pi.dwProcessId);
if( pi.hProcess != NULL )

CloseHandle( pi.hProcess );
if( pi.hThread != NULL )

CloseHandle( pi.hThread );
return IsOk;

}
CDebug::CDebug()

{}
CDebug::CDebug()

{

if (m_hProcess != NULL && m_hProcess != INVALID_HANDLE_VALUE)

{

CloseHandle(m_hProcess);

}

}
void CDebug::OnCreateThreadEvent(DEBUG_EVENT DebugEvent)

{

msg.EventStrings->push_front(CMS(System::String::Format("Створено потік: 0x{0:X} адреса:0x{1:X}",

(unsigned)GetThreadId(DebugEvent.u.CreateThread.hThread),

(unsigned)DebugEvent.u.CreateThread.lpStartAddress)->PadRight(8, '0')));

}
void CDebug::OnExitThreadEvent(DEBUG_EVENT DebugEvent)

{

msg.EventStrings->push_front(CMS(System::String::Format("Завершення потоку: 0x{0:X} код завершення: 0x{1:X} ({1})",

(unsigned)DebugEvent.dwThreadId,

(unsigned)DebugEvent.u.ExitThread.dwExitCode)->PadLeft(8, '0')));

}
void CDebug::OnCreateProcessEvent(DEBUG_EVENT DebugEvent)

{

msg.EventStrings->push_front(CMS(System::String::Format("Створено процес Id: 0x{0:X} ({0})",

(unsigned)DebugEvent.dwProcessId)));

}
void CDebug::OnExitProcessEvent(DEBUG_EVENT DebugEvent)

{

msg.EventStrings->push_front(CMS(System::String::Format("Завершення процесу id: 0x{0:X} ({0}) код завершення: 0x{1:X} ({1})",

(unsigned)DebugEvent.dwProcessId,

(unsigned)DebugEvent.u.ExitProcess.dwExitCode)));

}
void CDebug::OnExceptionEvent(DEBUG_EVENT DebugEvent)

{

EXCEPTION_DEBUG_INFO Info = DebugEvent.u.Exception;
msg.EventStrings->push_front(CMS(System::String::Format("{0} виключення в потоці: 0x{1:X}",

Info.dwFirstChance ? "First-chance" : "Second-chance",

(unsigned)DebugEvent.dwThreadId)));

}
bool CDebug::GetFileNameFromHandle(HANDLE hFile, TString& FileName)

{

BOOL bSuccess = FALSE;

TCHAR pszFilename[MAX_PATH+1];

HANDLE hFileMap;

FileName = L"";
// Get the file size.

DWORD dwFileSizeHi = 0;

DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi);
if( dwFileSizeLo == 0 && dwFileSizeHi == 0 )

{

return FALSE;

}
// Create a file mapping object.

hFileMap = CreateFileMapping(hFile,

NULL,

PAGE_READONLY,

0,

1,

NULL);
if (hFileMap)

{

// Create a file mapping to get the file name.

void* pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1);
if (pMem)

{

if (GetMappedFileName (GetCurrentProcess(),

pMem,

pszFilename,

MAX_PATH))

{

// Translate path with device name to drive letters.

TCHAR szTemp[BUFSIZE];

szTemp[0] = '\0';
if (GetLogicalDriveStrings(BUFSIZE-1, szTemp))

{

TCHAR szName[MAX_PATH];

TCHAR szDrive[3] = TEXT(" :");

BOOL bFound = FALSE;

TCHAR* p = szTemp;
do

{

// Copy the drive letter to the template string

*szDrive = *p;
// Look up each device name

if (QueryDosDevice(szDrive, szName, MAX_PATH))

{

size_t uNameLen = _tcslen(szName);
if (uNameLen < MAX_PATH)

{

bFound = _tcsnicmp(pszFilename,

szName,

uNameLen) == 0

&& *(pszFilename + uNameLen) == _T('\\');
if (bFound)

{

// Reconstruct pszFilename using szTempFile

// Replace device path with DOS path

TCHAR szTempFile[MAX_PATH];

//wsprintf(szTempFile,L"%s%S",szDrive,pszFilename + uNameLen);

int i = 0;

for(i = 0; i < MAX_PATH && szDrive[i] != 0; i++)

{

szTempFile[i] = szDrive[i];

}

//i = 0;

for(int j = 0; j < MAX_PATH && pszFilename[j + uNameLen] != 0;j++, i++)

{

szTempFile[i] = (pszFilename+uNameLen)[j];

}

szTempFile[i] = 0;

/*StringCchPrintf(szTempFile,

MAX_PATH,

TEXT("%s%s"),

szDrive,

pszFilename+uNameLen);*/
StringCchCopyN(pszFilename,

MAX_PATH+1,

szTempFile,

_tcslen(szTempFile));

}

}

}
// Go to the next NULL character.

while (*p++);

} while (!bFound && *p); // end of string

}

}

bSuccess = TRUE;

UnmapViewOfFile(pMem);

}
CloseHandle(hFileMap);

}

FileName.append(pszFilename);

return(bSuccess);

}
void CDebug::MainLoop()

{

DEBUG_EVENT DebugEvent;

msg.IsRunning = true;

bool bSeenInitialBreakpoint = false;
while (msg.IsRunning)

{

if (WaitForDebugEvent(&DebugEvent, msg.TimeOut))

{

DWORD ContinueStatus = DBG_CONTINUE;

switch(DebugEvent.dwDebugEventCode)

{

case EXCEPTION_DEBUG_EVENT:

{

OnExceptionEvent( DebugEvent);
ContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
DWORD ExceptionCode = DebugEvent.u.Exception.ExceptionRecord.ExceptionCode;
if( !bSeenInitialBreakpoint && ( ExceptionCode == EXCEPTION_BREAKPOINT ) )

{

ContinueStatus = DBG_CONTINUE;

bSeenInitialBreakpoint = true;

}
break;

}

case CREATE_THREAD_DEBUG_EVENT:

{

OnCreateThreadEvent(DebugEvent);

break;

}

case EXIT_THREAD_DEBUG_EVENT:

{

OnExitThreadEvent(DebugEvent);

break;

}

case CREATE_PROCESS_DEBUG_EVENT:

{

OnCreateProcessEvent(DebugEvent);

OnCreateThreadEvent(DebugEvent);

OnLoadModuleEvent(DebugEvent);

CloseHandle( DebugEvent.u.CreateProcessInfo.hFile );

break;

}

case EXIT_PROCESS_DEBUG_EVENT:

{

OnExitProcessEvent(DebugEvent);

msg.IsRunning = false;

break;

}

case LOAD_DLL_DEBUG_EVENT:

{

OnLoadModuleEvent(DebugEvent);

CloseHandle( DebugEvent.u.LoadDll.hFile );

break;

}

case OUTPUT_DEBUG_STRING_EVENT:

{

/*OnDebugStringEvent( DebugEvent.dwProcessId, DebugEvent.dwThreadId,

DebugEvent.u.DebugString );*/

break;

}

case RIP_EVENT:

{

/*OnRipEvent( DebugEvent.dwProcessId, DebugEvent.dwThreadId,

DebugEvent.u.RipInfo );*/

break;

}

case UNLOAD_DLL_DEBUG_EVENT:

{

OnUnloadModuleEvent(DebugEvent);

break;

}

}

/*if (!msg.IsRunning )

{

DebugActiveProcessStop(msg.ProcId);

}*/

if(!ContinueDebugEvent (DebugEvent.dwProcessId,

DebugEvent.dwThreadId,

ContinueStatus))

{

DebugActiveProcessStop(msg.ProcId);

return;

}

}

else

{

if(GetLastError() != ERROR_SEM_TIMEOUT)

{

DebugActiveProcessStop(msg.ProcId);

return;

}

}

}
DebugActiveProcessStop(msg.ProcId);

return;

}
Файл kursec.cpp

// kursec.cpp : main project file.
#include "stdafx.h"

#include "Form1.h"
using namespace kursec;
void EnablePrivileges()

{

bool Success = false;

HANDLE hToken = NULL;
do

{

if( !OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken ) )

break;
TOKEN_PRIVILEGES tp;

tp.PrivilegeCount = 1;
if( !LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid ) )

break;

tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if( !AdjustTokenPrivileges( hToken, FALSE, &tp, sizeof(tp), NULL, NULL ) )

break;
Success = true;

} while( 0 );
if( hToken != NULL )

CloseHandle( hToken );

}
[STAThreadAttribute]

int main(array ^args)

{
EnablePrivileges();

// Enabling Windows XP visual effects before any controls are created

Application::EnableVisualStyles();

Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it

Application::Run(gcnew Form1());

return 0;

}
Файл Form1.h

#pragma once
#include "ChooseProc.h"

#include "StartProc.h"

#include "Debugger.h"
extern BufferInfo msg;
void StartEx(void)

{

CDebug Debuger;
if( Debuger.StartProcess(msg.FileName,msg.CmdLine))

Debuger.MainLoop();

}
void AttchEx(void)

{

CDebug Debuger;
if (Debuger.AttachProcess(msg.ProcId))

Debuger.MainLoop();

}
void TakeInf(void)

{

MEMORYSTATUSEX statex;

statex.dwLength = sizeof (statex);

PPROCESS_MEMORY_COUNTERS ppsmemCounters ;

ppsmemCounters = new PROCESS_MEMORY_COUNTERS();

HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS,false,msg.ProcId);

_int64 lIdleTime;

_int64 lKernelTime;

_int64 lUserTime;
_int64 lPTotalTime;
while(msg.IsRunning)

{

//Використання загальної памяті

GlobalMemoryStatusEx (&statex);

1   2   3   4   5   6

скачати

© Усі права захищені
написати до нас