Skip to content

Commit

Permalink
Include metrics for protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Aug 27, 2024
1 parent aa95d39 commit 5166ccd
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ PROTO_SOURCE=../protocol/protobufs
proto: protoc protoc-swift
protoc --swift_out=Sources/LiveKit/protos -I=${PROTO_SOURCE} \
${PROTO_SOURCE}/livekit_models.proto \
${PROTO_SOURCE}/livekit_rtc.proto
${PROTO_SOURCE}/livekit_rtc.proto \
${PROTO_SOURCE}/livekit_metrics.proto

docs: swift-docs
swift doc generate Sources/LiveKit \
Expand Down
385 changes: 385 additions & 0 deletions Sources/LiveKit/Protos/livekit_metrics.pb.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,385 @@
// DO NOT EDIT.
// swift-format-ignore-file
//
// Generated by the Swift generator plugin for the protocol buffer compiler.
// Source: livekit_metrics.proto
//
// For information on using the generated types, please see the documentation:
// https://github.com/apple/swift-protobuf/

import Foundation
import SwiftProtobuf

// If the compiler emits an error on this type, it is because this file
// was generated by a version of the `protoc` Swift plug-in that is
// incompatible with the version of SwiftProtobuf to which you are linking.
// Please ensure that you are building against the same version of the API
// that was used to generate this file.
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
typealias Version = _2
}

/// index from [0; 512] are for predefined labels (`MetricLabel`)
enum Livekit_MetricLabel: SwiftProtobuf.Enum, Swift.CaseIterable {
typealias RawValue = Int

/// time to first token from LLM
case agentsLlmTtft // = 0

/// time to final transcription
case agentsSttTtft // = 1

/// time to first byte
case agentsTtsTtfb // = 2
case maxValue // = 512
case UNRECOGNIZED(Int)

init() {
self = .agentsLlmTtft
}

init?(rawValue: Int) {
switch rawValue {
case 0: self = .agentsLlmTtft
case 1: self = .agentsSttTtft
case 2: self = .agentsTtsTtfb
case 512: self = .maxValue
default: self = .UNRECOGNIZED(rawValue)
}
}

var rawValue: Int {
switch self {
case .agentsLlmTtft: return 0
case .agentsSttTtft: return 1
case .agentsTtsTtfb: return 2
case .maxValue: return 512
case .UNRECOGNIZED(let i): return i
}
}

// The compiler won't synthesize support with the UNRECOGNIZED case.
static let allCases: [Livekit_MetricLabel] = [
.agentsLlmTtft,
.agentsSttTtft,
.agentsTtsTtfb,
.maxValue,
]

}

struct Livekit_MetricsBatch: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

/// To avoid repeating string values, we store them in a separate list and reference them by index
/// This is useful for storing participant identities, track names, etc.
/// There is also a predefined list of labels that can be used to reference common metrics.
/// They have reserved indices from 0 to 512
var strData: [String] = []

var timeSeries: [Livekit_TimeSeriesMetric] = []

var events: [Livekit_EventMetric] = []

var unknownFields = SwiftProtobuf.UnknownStorage()

init() {}
}

struct Livekit_TimeSeriesMetric: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

/// Metric name e.g "speech_probablity". The string value is not directly stored in the message, but referenced by index
/// in the `str_data` field of `MetricsBatch`
var label: UInt32 = 0

var participantIdentity: UInt32 = 0

var trackSid: UInt32 = 0

/// samples
var startTimestamp: Int64 = 0

var endTimestamp: Int64 = 0

/// list of samples between start_timestamp and end_timestamp
var samples: [Livekit_MetricSample] = []

var unknownFields = SwiftProtobuf.UnknownStorage()

init() {}
}

struct Livekit_MetricSample: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

var timestamp: Int64 = 0

var value: Float = 0

var unknownFields = SwiftProtobuf.UnknownStorage()

init() {}
}

struct Livekit_EventMetric: Sendable {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

var label: UInt32 = 0

var participantIdentity: UInt32 = 0

/// 0 =
var trackSid: UInt32 = 0

var startTimestamp: Int64 = 0

var endTimestamp: Int64 {
get {return _endTimestamp ?? 0}
set {_endTimestamp = newValue}
}
/// Returns true if `endTimestamp` has been explicitly set.
var hasEndTimestamp: Bool {return self._endTimestamp != nil}
/// Clears the value of `endTimestamp`. Subsequent reads from it will return its default value.
mutating func clearEndTimestamp() {self._endTimestamp = nil}

var metadata: String = String()

var unknownFields = SwiftProtobuf.UnknownStorage()

init() {}

fileprivate var _endTimestamp: Int64? = nil
}

// MARK: - Code below here is support for the SwiftProtobuf runtime.

fileprivate let _protobuf_package = "livekit"

extension Livekit_MetricLabel: SwiftProtobuf._ProtoNameProviding {
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
0: .same(proto: "AGENTS_LLM_TTFT"),
1: .same(proto: "AGENTS_STT_TTFT"),
2: .same(proto: "AGENTS_TTS_TTFB"),
512: .same(proto: "METRIC_LABEL_MAX_VALUE"),
]
}

extension Livekit_MetricsBatch: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".MetricsBatch"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .standard(proto: "str_data"),
2: .standard(proto: "time_series"),
3: .same(proto: "events"),
]

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeRepeatedStringField(value: &self.strData) }()
case 2: try { try decoder.decodeRepeatedMessageField(value: &self.timeSeries) }()
case 3: try { try decoder.decodeRepeatedMessageField(value: &self.events) }()
default: break
}
}
}

func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if !self.strData.isEmpty {
try visitor.visitRepeatedStringField(value: self.strData, fieldNumber: 1)
}
if !self.timeSeries.isEmpty {
try visitor.visitRepeatedMessageField(value: self.timeSeries, fieldNumber: 2)
}
if !self.events.isEmpty {
try visitor.visitRepeatedMessageField(value: self.events, fieldNumber: 3)
}
try unknownFields.traverse(visitor: &visitor)
}

static func ==(lhs: Livekit_MetricsBatch, rhs: Livekit_MetricsBatch) -> Bool {
if lhs.strData != rhs.strData {return false}
if lhs.timeSeries != rhs.timeSeries {return false}
if lhs.events != rhs.events {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}

extension Livekit_TimeSeriesMetric: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".TimeSeriesMetric"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "label"),
2: .standard(proto: "participant_identity"),
3: .standard(proto: "track_sid"),
4: .standard(proto: "start_timestamp"),
5: .standard(proto: "end_timestamp"),
6: .same(proto: "samples"),
]

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeSingularUInt32Field(value: &self.label) }()
case 2: try { try decoder.decodeSingularUInt32Field(value: &self.participantIdentity) }()
case 3: try { try decoder.decodeSingularUInt32Field(value: &self.trackSid) }()
case 4: try { try decoder.decodeSingularInt64Field(value: &self.startTimestamp) }()
case 5: try { try decoder.decodeSingularInt64Field(value: &self.endTimestamp) }()
case 6: try { try decoder.decodeRepeatedMessageField(value: &self.samples) }()
default: break
}
}
}

func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if self.label != 0 {
try visitor.visitSingularUInt32Field(value: self.label, fieldNumber: 1)
}
if self.participantIdentity != 0 {
try visitor.visitSingularUInt32Field(value: self.participantIdentity, fieldNumber: 2)
}
if self.trackSid != 0 {
try visitor.visitSingularUInt32Field(value: self.trackSid, fieldNumber: 3)
}
if self.startTimestamp != 0 {
try visitor.visitSingularInt64Field(value: self.startTimestamp, fieldNumber: 4)
}
if self.endTimestamp != 0 {
try visitor.visitSingularInt64Field(value: self.endTimestamp, fieldNumber: 5)
}
if !self.samples.isEmpty {
try visitor.visitRepeatedMessageField(value: self.samples, fieldNumber: 6)
}
try unknownFields.traverse(visitor: &visitor)
}

static func ==(lhs: Livekit_TimeSeriesMetric, rhs: Livekit_TimeSeriesMetric) -> Bool {
if lhs.label != rhs.label {return false}
if lhs.participantIdentity != rhs.participantIdentity {return false}
if lhs.trackSid != rhs.trackSid {return false}
if lhs.startTimestamp != rhs.startTimestamp {return false}
if lhs.endTimestamp != rhs.endTimestamp {return false}
if lhs.samples != rhs.samples {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}

extension Livekit_MetricSample: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".MetricSample"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "timestamp"),
2: .same(proto: "value"),
]

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeSingularInt64Field(value: &self.timestamp) }()
case 2: try { try decoder.decodeSingularFloatField(value: &self.value) }()
default: break
}
}
}

func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if self.timestamp != 0 {
try visitor.visitSingularInt64Field(value: self.timestamp, fieldNumber: 1)
}
if self.value.bitPattern != 0 {
try visitor.visitSingularFloatField(value: self.value, fieldNumber: 2)
}
try unknownFields.traverse(visitor: &visitor)
}

static func ==(lhs: Livekit_MetricSample, rhs: Livekit_MetricSample) -> Bool {
if lhs.timestamp != rhs.timestamp {return false}
if lhs.value != rhs.value {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}

extension Livekit_EventMetric: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".EventMetric"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "label"),
2: .standard(proto: "participant_identity"),
3: .standard(proto: "track_sid"),
4: .standard(proto: "start_timestamp"),
5: .standard(proto: "end_timestamp"),
6: .same(proto: "metadata"),
]

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every case branch when no optimizations are
// enabled. https://github.com/apple/swift-protobuf/issues/1034
switch fieldNumber {
case 1: try { try decoder.decodeSingularUInt32Field(value: &self.label) }()
case 2: try { try decoder.decodeSingularUInt32Field(value: &self.participantIdentity) }()
case 3: try { try decoder.decodeSingularUInt32Field(value: &self.trackSid) }()
case 4: try { try decoder.decodeSingularInt64Field(value: &self.startTimestamp) }()
case 5: try { try decoder.decodeSingularInt64Field(value: &self._endTimestamp) }()
case 6: try { try decoder.decodeSingularStringField(value: &self.metadata) }()
default: break
}
}
}

func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
// The use of inline closures is to circumvent an issue where the compiler
// allocates stack space for every if/case branch local when no optimizations
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
// https://github.com/apple/swift-protobuf/issues/1182
if self.label != 0 {
try visitor.visitSingularUInt32Field(value: self.label, fieldNumber: 1)
}
if self.participantIdentity != 0 {
try visitor.visitSingularUInt32Field(value: self.participantIdentity, fieldNumber: 2)
}
if self.trackSid != 0 {
try visitor.visitSingularUInt32Field(value: self.trackSid, fieldNumber: 3)
}
if self.startTimestamp != 0 {
try visitor.visitSingularInt64Field(value: self.startTimestamp, fieldNumber: 4)
}
try { if let v = self._endTimestamp {
try visitor.visitSingularInt64Field(value: v, fieldNumber: 5)
} }()
if !self.metadata.isEmpty {
try visitor.visitSingularStringField(value: self.metadata, fieldNumber: 6)
}
try unknownFields.traverse(visitor: &visitor)
}

static func ==(lhs: Livekit_EventMetric, rhs: Livekit_EventMetric) -> Bool {
if lhs.label != rhs.label {return false}
if lhs.participantIdentity != rhs.participantIdentity {return false}
if lhs.trackSid != rhs.trackSid {return false}
if lhs.startTimestamp != rhs.startTimestamp {return false}
if lhs._endTimestamp != rhs._endTimestamp {return false}
if lhs.metadata != rhs.metadata {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}
Loading

0 comments on commit 5166ccd

Please sign in to comment.