Skip to main content

Mouritech Custome package on Performance Logging

Package Name

MT_PY_PerformanceLogging

''' Performance in python. This is the project ,Whenever you need to check the performance of the code like time taken by the code to perform some task ,we will use this package in our module'''

Author

Requirements

'''For running this, you need to have python3 installed on your system'''

Debugging tools

'''supported tools pycharm ,Anakonda ,Visual Studio etc...

Installation

Install my-project with Python Install MT_PY_Performancelogging_ver2

At command Promt

  pip install  MT_PY_Performancelogging_ver2
  cd  MT_PY_PerformanceLogging_ver2

(Globally )

pip install MT_PY_Performancelogging_ver2

Steps

Before using library, you need setup some things in your django project, please follow this steps

  1. Create virtual Environment for our Project ,
  2. Setup all required variables in your settings.py

At terminal :

pip install  MT_PY_Performancelogging_ver2
# locally 

from  src.MT_PY_Performancelogging_ver2.MT_Performancelogger import MT_PerformanceLogging1
# globally 
from MT_PY_Performancelogging.MT_Performance import MT_PerformanceLogging1
from MT_Performance import MT_PerformanceLogging1

MT_PerformanceLogging1(

)

Receiver Example

from src.MT_PY_Performancelogging_ver2.MT_Performancelogger import MT_PerformanceLogging1
# globally 
from  MT_PY_Performancelogging_ver2.MT_Performancelogger import MT_PerformanceLogging1
# test code for our package 
# 

import datetime
import time

import logging
# Create an instance of PerformanceLogger

logger = MT_PerformanceLogging1(__name__)
logging.basicConfig(level=logging.INFO,filename='normfunction.log' ,format='%(asctime)s - %(levelname)s - %(message)s')

# Use the logger to measure function performance
@logger.performance_log
# example code to check the loggingperformance 
# Diasum number =175
# Disarum Number = 1¹ + 7² + 5³ = 1 + 49 + 125= 175
# each digit is added with incrementation in power  and the addition of the powered value should be equal to actual input
def my_function():
    start_time = time.time()

    current_time = datetime.datetime.now()

    num=int(input('Enter Num value:'))

    result=0

    power=1

    for x in str(num):

        y=int(x)

        result= result + y**power

        power=power+1

    if num==result:

        print(f'The provide {num} is Disarum')

    else:

        print(f'The Provided {num} is Not a Disarum Number')

    # time sleep function is used to add delay in the execution of a program

    duration_to_add = datetime.timedelta(hours=0, minutes=1)

# # Estimate the end time by adding the duration to the current time

    ended_time = current_time  + duration_to_add
    end_time = time.time()
    elapsed_time = end_time - start_time
    logging.info(f'Code execution completed. Elapsed time: started at {current_time} {(start_time *10**3):.4f}  ended at {ended_time} {(end_time *10**3):.4f} = {elapsed_time:.4f} seconds')

# Call the function

my_function()
2023-09-25 18:05:33,438 - INFO - Code execution completed. Elapsed time: started at 2023-09-25 18:05:30.695571 1695645330695.5710  ended at 2023-09-25 18:06:30.695571 1695645333436.9390 = 2.7414 seconds
2023-09-25 18:05:33,438 - INFO - Function 'my_function' executed in 2.7426 seconds

Example2:-

from src.MT_PY_Performancelogging_ver2.MT_Performancelogger import MT_PerformanceLogging1
# globally 
from  MT_PY_Performancelogging_ver2.MT_Performancelogger import MT_PerformanceLogging1

import datetime

import time
import logging
# Create an instance of PerformanceLogger
logger = MT_PerformanceLogging1(__name__)
logging.basicConfig(level=logging.INFO, filename='decoresult.log', format='%(asctime)s - %(levelname)s - %(message)s')
def outer_addition(func):  #wrapped function
    @logger.performance_log
    def inner_addition(a, b):
        start_time = time.time()
        print("I'm in addition")
        sum_result = a + b
        print("Sum of", a, "and", b, "is", sum_result)
        print("Returning addition")
        func(sum_result, a)
        end_time = time.time()
        elapsed_time = end_time - start_time
        logging.info(f'Addition execution completed. Elapsed time: {elapsed_time} seconds')
    return inner_addition
def outer_subtraction(func):  #wrapped function
    @logger.performance_log
    def inner_substarction(a, b):
        start_time = time.time()
        print("I'm in subtraction")
        subtraction_result = a - b
        print("Subtraction of", a, "and", b, "is", subtraction_result)
        print("Returning subtraction")
        func(a, b)
        end_time = time.time()
        elapsed_time = end_time - start_time
        logging.info(f'Subtraction execution completed. Elapsed time: {elapsed_time} seconds')
    return inner_substarction
@logger.performance_log
@outer_addition
@logger.performance_log
@outer_subtraction
@logger.performance_log
def mOperations(a, b):
    start_time = time.time()
    print("I'm in mOperations")
    print("mOperations execution completed")
    end_time = time.time()
    elapsed_time = end_time - start_time
    logging.info(f'mOperations execution completed. Elapsed time: {elapsed_time} seconds')
mOperations(15, 10)

output:-

2023-09-25 18:12:08,428 - INFO - Function 'mOperations' executed in 0.0017 seconds
2023-09-25 18:12:08,428 - INFO - Subtraction execution completed. Elapsed time: 0.001699209213256836 seconds
2023-09-25 18:12:08,428 - INFO - Function 'inner_substarction' executed in 0.0017 seconds
2023-09-25 18:12:08,428 - INFO - Function 'wrapper' executed in 0.0017 seconds
2023-09-25 18:12:08,428 - INFO - Addition execution completed. Elapsed time: 0.003078937530517578 seconds
2023-09-25 18:12:08,428 - INFO - Function 'inner_addition' executed in 0.0031 seconds
2023-09-25 18:12:08,428 - INFO - Function 'wrapper' executed in 0.0031 seconds

Release files for MT-PY-Performancelogging-ver2 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MT-PY-Performancelogging-ver2 0.0.1
File Size Uploaded
MT_PY_Performancelogging_ver2-0.0.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MT-PY-Performancelogging-ver2 0.0.1
File Interpreter ABI Platform
MT_PY_Performancelogging_ver2-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / MT_PY_Performancelogging_ver2-0.0.1.tar.gz

Download URL MT_PY_Performancelogging_ver2-0.0.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c93125efce1487e35f45228913b04d9033b69feba43ca4e4be9f036992a91551
BLAKE2b-256 checksum
How to use checksums
b082559e551269d7575870b9c5bc7e1122a22296f37082d4765049e765d2b542
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / MT_PY_Performancelogging_ver2-0.0.1-py3-none-any.whl

Download URL MT_PY_Performancelogging_ver2-0.0.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e82a8a299c322770a6d4aef602855c651906f18d36dceeb19ed0b7e10f67f71
BLAKE2b-256 checksum
How to use checksums
987aa5161f66d12c4ae678a781d01bd8524fce8748aa673940007ba32ab3deaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page