MeasureKit 0.0.2

MeasureKit 0.0.2

Maintained by Hoang Nguyen.



  • By
  • Hoang Nguyen

MeasureKit Library

The MeasureKit is a lightweight Swift library designed to simplify the measurement of task execution within your iOS applications. It provides a simple interface for measuring the duration of tasks and reporting events to an analytics service. This README.md file serves as a guide to help you integrate and use the library in your projects.

Installation

You can integrate the Task Measurement Library into your project using CocoaPods. Add the following line to your Podfile:

pod 'MeasureKit'

Then, run the following command in your project directory:

pod install

Alternatively, you can manually download the library and add the source files to your project.

Getting Started

1. Import the library

Import the MeasureKit module in the file where you want to use it:

import MeasureKit

2. Create an instance of TaskMeasurement

In your Swift file, create an instance of TaskMeasurement:

let taskMeasurement = TaskMeasurementImp(analyticsService: AnalyticsServiceImp())

Replace AnalyticsServiceImp() with your actual analytics service implementation. This service will receive the measured events.

3. Measure a Task

Use the startEvent and completeEvent methods to measure the duration of a task. Here's an example within a UIViewController:

class ViewController: UIViewController {
    // ... other code

    lazy var taskMeasurement = TaskMeasurementImp(analyticsService: AnalyticsServiceImp())

    override func viewDidLoad() {
        super.viewDidLoad()

        // ... other code

        // Start event
        taskMeasurement.startEvent(eventIdentifier: "get_users_api")

        // Perform your task here, e.g., network request
        // ...

        // Completed event. It will throw an event to `AnalyticsService`.
        taskMeasurement.completeEvent(eventIdentifier: "get_users_api")
    }
}

MeasureKit will send an event to AnalyticsService. The result will be:

"name: get_users_api, params: Optional([\"val\": \"983.3632500004023\"])"

We also provide you method to completeEvent with customAttributes

taskMeasurement.completeEvent(eventIdentifier: "get_users_api",
                              customAttributes: ["user": "123", "env": "ios"])

License

This library is released under the MIT License.

Contributions

Contributions are welcome! Feel free to submit issues and pull requests.

Happy coding!