Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Simplifies Python code profiling by offering an easy-to-use decorator for measuring function performance. Customize profiling with options for sort criteria and output format. Perfect for quickly identifying bottlenecks.
Simplifies Method Profiling
The profile decorator is designed for easy profiling of Python functions, leveraging the built-in cProfile and pstats modules for performance analysis. It provides a flexible way to output profiling information either to the standard output, logger or to a file and allows for sorting of profiling data based on various criteria.
The decorator is designed to be a "no frills" implementation of CProfile that saves you time. Just add it to a method, call your endpoint or run your script, and see the output.
Features Seamless Integration: Just decorate functions you wish to profile without altering their implementation.
There are no external dependancies, profiling is done using the standard library
package CProfile
.
Install the package
pip install profiling-decorator
Import the profile decorator:
from profiling_decorator import profile
Basic Usage To use the decorator without any customization, simply decorate your function. By default, it profiles the function, sorts the results by cumulative time, and prints the results to standard output.
@profile
def example_function():
# Function code to profile
pass
example_function()
Limit the profiling output to a specific number of rows to focus on the top time-consuming operations.
@profile(n_rows=10)
def example_function():
# Function code to profile
pass
example_function()
Customize the sorting criteria of the profiling report (e.g., by number of calls).
@profile(sort_by="calls")
def example_function():
# Function code to profile
pass
example_function()
The valid options for the sort_by parameter align with the SortKey attributes in the pstats module and include:
See the pstats module for a complete up to date list.
To save the profiling results to a file, specify the output and filename parameters.
@profile(output='file', filename='profile_stats.txt')
def example_function():
# Function code to profile
pass
example_function()
Before using the log output option, ensure the logging system is configured to handle messages at the INFO level or lower. Here's a basic configuration example:
import logging
logging.basicConfig(level=logging.INFO)
@profile(output='log')
def example_function():
# Function code to profile
pass
example_function()
The profile decorator is enhanced to support profiling of both synchronous and asynchronous functions. This feature allows developers to gain insights into the performance characteristics of their code, whether it operates synchronously or leverages Python's asyncio for asynchronous execution.
Usage is identical:
@profile
async def async_function():
# Async function code to profile
await some_async_operation()
await async_function()
Distributed under the Apache Software License. See LICENSE.txt
for more information.
Joshua Brumpton - ja.brumpton@gmail.com
Project Link: github repo
FAQs
Simplifies Python code profiling by offering an easy-to-use decorator for measuring function performance. Customize profiling with options for sort criteria and output format. Perfect for quickly identifying bottlenecks.
We found that profiling-decorator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.