-
Notifications
You must be signed in to change notification settings - Fork 11
Add logs to get time taken by assessment job and install updates job #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ac90666
Add logs to get time taken by assessment job and install updates job.…
GAURAVRAMRAKHYANI df9c818
Addressing PR comments. Some of the changes:
GAURAVRAMRAKHYANI a247894
Removing import TelemetryWriter from PatchInstaller.py as telemetryWr…
GAURAVRAMRAKHYANI 9e4b43d
Removing extra spaces
GAURAVRAMRAKHYANI 5dd3a5f
Addressing PR comments:
GAURAVRAMRAKHYANI ca7669b
Incorporated PR comments. Some of the major changes:
GAURAVRAMRAKHYANI 75f27c3
Incorporated the comments. Some of the changes done are:
GAURAVRAMRAKHYANI efaa90d
Incorporating comments.
GAURAVRAMRAKHYANI 42fe283
Thow error if total_time_in_minutes is 0 in get_percentage_maintenanc…
GAURAVRAMRAKHYANI fdaf8f3
The test test_write_assessment_perf_logs is succeeding when ran local…
GAURAVRAMRAKHYANI e404b8e
Incorporated PR comments.
GAURAVRAMRAKHYANI a285b43
Swallow exception if any raised during writing performance logs. We d…
GAURAVRAMRAKHYANI 342afd1
(a) Do not throw exception in stopwatch. Add logs.
GAURAVRAMRAKHYANI bbab8d5
Merge branch 'master' into garamrak-addTimeTakenLogs
GAURAVRAMRAKHYANI 99298c0
Removing catch exception in PatchAssessor and PatchInstaller where st…
GAURAVRAMRAKHYANI 6ca8ce0
Covering test for catch exception in the write_installer_perf_logs me…
GAURAVRAMRAKHYANI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
| # Copyright 2023 Microsoft Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # Requires Python 2.7+ | ||
|
|
||
| from core.src.bootstrap.Constants import Constants | ||
|
|
||
| class Stopwatch(object): | ||
rane-rajasi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Implements the stopwatch logic""" | ||
|
|
||
| class StopwatchException(Constants.EnumBackport): | ||
| # Stopwatch exception strings | ||
| STARTED_ALREADY = "Stopwatch is already started" | ||
| NOT_STARTED = "Stopwatch is not started" | ||
| STOPPED_ALREADY = "Stopwatch is already stoppped" | ||
|
|
||
| def __init__(self, env_layer, telemetry_writer, composite_logger): | ||
| self.env_layer = env_layer | ||
| self.telemetry_writer = telemetry_writer | ||
| self.composite_logger = composite_logger | ||
| self.start_time = None | ||
| self.end_time = None | ||
| self.time_taken = None | ||
| self.task_details = None | ||
|
|
||
rane-rajasi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def __del__(self): | ||
| # if start_time is None that means Stopwatch is not started and hence no need to log | ||
| # call stop only if end_time is None otherwise stop() is already called. | ||
| if self.start_time is not None and self.end_time is None: | ||
SathishMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.stop() | ||
| self.set_task_details("") | ||
| self.composite_logger.log("Stopwatch details before instance is destroyed: " + str(self.task_details)) | ||
|
|
||
| def start(self): | ||
| if self.start_time is not None: | ||
| self.composite_logger.log_debug(str(Stopwatch.StopwatchException.STARTED_ALREADY)) | ||
| self.start_time = self.env_layer.datetime.datetime_utcnow() | ||
SathishMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.end_time = None | ||
| self.time_taken = None | ||
| self.task_details = None | ||
|
|
||
| def stop(self): | ||
| if self.end_time is not None: | ||
| self.composite_logger.log_debug(str(Stopwatch.StopwatchException.STOPPED_ALREADY)) | ||
| self.end_time = self.env_layer.datetime.datetime_utcnow() | ||
| if self.start_time is None: | ||
| self.composite_logger.log_debug(str(Stopwatch.StopwatchException.NOT_STARTED)) | ||
| self.start_time = self.end_time | ||
|
|
||
| self.time_taken = self.env_layer.datetime.total_minutes_from_time_delta(self.end_time - self.start_time) | ||
|
|
||
| def stop_and_write_telemetry(self, message): | ||
| self.stop() | ||
rane-rajasi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.set_task_details(message) | ||
| self.composite_logger.log("Stopwatch details: " + str(self.task_details)) | ||
|
|
||
| def set_task_details(self, message): | ||
| self.task_details = {Constants.PerfLogTrackerParams.START_TIME: str(self.start_time), Constants.PerfLogTrackerParams.END_TIME: str(self.end_time), Constants.PerfLogTrackerParams.TIME_TAKEN: str(self.time_taken), | ||
| Constants.PerfLogTrackerParams.MACHINE_INFO: self.telemetry_writer.machine_info, Constants.PerfLogTrackerParams.MESSAGE: str(message)} | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.