Adding comments inside the code.

This commit is contained in:
Vishal Ratna 2021-11-20 13:56:45 +05:30
Родитель f92d69b83a
Коммит 9bb8878ac0
4 изменённых файлов: 45 добавлений и 59 удалений

Просмотреть файл

@ -9,15 +9,15 @@
> ReleaseExecutionPath - A no-op path (default path) that is usually installed in the release variants.
# Features
Easy to integrate and configure
Switch behavior depending on build type
Reduces boiler plate
Data reuse
Makes PR reviews more quantitative
APK size impact of 23KB
Designed to be thread safe & null safe
Rich API
Fully documented, just run java docs!
1. Easy to integrate and configure
2. Switch behavior depending on build type
3. Reduces boiler plate
4. Data reuse
5. Makes PR reviews more quantitative
6. APK size impact of 23KB
7. Designed to be thread safe & null safe
8. Rich API
9. Fully documented, just run java docs!
# Vocabulary
1. Capture: Logical span of code. Can be contiguous or non-contiguous
@ -71,47 +71,3 @@ trademarks or logos is subject to and must follow
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
## Usage
Two easy steps:
1. Install the `MeasuredExecutionPath` instance you want in the `onCreate` of your application class.
2. Set the filter that you would like to use in the log cat.
3. Set the flags that determine the amount of verbose in the logs.
`if(BuildConfig.DEBUG) { `
`Snippet.install(new Snippet.MeasuredExecutionPath());`
`Snippet.newFilter("SomeFilter");`
`Snippet.addFlag(Snippet.FLAG_METADATA_LINE | Snippet.FLAG_METADATA_THREAD_INFO);`
`}`
There are 3 ways to capture the code path.
1. Snippet.capture(Closure closure) - For continuous section of code, pass lambda as closure
2. Snippet.startCapture()/LogToken.endCapture() - For non contiguous sections inside the same file
3. Snippet.startCapture(String tag)/Snippet.find(tag).endCapture() - For code flows spanning over multiple files
Check out the sample app in `app/` to see it in action.
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.

Просмотреть файл

@ -30,9 +30,9 @@ android {
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation project(':snippet')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

Просмотреть файл

@ -2,16 +2,40 @@ package com.microsoft.sample;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.microsoft.snippet.Snippet;
import com.microsoft.snippet.token.ILogToken;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
protected void onCreate(@Nullable Bundle savedInstanceState) {
// The capture API can be used to measure the code that can be passed as a lambda.
// Adding this lambda captures the class, line, thread etc automatically into the logcat.
// This cannot be use for code that returns a value as the lambda declared for closure is
// is a non returning lambda. For the case that could return a value and are a little complex
// use the log-token based API demonstrated below.
Snippet.capture(()-> super.onCreate(savedInstanceState)); // Captures the code as a lambda.
// Calling startCapture gives a log token to the caller that can we used to end the measurement.
// The moment start capture is called, the measurement has started and when end capture will
// be called on the log-token, that is when the measurement will end. Endcapture can be called only once
// per log token.
ILogToken token = Snippet.startCapture();
setContentView(R.layout.activity_main);
Snippet.find("app_start").endCapture();
token.endCapture("Time to set the content view");
Snippet.find("app_start").endCapture(); // End the measurement that started in the Application class
}
@Override
protected void onStart() {
super.onStart();
}
}

Просмотреть файл

@ -13,6 +13,12 @@ public class SampleApplication extends Application {
Snippet.newFilter("SampleFilter");
Snippet.addFlag(Snippet.FLAG_METADATA_LINE | Snippet.FLAG_METADATA_THREAD_INFO);
}
Snippet.startCapture("app_start");
// There are cases where the code flow is spread across different files,
// in those kind of scenarios we use tag based startCapture call.
// We can then use find() with the tag and end the capture.
// It handles the case, when start capture is not called in warm launches and find() and endCapture()
// are called. In those case the calls to find() and endCapture() are no-op.
Snippet.startCapture("app_start"); // Start the measurement in Application class
}
}