Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios DTSendSignalFlag的替代方案,用于识别仪器中的关键事件?_Ios_Xcode Instruments_Dtsignalflag - Fatal编程技术网

Ios DTSendSignalFlag的替代方案,用于识别仪器中的关键事件?

Ios DTSendSignalFlag的替代方案,用于识别仪器中的关键事件?,ios,xcode-instruments,dtsignalflag,Ios,Xcode Instruments,Dtsignalflag,过去有一个很好的工具,DTSendSignalFlag,它是DTPerformanceSession框架的一部分,通过它,您可以通过编程方式将标志插入仪器(请参阅)。此功能在iOS 7中停止工作 是否有人成功地让DTSendSignalFlag在iOS 7中工作?信号标志是(曾经?)一种通过代码以编程方式在仪器中发布标志的有用方法(在诊断仪器中的复杂应用时非常有用),但当我在iOS 7模拟器上运行时,我在仪器中看不到以编程方式创建的标志(但当我为iOS 6模拟器构建了Xcode 5时,它会起作用

过去有一个很好的工具,
DTSendSignalFlag
,它是
DTPerformanceSession
框架的一部分,通过它,您可以通过编程方式将标志插入仪器(请参阅)。此功能在iOS 7中停止工作


是否有人成功地让
DTSendSignalFlag
在iOS 7中工作?信号标志是(曾经?)一种通过代码以编程方式在仪器中发布标志的有用方法(在诊断仪器中的复杂应用时非常有用),但当我在iOS 7模拟器上运行时,我在仪器中看不到以编程方式创建的标志(但当我为iOS 6模拟器构建了Xcode 5时,它会起作用).

我们现在可以使用程序插入的路标,而不是使用标志,这些路标在仪器的“兴趣点”中捕获

在iOS 13和macOS 10.15中,我们可以使用
os\u路标
。这在WWDC 2019视频中有说明

例如,在Swift中:

  • 导入统一日志框架:

    import os.log
    
    @import os.signpost;
    
  • 为兴趣点创建
    OSLog

    private let pointsOfInterest = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: .pointsOfInterest)
    
    let id = OSSignpostID(log: pointsOfInterest)
    os_signpost(.begin, log: pointsOfInterest, name: "Download", signpostID: id, "Download %d", index)
    
    os_log_t log = os_log_create("ViewController", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
    
    os_signpost_id_t identifier = os_signpost_id_generate(log);
    os_signpost_interval_begin(log, identifier, "Download", "Started %d", index);
    
  • 如果要开始兴趣点范围,可以
    。开始
    兴趣点:

    private let pointsOfInterest = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: .pointsOfInterest)
    
    let id = OSSignpostID(log: pointsOfInterest)
    os_signpost(.begin, log: pointsOfInterest, name: "Download", signpostID: id, "Download %d", index)
    
    os_log_t log = os_log_create("ViewController", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
    
    os_signpost_id_t identifier = os_signpost_id_generate(log);
    os_signpost_interval_begin(log, identifier, "Download", "Started %d", index);
    
  • 当您想要结束兴趣点范围时,您可以
    。结束它:

    os_signpost(.end, log: pointsOfInterest, name: "Download", signpostID: id, "Download %d", index)
    
    os_signpost_interval_end(log, identifier, "Download", "Finished %d", index);
    
  • 如果您对一段时间不感兴趣,而是对一个路标感兴趣,您可以发布一个
    .event

    os_signpost(.event, log: pointsOfInterest, name: "Done", "All done")
    
    os_signpost_event_emit(log, OS_SIGNPOST_ID_EXCLUSIVE, "Done");
    
或在Objective-C中:

  • 导入统一日志路标框架:

    import os.log
    
    @import os.signpost;
    
  • 为兴趣点创建
    OSLog

    private let pointsOfInterest = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: .pointsOfInterest)
    
    let id = OSSignpostID(log: pointsOfInterest)
    os_signpost(.begin, log: pointsOfInterest, name: "Download", signpostID: id, "Download %d", index)
    
    os_log_t log = os_log_create("ViewController", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
    
    os_signpost_id_t identifier = os_signpost_id_generate(log);
    os_signpost_interval_begin(log, identifier, "Download", "Started %d", index);
    
  • 如果要开始兴趣点范围,可以
    。开始
    兴趣点:

    private let pointsOfInterest = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: .pointsOfInterest)
    
    let id = OSSignpostID(log: pointsOfInterest)
    os_signpost(.begin, log: pointsOfInterest, name: "Download", signpostID: id, "Download %d", index)
    
    os_log_t log = os_log_create("ViewController", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
    
    os_signpost_id_t identifier = os_signpost_id_generate(log);
    os_signpost_interval_begin(log, identifier, "Download", "Started %d", index);
    
  • 当您想要结束兴趣点范围时,您可以
    。结束它:

    os_signpost(.end, log: pointsOfInterest, name: "Download", signpostID: id, "Download %d", index)
    
    os_signpost_interval_end(log, identifier, "Download", "Finished %d", index);
    
  • 如果您对一段时间不感兴趣,而是对一个路标感兴趣,您可以发布一个
    .event

    os_signpost(.event, log: pointsOfInterest, name: "Done", "All done")
    
    os_signpost_event_emit(log, OS_SIGNPOST_ID_EXCLUSIVE, "Done");
    
无论如何,“兴趣点”工具现在可以图形化地表示工具中的一系列下载和解析操作(每个队列约束为每个队列两个并发操作):

enum SignPostColor: UInt {    // standard color scheme for signposts in Instruments
    case blue = 0
    case green = 1
    case purple = 2
    case orange = 3
    case red = 4
}

请注意,
name
值(一组我使用的是name
Download
,另一组我使用的是
Parse
)在兴趣点工具中被很好地划分为不同的泳道。因为我使用了可选的格式字符串,所以我实际上可以看到消息,在这些消息中,我可以清楚地将每个下载和解析操作与我的应用程序中的特定任务关联起来

上面我使用了可选的
OSSignpostID
参数,因为我有多个重叠的范围,我希望避免将特定的
.end
与相应的
.begin
关联时出现任何混淆。如果您没有使用兴趣点范围,或者没有重叠范围,那么从技术上讲,如果不可能存在歧义,则不需要使用此可选参数。(即使使用这些路标标识符,也要确保关联的
.begin
.end
路标的
名称也匹配,否则即使路标id相同,仪器也不会将它们识别为同一兴趣点范围的起点和终点。)

无论如何,现在您已经用信息填充了“兴趣点”工具,您可以双击一个范围来选择它,或者三次单击它来设置您的检查范围


在iOS 10和macOS 10.12中,我们使用了
kdebug\u路标
。WWDC 2016视频对此进行了说明

对于那些需要离散时间的过程,我们可以使用
kdebug\u signpost\u start
kdebug\u signpost\u end
。例如:

kdebug_signpost_start(SignPostCode.download.rawValue, UInt(index), 0, 0, SignPostColor.orange.rawValue)
performDownload {
    kdebug_signpost_end(SignPostCode.download.rawValue, UInt(index), 0, 0, SignPostColor.orange.rawValue)
}
要在时间上标记一个时刻,我们只需使用
kdebug_路标

kdebug_signpost(SignPostCode.done.rawValue, 0, 0, 0, SignPostColor.red.rawValue)
第一个参数只是一些与我们将在仪器中使用的“路标代码名”相对应的唯一数字代码。您可以使用您想要的任何值(介于0和16383之间),但我使用的是指定任务类型的内容:

enum SignPostCode: UInt32 {   // some custom constants that I'll reference in Instruments
    case download = 0
    case parse = 1
    case done = 2
}
其余的参数可以是您想要的任何
UInt
值,但在我的示例中,我将使用第二个参数作为唯一标识符来匹配重复的
start
end
调用,并且我将使用最后一个参数对我在仪器中的区域进行颜色编码:

enum SignPostColor: UInt {    // standard color scheme for signposts in Instruments
    case blue = 0
    case green = 1
    case purple = 2
    case orange = 3
    case red = 4
}
完成此操作后,您可以在Instruments中评测应用程序,单击Instruments工具栏右侧的“+”按钮,然后添加“兴趣点”。通过配置“路标代码名”以匹配我作为第一个参数传递给路标的数值,仪器将实际为我翻译这些代码。一旦我对应用程序进行了评测,现在我就可以清楚地突出我的兴趣点:

在这个快照中,我分析了七个下载操作(橙色)和七个解析操作(绿色),分别限制为一次两个。完成后,我贴了一个“完成”的路标(红色)。但这个演示应用程序的细节并不重要,而是说明了单路标和开始/结束路标是如何在Instruments的“兴趣点”中呈现的

主要的问题是,我现在在代码中的事件和我在工具中看到的事件之间有了明确的对应关系。我可以控制点击路标范围列表中的一个条目,并告诉仪器“设置时间过滤器”,如果我愿意的话,这样当我返回到我的其他仪器(分配或时间分析器或任何东西)时,检查范围会被过滤到我应用程序中的相关兴趣点


注意,以上是Swift。在Objective-C中,kdebug_路标的API类似,但必须包括:

#导入
显然,您为代码定义枚举的方式也将改变

注意,这个
kdebug_路标
API是intr