-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
872cb97
commit b3b0b3a
Showing
4 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// PerformanceTracer.swift | ||
// Clickstream | ||
// | ||
// Created by Abhijeet Mallick on 08/04/24. | ||
// Copyright © 2024 Gojek. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol Traceable { | ||
mutating func start() | ||
mutating func stop() | ||
} | ||
|
||
struct Trace: Traceable { | ||
|
||
private var isRunning: Bool = false | ||
|
||
var name: String | ||
var attributes: [String:Any] | ||
|
||
init(name: String, | ||
attributes:[String:Any] = [:]) { | ||
self.name = name | ||
self.attributes = attributes | ||
} | ||
|
||
mutating func start() { | ||
if Tracker.debugMode && isRunning == false { | ||
let notificationDict: [String:Any] = [TrackerConstant.traceName: name, | ||
TrackerConstant.traceAttributes: attributes] | ||
NotificationCenter.default.post(name: TrackerConstant.TraceStartNotification, object: notificationDict) | ||
isRunning = true | ||
} | ||
} | ||
|
||
mutating func stop() { | ||
if Tracker.debugMode && isRunning { | ||
isRunning = false | ||
let notificationDict: [String:Any] = [TrackerConstant.traceName: name, | ||
TrackerConstant.traceAttributes: attributes] | ||
NotificationCenter.default.post(name: TrackerConstant.TraceStopNotification, object: notificationDict) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters