Skip to content

Commit

Permalink
improve verbose time precision (#1108)
Browse files Browse the repository at this point in the history
# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.


![image](https://github.com/microsoft/promptflow/assets/47586720/323c0131-8456-4ff3-b317-89fe21a81245)
  • Loading branch information
wangchao1230 authored Nov 13, 2023
1 parent 1c4b194 commit ae76b8d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
37 changes: 20 additions & 17 deletions src/promptflow/promptflow/_cli/_pf/entry.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import argparse
import logging
import sys
import timeit

from promptflow._cli._pf._config import add_config_parser, dispatch_config_commands
from promptflow._cli._pf._connection import add_connection_parser, dispatch_connection_commands
from promptflow._cli._pf._flow import add_flow_parser, dispatch_flow_commands
from promptflow._cli._pf._run import add_run_parser, dispatch_run_commands
from promptflow._cli._pf._tool import add_tool_parser, dispatch_tool_commands
from promptflow._cli._user_agent import USER_AGENT
from promptflow._sdk._constants import LOGGER_NAME
from promptflow._sdk._logger_factory import LoggerFactory
from promptflow._sdk._utils import get_promptflow_sdk_version, setup_user_agent_to_operation_context
# pylint: disable=wrong-import-position
import time

# Log the start time
start_time = timeit.default_timer()
start_time = time.perf_counter()

# E402 module level import not at top of file
import argparse # noqa: E402
import logging # noqa: E402
import sys # noqa: E402

from promptflow._cli._pf._config import add_config_parser, dispatch_config_commands # noqa: E402
from promptflow._cli._pf._connection import add_connection_parser, dispatch_connection_commands # noqa: E402
from promptflow._cli._pf._flow import add_flow_parser, dispatch_flow_commands # noqa: E402
from promptflow._cli._pf._run import add_run_parser, dispatch_run_commands # noqa: E402
from promptflow._cli._pf._tool import add_tool_parser, dispatch_tool_commands # noqa: E402
from promptflow._cli._user_agent import USER_AGENT # noqa: E402
from promptflow._sdk._constants import LOGGER_NAME # noqa: E402
from promptflow._sdk._logger_factory import LoggerFactory # noqa: E402
from promptflow._sdk._utils import get_promptflow_sdk_version, setup_user_agent_to_operation_context # noqa: E402

# configure logger for CLI
logger = LoggerFactory.get_logger(name=LOGGER_NAME, verbosity=logging.WARNING)
Expand Down Expand Up @@ -45,7 +48,7 @@ def entry(argv):

args = parser.parse_args(argv)
# Log the init finish time
init_finish_time = timeit.default_timer()
init_finish_time = time.perf_counter()
try:
# --verbose, enable info logging
if hasattr(args, "verbose") and args.verbose:
Expand Down Expand Up @@ -79,7 +82,7 @@ def entry(argv):
raise ex
finally:
# Log the invoke finish time
invoke_finish_time = timeit.default_timer()
invoke_finish_time = time.perf_counter()
logger.info(
"Command ran in %.3f seconds (init: %.3f, invoke: %.3f)",
invoke_finish_time - start_time,
Expand Down
29 changes: 16 additions & 13 deletions src/promptflow/promptflow/_cli/_pf_azure/entry.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import argparse
import logging
import sys
import timeit

from promptflow._cli._pf_azure._flow import add_parser_flow, dispatch_flow_commands
from promptflow._cli._pf_azure._run import add_parser_run, dispatch_run_commands
from promptflow._sdk._constants import LOGGER_NAME
from promptflow._sdk._logger_factory import LoggerFactory
from promptflow._sdk._utils import get_promptflow_sdk_version
# pylint: disable=wrong-import-position
import time

# Log the start time
start_time = timeit.default_timer()
start_time = time.perf_counter()

# E402 module level import not at top of file
import argparse # noqa: E402
import logging # noqa: E402
import sys # noqa: E402

from promptflow._cli._pf_azure._flow import add_parser_flow, dispatch_flow_commands # noqa: E402
from promptflow._cli._pf_azure._run import add_parser_run, dispatch_run_commands # noqa: E402
from promptflow._sdk._constants import LOGGER_NAME # noqa: E402
from promptflow._sdk._logger_factory import LoggerFactory # noqa: E402
from promptflow._sdk._utils import get_promptflow_sdk_version # noqa: E402

# configure logger for CLI
logger = LoggerFactory.get_logger(name=LOGGER_NAME, verbosity=logging.WARNING)
Expand All @@ -38,7 +41,7 @@ def entry(argv):

args = parser.parse_args(argv)
# Log the init finish time
init_finish_time = timeit.default_timer()
init_finish_time = time.perf_counter()
try:
# --verbose, enable info logging
if hasattr(args, "verbose") and args.verbose:
Expand Down Expand Up @@ -66,7 +69,7 @@ def entry(argv):
raise ex
finally:
# Log the invoke finish time
invoke_finish_time = timeit.default_timer()
invoke_finish_time = time.perf_counter()
logger.info(
"Command ran in %.3f seconds (init: %.3f, invoke: %.3f)",
invoke_finish_time - start_time,
Expand Down

0 comments on commit ae76b8d

Please sign in to comment.