1
我想运行简单的功能分析。当一个函数开始运行时,计时器将变为星号。当它完成时,时间被输出到日志:如何在运行时创建函数包装?
-(int) myFunc {
[MyProfileService startTimer:@"myFuncTimer"];
... code ...
[MyProfileService stopTimer:@"myFuncTimer"];
return result;
}
此溶液与生产代码搞乱。一个更优雅的soultion将在类initialize方法静态注册定时器:
@implementation MyClass {
+(void) initialize {
[MyProfileService monitorFunction:@Selector(myFunc) inClass[Myclass class]];
}
为了实现这一目标,我需要一个新的实现来取代myFunc的实施:
-(void) runProfileFunc(....) {
[MyProfileService startTimer:@"myFuncTimer"];
id result = [MyClass performSelector:@selector(myFunc) withObject: ...];
[MyProfileService stopTimer:@"myFuncTimer"];
return result;
}
与objc /运行时我可以在运行时切换功能。 如何复制原始函数签名并将参数传递给包装器中的原始函数?
之前重新发明轮子,你看着仪器? – JustSid 2012-03-29 09:36:30
你这样做是因为:a)你想让它运行得更快,或者b)你只是想知道测量结果? – 2012-03-29 13:12:01
我想收集来自我的测试者测试者的信息,但我不希望#if无处不在。 – 2012-03-31 12:49:18