void pgFunction::ShowStatistics(frmMain *form, ctlListView *statistics) { if (GetConnection()->BackendMinimumVersion(8, 4)) { wxString sql = wxT("SELECT calls AS ") + qtIdent(_("Number of calls")) + wxT(", total_time AS ") + qtIdent(_("Total Time")) + wxT(", self_time AS ") + qtIdent(_("Self Time")) + wxT(" FROM pg_stat_user_functions") + wxT(" WHERE funcid = ") + NumToStr(GetOid()); DisplayStatistics(statistics, sql); } }
void CalculateAndDisplayStatistics(double emuEndTime) { int packetsServiced; double avgPktInterArrivalTime, avgPktServiceTime, avgTimeInSystem, avgPktsAtQ1, avgPktsAtQ2, avgPktsAtServer, tokenDropProbability, packetDropProbability; double ePowerX2, eXPower2, standardDeviation; My402ListElem *elem; PacketData *data; avgPktInterArrivalTime = 0; avgPktServiceTime = 0; avgTimeInSystem = 0; avgPktsAtQ1 = 0; avgPktsAtQ2 = 0; avgPktsAtServer = 0; standardDeviation = 0; ePowerX2 = 0; eXPower2 = 0; tokenDropProbability = 0; packetDropProbability = 0; packetsServiced = 0; for(elem = My402ListFirst(PacketDetailsList) ; elem != NULL ; elem = My402ListNext(PacketDetailsList, elem)) { data = (PacketData *)elem->obj; data->serviceTime /= 1000; data->interArrivalTime /= 1000; data->timeInSystem /= 1000; data->timeInQ1 /= 1000; data->timeInQ2 /= 1000; } for(elem = My402ListFirst(PacketDetailsList) ; elem != NULL ; elem = My402ListNext(PacketDetailsList, elem)) { data = (PacketData *)elem->obj; avgPktInterArrivalTime += data->interArrivalTime; if(data->packetServiced == true) { packetsServiced++; avgPktServiceTime += data->serviceTime; avgTimeInSystem += data->timeInSystem; avgPktsAtQ1 += data->timeInQ1; avgPktsAtQ2 += data->timeInQ2; ePowerX2 += ((data->timeInSystem)*(data->timeInSystem)); } } avgPktsAtServer = avgPktServiceTime; if(packetsInSystem != 0 && packetsServiced !=0) { emuEndTime = emuEndTime/1000; ePowerX2 /= packetsServiced; avgPktInterArrivalTime /= packetsInSystem; avgPktServiceTime /= packetsServiced; avgTimeInSystem /= packetsServiced; avgPktsAtQ1 /= emuEndTime; avgPktsAtQ2 /= emuEndTime; avgPktsAtServer /= emuEndTime; } if(packetsInSystem != 0) { packetDropProbability = (double)droppedPackets / (double)packetsInSystem; } if(totalTokens != 0) { tokenDropProbability = (double)droppedTokens / (double)totalTokens; } eXPower2 = (avgTimeInSystem)*(avgTimeInSystem); standardDeviation = ePowerX2 - eXPower2; standardDeviation = sqrt(standardDeviation); DisplayStatistics(avgPktInterArrivalTime, avgPktServiceTime, avgTimeInSystem, avgPktsAtQ1, avgPktsAtQ2, avgPktsAtServer, standardDeviation, tokenDropProbability, packetDropProbability); }
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { HDC hdc; LPDCB lpDCB = &cc.dcb; static int cxClient,cyClient; PAINTSTRUCT ps; static int iVertPos = 0; SCROLLINFO si; char buffer[128] = {0}; DWORD bytesRead; DWORD bytesWritten; //OVERLAPPED ov = {0,0,0}; std::fstream ifs; OPENFILENAME ofn; static TCHAR szFilter[] = TEXT ("All Files (*.*)\0*.*\0\0") ; static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ; char packet[1024]; char packet2[2]; if (cxClient && cyClient) { /*text_area.left = 0; text_area.top = 0; text_area.right = cxClient; text_area.bottom = cyClient; areaset = true;*/ topright.left = cxClient - cxClient/3 + 1; topright.top = 1; topright.right = cxClient; topright.bottom = cyClient - cyClient/3 - 1; topleft.left = 1; topleft.top = 1; topleft.right = cxClient - cxClient/3 - 1; topleft.bottom = cyClient - cyClient/3 - 1; } switch (Message) { case WM_CREATE: ov.Offset = 0; ov.OffsetHigh = 0; ov.Pointer = 0; ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); semm = CreateSemaphore(NULL, 0, 1, NULL); global.hSem = &semm; InitializeCriticalSection(§ion); break; case WM_COMMAND: switch (LOWORD (wParam)) { case IDM_COM1: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName1, hwnd, &cc)) break; else { comset = true; curCom = 1; } break; case IDM_COM2: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName2, hwnd, &cc)) break; else { comset = true; curCom = 2; } break; case IDM_COM3: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName3, hwnd, &cc)) break; else { comset = true; curCom = 3; } break; case IDM_COM4: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName4, hwnd, &cc)) { break; }else { comset = true; curCom = 4; } break; case IDM_Connect: //WaitForSingleObject(ov.hEvent, INFINITE); //MessageBox(hwnd, TEXT(""), TEXT(""), MB_OK); if (comset) { if (curCom == 1) { if ((hComm = CreateFile (lpszCommName1, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } else if (curCom == 2) { if ((hComm = CreateFile (lpszCommName2, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } else if (curCom == 3) { if ((hComm = CreateFile (lpszCommName3, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } else if (curCom == 4) { if ((hComm = CreateFile (lpszCommName4, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } lpDCB = &cc.dcb; if (!SetCommState(hComm, lpDCB)) { MessageBox (NULL, TEXT("Error setting COM state"), TEXT(""), MB_OK); return false; } COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; if (!SetCommTimeouts(hComm, &timeouts)) { MessageBox (NULL, TEXT("Error setting COM timeouts"), TEXT(""), MB_OK); return false; } if (hComm) { global.hComm = &hComm; global.ov = ov; //opThrd = CreateThread(NULL, 0, OutputThread, (LPVOID)hwnd, 0, &opThrdID ); recvThread = CreateThread(NULL, 0, receiverThread, &global, NULL, &opThrdID); MessageBox(NULL, TEXT("connected"), TEXT(""), MB_OK); } else { MessageBox(NULL, TEXT("Please select a COM port."), TEXT(""), MB_OK); } } else { MessageBox(NULL, TEXT("Please select a COM port."), TEXT(""), MB_OK); } break; case IDM_Disconnect: //kills the reading thread and closes the com port if they are active if (KillReader == false && hComm) { KillReader = true; CloseHandle(hComm); MessageBox(NULL, TEXT("disconnected"), TEXT(""), MB_OK); } break; case IDM_OpenFile: ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = hwnd ; ofn.hInstance = NULL ; ofn.lpstrFilter = szFilter ; ofn.lpstrCustomFilter = NULL ; ofn.nMaxCustFilter = 0 ; ofn.nFilterIndex = 0 ; ofn.lpstrFile = NULL ; // Set in Open and Close functions ofn.nMaxFile = MAX_PATH ; ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions ofn.nMaxFileTitle = MAX_PATH ; ofn.lpstrInitialDir = NULL ; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = TEXT ("txt") ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; ofn.lpTemplateName = NULL ; ofn.hwndOwner = hwnd ; ofn.lpstrFile = szFileName ; ofn.lpstrFileTitle = szTitleName ; ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ; if (GetOpenFileName(&ofn)) { std::wstring wfilename(szFileName); std::string filename; for(int i = 0; i < wfilename.size(); i++) { filename += wfilename[i]; } ifs = OpenFile(filename); readFile(ifs); DWORD threadID; DWORD exitStatus; if (sendThread == 0 || (GetExitCodeThread(sendThread, &exitStatus) && exitStatus != STILL_ACTIVE)) { sendThread = CreateThread(NULL, 0, sendBufferThread, &global, NULL, &threadID); } } } break; case WM_CHAR: // Process keystroke break; case WM_LBUTTONDOWN: break; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); si.cbSize = sizeof(si); si.fMask = SIF_ALL; si.nMin = 0; si.nMax = cyClient; si.nPos = 0; si.nPage = 50; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); break; case WM_VSCROLL: si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); iVertPos = si.nPos; switch(LOWORD(wParam)){ case SB_LINEUP: si.nPos -= 10; break; case SB_LINEDOWN: si.nPos += 10; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); GetScrollInfo(hwnd, SB_VERT, &si); //if there was change in the vertical scroll bar, make adjustments to redraw if (si.nPos != iVertPos){ //InvalidateRect(hwnd, &text_area, TRUE); } break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); MoveToEx(hdc, cxClient - cxClient/3, 0, NULL); LineTo(hdc, cxClient - cxClient/3, cyClient); MoveToEx(hdc, 0, cyClient - cyClient/3, NULL); LineTo(hdc, cxClient, cyClient - cyClient/3); DisplayStatistics(topright, stats, hdc); //DisplayReceivedFileData(topleft, file, hdc); ReleaseDC(hwnd, hdc); break; case WM_DESTROY: // Terminate program if (hComm) { CloseHandle(hComm); } PostQuitMessage (0); break; default: return DefWindowProc (hwnd, Message, wParam, lParam); } return 0; }
int main(int argc, char * argv[]) { char *testFileName; FILE *fd; struct SymTab *theTable, *firstCopy, *secondCopy; struct SymEntry *anEntry; struct Attributes *anAttr; char buffer[16]; int val1, val2; if (argc != 2) { fprintf(stderr,"usage: SymTabDriver test-data-file\n"); exit(1); } testFileName = argv[1]; fd = fopen(testFileName,"r"); if (!fd) ErrorExit("Can't open input file.\n"); if (!(theTable = CreateSymTab(5))) ErrorExit("Failed to alloc first table.\n"); /* Read lines consisting of a name string and an integer from std input. If name already present increment value2, if new allocate storage for attribute structure and fill in fields. */ while (fscanf(fd,"%15s %d",buffer,&val1) != EOF) { printf("Find: %15s ",buffer); (FindName(theTable,buffer)) ? fprintf(stdout," Present -") : fprintf(stdout," Not Present -"); if (EnterName(theTable,buffer,&anEntry)) { fprintf(stdout," Enter: Present: %15s\n",GetName(anEntry)); anAttr = (struct Attributes *) GetAttr(anEntry); anAttr->value2++; anAttr->value1 = MAX(((struct Attributes *) GetAttr(anEntry))->value1,val1); } else { fprintf(stdout," Enter: Entered: %15s\n",GetName(anEntry)); anAttr = malloc(sizeof(struct Attributes)); anAttr->value1 = val1; anAttr->value2 = 1; SetAttr(anEntry,anAttr); } } fprintf(stdout,"\nContents of Original Table\n"); DisplayTable(theTable); DisplayStatistics(theTable); if (!(firstCopy = CopyTable(theTable,1))) ErrorExit("Failed to alloc first copy table.\n"); DestroySymTab(theTable); fprintf(stdout,"\nContents of First Copy Table\n"); DisplayTable(firstCopy); DisplayStatistics(firstCopy); if (!(secondCopy = CopyTable(firstCopy,100))) ErrorExit("Failed to alloc first copy table.\n"); DestroySymTab(firstCopy); fprintf(stdout,"\nContents of Second Copy Table\n"); DisplayTable(secondCopy); DisplayStatistics(secondCopy); VerifyCounts(secondCopy); FreeAllAttr(secondCopy); DestroySymTab(secondCopy); return 0; }