안녕하세요 : iPhone 애플리케이션에서 계산이 완료되면 비동기식으로 콜백하는 라이브러리 (C++)를 사용합니다. 이제 콜백이 수행 될 때까지 라이브러리를 호출하는 메소드를 포함하여 소비 된 시간을 측정하고 싶습니다. Apple의 Instruments 응용 프로그램을 사용하여이 작업을 수행 할 수 있습니까? 모범 사례는 무엇입니까?라이브러리 호출과 콜백 사이의 시간 측정
2
A
답변
8
과거에 나는 최적화해야했던 네트워크 호출을 위해 다음을 사용했습니다. 처음에는 약간 복잡한 것처럼 보였지만, 필자가 본 가장 정확한 시간을 제공합니다.
uint64_t time_a = mach_absolute_time();
// do stuff
uint64_t time_b = mach_absolute_time();
[self logTime:(time_b-time_a)];
- (void) logTime:(uint64_t)machTime {
static double timeScaleSeconds = 0.0;
if (timeScaleSeconds == 0.0) {
mach_timebase_info_data_t timebaseInfo;
if (mach_timebase_info(&timebaseInfo) == KERN_SUCCESS) {
double timeScaleMicroSeconds = ((double) timebaseInfo.numer/(double) timebaseInfo.denom)/1000;
timeScaleSeconds = timeScaleMicroSeconds/1000000;
}
}
NSLog(@"%g seconds", timeScaleSeconds*machTime);
}
0
mach_absolute_time 호출을 래핑하기 위해 C++ 클래스를 작성했습니다. 이것은 시간 차이를 측정하기위한 이벤트의 시작/정지시에 코드에 뿌려주는 것이 편리합니다.
클래스에서 타이머를 사용하여 (호출 간) 또는 상태 기반 동작 (타이머가 X에 도달 한 후 수행)에 사용하려는 경우에도 잘 작동합니다.
StopWatch.h
class StopWatch
{
private:
uint64 _start;
uint64 _stop;
uint64 _elapsed;
public:
void Start();
void Stop();
void Reset();
void Continue();
double GetSeconds();
};
StopWatch.cpp
#include "Stopwatch.h"
#include <mach/mach_time.h>
void StopWatch::Start()
{
_stop = 0;
_elapsed = 0;
_start = mach_absolute_time();
}
void StopWatch::Stop()
{
_stop = mach_absolute_time();
if(_start > 0)
{
if(_stop > _start)
{
_elapsed = _stop - _start;
}
}
}
void StopWatch::Reset()
{
_start = 0;
_stop = 0;
_elapsed = 0;
}
void StopWatch::Continue()
{
_elapsed = 0;
_stop = 0;
}
double StopWatch::GetSeconds()
{
double elapsedSeconds = 0.0;
uint64 elapsedTimeNano = 0;
if(_elapsed > 0)
{ // Stopped
mach_timebase_info_data_t timeBaseInfo;
mach_timebase_info(&timeBaseInfo);
elapsedTimeNano = _elapsed * timeBaseInfo.numer/timeBaseInfo.denom;
elapsedSeconds = elapsedTimeNano * 1.0E-9;
}
else if(_start > 0)
{ // Running or Continued
uint64_t elapsedTemp;
uint64_t stopTemp = mach_absolute_time();
if(stopTemp > _start)
{
elapsedTemp = stopTemp - _start;
}
else
{
elapsedTemp = 0;
}
mach_timebase_info_data_t timeBaseInfo;
mach_timebase_info(&timeBaseInfo);
elapsedTimeNano = elapsedTemp * timeBaseInfo.numer/timeBaseInfo.denom;
elapsedSeconds = elapsedTimeNano * 1.0E-9;
}
return elapsedSeconds;
}
관련 문제
- 1. 응용 프로그램/스레드에서 측정 된 측정 시간
- 2. Silverlight 차트로드 시간 측정
- 3. ActionScript 3 : enterFrame 이벤트 사이의 경과 시간 측정
- 4. HSL 색상 사이의 거리 측정
- 5. FPGA 측정 정확한 시간
- 6. ASP.NET 페이지의 시간 측정
- 7. CodeIgniter : 페이지로드 시간 측정
- 8. 측정 대기 시간
- 9. 페이지로드 시간 측정
- 10. 메서드 호출과 메서드 실행
- 11. 파스칼 프로그램에서 실행 시간 측정
- 12. JVMTI로 Java 실행 시간 측정
- 13. 선택된 루프의 실행 시간 측정
- 14. html 렌더링 시간 측정 도구
- 15. 평균 서비스 실행 시간 측정
- 16. 개발자 빌드 시간 측정 방법
- 17. AJAX 통화 측정 처리 시간
- 18. 흔들 장치의 소요 시간 측정
- 19. AudioQueueNewInput 콜백 대기 시간
- 20. 뮤텍스 또는 퓨 텍스 대기 시간 측정
- 21. 유닉스 서버와 PC 사이의 측정 속도
- 22. 코코아 : 키를 누르는 사이의 시간을 측정 하시겠습니까?
- 23. ccTouchMoved 사이의 시간
- 24. 시간 사이의 작업
- 25. 사이의 시간 비교
- 26. jQuery $ .post 호출과 콜백 메소드를 사용하여 PHP $ _SESSION [ 'username'] 설정하기
- 27. 클래스 호출과 메소드 호출 사이의 Python 차이점은 무엇입니까?
- 28. WCF 단방향 콜백 시간 초과?
- 29. jQuery를 (PARAMS [시간], [완화], [콜백])
- 30. 리눅스에서 exec() 프로세스가 수행 한 측정 시간