JAVA

java _ 프로그램 성능검사 프로세스별 점검(시간) - > 수정함.

사라링 2016. 9. 23. 15:45


//VO 객체의 독립성을 유지 하기 위해 변경 처리. 

//사용법은 주석 확인. 



package module.common.otherinterface ;


import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.HashMap;

import java.util.Map;


import com.base.SystemException;

import com.component.parameter.IParameterManagement;

import com.framework.core.Workspace;


/**

 * 각 프로세스(메소드 단위) 시간 1/10000 단위로 점검 프로그램 

 * procTSOBegin -> procTSOWork procTSOWork procTSOWork(프로세스 숫자 만큼) -> procTSOEnd

 * 

 * 1. 로직 instance 호출

 *  ProcessTimeSysOut procTSO = new ProcessTimeSysOut();

 * 

 * 2. 최초 호출

 *  procTSO.procTSOBegin("국내출장);

 * 

 * 3. 각 프로세스 단위로 각 각 사이에 계속 추가. 

 *    procTSO.procTSOWork("신규:신청번호 채번 or 기 신청서 변경 체크");

 *    .

 *    .

 *    procTSO.procTSOWork("출장신청기본/출장예산정보");

 *    .

 *    .

 *    procTSO.procTSOWork("출장자 및 여비정보");

 *    

 * 4. 로직 instance 종료

 *    procTSO.procTSOEnd();

 * 

 * 싱글톤 패턴 구현

 * @since 1.0

 */

public class ProcessTimeSysOut extends Workspace {

PTSOVO ptsovo;

//private static ProcessTimeSysOut procTSO;

/* 복수의 프로그램에서 사용 가능 함에 따라 싱글톤 패턴 사용시 프로세스 누적 시간등이 혼합될 가능성이 있어

 *  싱글톤 패턴 해제함.

 * 

 * private ProcessTimeSysOut(){}

public static ProcessTimeSysOut getInstance(){

if(procTSO==null){

procTSO = new ProcessTimeSysOut();

procTSO.proCnt = 0;

procTSO.fullTime = 0;

procTSO.beforTime = 0;

}

return procTSO;

}

*/

//프로세스 최초시작 및 타이틀 설정

public void procTSOBegin(String processNameParam){

long time = System.currentTimeMillis(); 

this.ptsovo = new PTSOVO();

this.ptsovo.setProcTSOKEY(time);

System.out.println("============================"+processNameParam+" 프로세스 검토 로직 시작 ============================\n");

System.out.println("process key number : "+this.ptsovo.getProcTSOKEY());

this.ptsovo.setBeforTime(time);

this.ptsovo.setProcTitle(processNameParam);

SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

System.out.println("시작 시간 : "+dayTime.format(new Date(time))+"\n");

}

//프로세스 내의 작업 구분 요청(out 처리)

public void procTSOWork(String workName){

if(this.ptsovo!=null){

long nowtTime  = System.currentTimeMillis(); 

long processTime  = nowtTime - this.ptsovo.getBeforTime();

this.ptsovo.setFullTime(this.ptsovo.getFullTime()+processTime); 

this.ptsovo.setProCnt(this.ptsovo.getProCnt()+1);

//하단 sysout도출시 내용의 길이는 변경 하지 않도록 처리(30글자).

System.out.println(String.format("%03d",this.ptsovo.getProCnt())+"("+this.ptsovo.getProcTSOKEY()+")||"+this.ptsovo.getProcTitle()+" ==> "+String.format("%-30s",workName)+"======>"+processTime+" / "+this.ptsovo.getFullTime()+"\n");

this.ptsovo.setBeforTime(nowtTime);

}

}

//프로세스 검토 종료 로직

public void procTSOEnd(){

if(this.ptsovo!=null){

System.out.println("process key number : "+ptsovo.getProcTSOKEY());

long time = System.currentTimeMillis(); 

//최초 시작시 프로세스 시작 시간을 넣도록 함.

SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

System.out.println("종료 시간 : "+dayTime.format(new Date(time)));

System.out.println("총 누적 시간: " +this.ptsovo.getFullTime());

System.out.println("검토 프로세스 숫자: "+this.ptsovo.getProCnt()+"\n");

System.out.println("============================"+this.ptsovo.getProcTitle()+" 프로세스 검토 로직 종료 ============================\n");

System.out.println();

}

}


}




package module.common.otherinterface;


import java.math.BigDecimal;

import java.util.ArrayList;


import module.mis.trans.TransItem;

import module.mis.trans.TransVat;




public class PTSOVO {// 프로세스 분석 구조 객체

private int  proCnt = 0;  //프로세스 순번 

private long fullTime =0; //총 누적 소요 시간 

private long beforTime=0; //프로세스 시작 시간

private long procTSOKEY =0 ; //프로세스 생성시 주요키 값 (차후 조회시 대상 키값을 기준으로 조회 할수 있도록 처리.

private String procTitle ;  //프로세스 타이틀

public int getProCnt() {

return proCnt;

}

public void setProCnt(int proCnt) {

this.proCnt = proCnt;

}

public long getFullTime() {

return fullTime;

}

public void setFullTime(long fullTime) {

this.fullTime = fullTime;

}

public long getBeforTime() {

return beforTime;

}

public void setBeforTime(long beforTime) {

this.beforTime = beforTime;

}

public long getProcTSOKEY() {

return procTSOKEY;

}

public void setProcTSOKEY(long procTSOKEY) {

this.procTSOKEY = procTSOKEY;

}

public String getProcTitle() {

return procTitle;

}

public void setProcTitle(String procTitle) {

this.procTitle = procTitle;

}

}















//선언 및 만들어둬야 할것 소스 . 


//class 전역 변수 


int  proCnt = 0;  //프로세스 순번 

long fullTime =0; //총 누적 소요 시간 

long beforTime=0; //프로세스 시작 시간


//class 내 추가메소드 / 별도의 class 로 만들어 외부 접근 해도 무방


public void proTimeSysOut(String processNameParam,String type){

//시작 처리 type : S

if("S".equals(type)){

System.out.println("============================"+processNameParam+" 프로세스 검토 로직 시작 ============================\n");

long time = System.currentTimeMillis(); 

//최초 시작시 프로세스 시작 시간을 넣도록 함.

beforTime = time; 

SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

System.out.println("시작 시간 : "+dayTime.format(new Date(time))+"\n");

//종료 처리 type : E 

}else if("E".equals(type)){

System.out.println("============================"+processNameParam+" 프로세스 검토 로직 종료 ============================\n");

long time = System.currentTimeMillis(); 

//최초 시작시 프로세스 시작 시간을 넣도록 함.

SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

System.out.println("종료 시간 : "+dayTime.format(new Date(time))+"\n");

System.out.println("총 누적 시간: " +fullTime+"\n");

System.out.println("검토 프로세스 숫자: "+proCnt);

//종료시 전역 변수 long ,cnt 값을 초기화 한다. 

proCnt = 0;  //프로세스 순번 

fullTime =0; //총 누적 소요 시간 

beforTime=0; //프로세스 시작 시간

//각 프로세스 검토 type : P

}else if("P".equals(type)) {

if(beforTime==0){

System.out.println("프로세스 검토 로직 시작 이 누락 되었습니다.");

}else {

long nowtTime  = System.currentTimeMillis(); 

long processTime  = nowtTime - beforTime;

fullTime += processTime;

//하단 sysout도출시 내용의 길이는 변경 하지 않도록 처리(30글자).

System.out.println(String.format("%03d",++proCnt)+"||"+String.format("%-30s",processNameParam)+"======>"+processTime+" / "+fullTime+"\n");

beforTime = nowtTime;

}

}

}



// 사용법!!!


//성능 검증내 에서 해당 메소드를 호출 . 

//최초

  proTimeSysOut("국내출장","S");


// 각프로세스 마다 첫번째 파라미터에 프로세스 명을 입력  2번째 파라미터는 무조건 "P"

proTimeSysOut("신규:신청번호 채번 or 기 신청서 변경 체크","P");


//종료 

   proTimeSysOut("국내출장","E");




// sysout log 확인시. 아래와 같이 나오면 정상. 



[16. 9. 23   13:20:31:458 KST] 00000272 SystemOut     O ======================================

[16. 9. 23   13:20:31:458 KST] 00000272 SystemOut     O [ module.mis.hrm.main.Hrm_4071]

[16. 9. 23   13:20:31:458 KST] 00000272 SystemOut     O [2016.09.23 13:20:31(458)]

[16. 9. 23   13:20:31:458 KST] 00000272 ExtendAction  I module.common.action.ExtendAction execute 트랜잭션 시작.....

[16. 9. 23   13:20:31:459 KST] 00000272 SystemOut     O [ tmSetTrpRqst ] Transaction Start

[16. 9. 23   13:20:31:459 KST] 00000272 SystemOut     O ============================국내출장 프로세스 검토 로직 시작 ============================


[16. 9. 23   13:20:31:459 KST] 00000272 SystemOut     O 시작 시간 : 2016-20-23 01:20:31


[16. 9. 23   13:20:31:500 KST] 00000272 SystemOut     O 001||신규:신청번호 채번 or 기 신청서 변경 체크     ======>41 / 41


[16. 9. 23   13:20:31:781 KST] 00000272 SystemOut     O 002||출장신청기본/출장예산정보                 ======>281 / 322


[16. 9. 23   13:20:31:964 KST] 00000272 SystemOut     O 003||출장자 및 여비정보                    ======>183 / 505


[16. 9. 23   13:20:32:006 KST] 00000272 SystemOut     O 004||출장지 및 경유지                     ======>41 / 546


[16. 9. 23   13:20:32:055 KST] 00000272 SystemOut     O 005||출장내용                          ======>50 / 596


[16. 9. 23   13:20:32:055 KST] 00000272 SystemOut     O 006||첨부파일 저장                       ======>0 / 596