-
Notifications
You must be signed in to change notification settings - Fork 22
Feature/disk stats metrics #12
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
Feature/disk stats metrics #12
Conversation
|
Looks good to me. |
Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Stevan Buzejic <[email protected]>
b2c5a9a to
96affd6
Compare
| jTidNameMap.put(id, name); | ||
| } | ||
|
|
||
| static void runThreadDump(String pid, String[] args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us add a method javadoc highlighting: A thread dump is a snapshot of the state of all the threads of a Java process.
- We use
HotSpotVirtualMachineto capture thread dump.VirtualMachineis type cast toHotSpotVirtualMachineto access the method at runtime. - Use this method ONLY when
NativeThreadIdis required, for all other purpose us ThreadMxBeans API’s. - Running Thread Dump is expensive and should be only judiciously done.
| @@ -0,0 +1,26 @@ | |||
| /* | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us rename this file, plugin-security isn't relevant for this library.
| // This method will be called before all following get methods | ||
| // to make sure that all information exists for a thread id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block comments are preferred.
| } | ||
| } | ||
|
|
||
| public synchronized void addSample() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaDoc for this new method. Additionally, we need 2 service timers - to measure the time taken for parsing, calculateCPUDetails and calculatePagingActivity
| kvTimestamp = System.currentTimeMillis(); | ||
| for (String tid : tids) { | ||
| Map<String, Object> sample = | ||
| // (new SchemaFileParser("/proc/"+tid+"/stat", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the comment ?
| public synchronized void addSample(String threadId) { | ||
| tids = OSGlobals.getTids(); | ||
|
|
||
| oldtidKVMap.clear(); | ||
| oldtidKVMap.putAll(tidKVMap); | ||
|
|
||
| tidKVMap.clear(); | ||
| oldkvTimestamp = kvTimestamp; | ||
| kvTimestamp = System.currentTimeMillis(); | ||
| Map<String, Object> sample = | ||
| // (new SchemaFileParser("/proc/"+tid+"/stat", | ||
| (new SchemaFileParser( | ||
| "/proc/" + pid + "/task/" + threadId + "/stat", | ||
| statKeys, | ||
| statTypes, | ||
| true)) | ||
| .parse(); | ||
| tidKVMap.put(threadId, sample); | ||
|
|
||
| calculateCPUDetails(); | ||
| calculatePagingActivity(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need repeated logic here? Update public synchronized void addSample() { for parameters with default set as All thread.
| public synchronized void addSample() { | ||
| tids = OSGlobals.getTids(); | ||
|
|
||
| oldtidKVMap.clear(); | ||
| oldtidKVMap.putAll(tidKVMap); | ||
|
|
||
| tidKVMap.clear(); | ||
| oldkvTimestamp = kvTimestamp; | ||
| kvTimestamp = System.currentTimeMillis(); | ||
| for (String tid : tids) { | ||
| Map<String, Object> sample = | ||
| (new SchemaFileParser( | ||
| "/proc/" + pid + "/task/" + tid + "/schedstat", | ||
| schedKeys, | ||
| schedTypes)) | ||
| .parse(); | ||
| tidKVMap.put(tid, sample); | ||
| } | ||
|
|
||
| calculateSchedLatency(); | ||
| } | ||
|
|
||
| public synchronized void addSample(String threadId) { | ||
| tids = OSGlobals.getTids(); | ||
|
|
||
| oldtidKVMap.clear(); | ||
| oldtidKVMap.putAll(tidKVMap); | ||
|
|
||
| tidKVMap.clear(); | ||
| oldkvTimestamp = kvTimestamp; | ||
| kvTimestamp = System.currentTimeMillis(); | ||
| Map<String, Object> sample = | ||
| (new SchemaFileParser( | ||
| "/proc/" + pid + "/task/" + threadId + "/schedstat", | ||
| schedKeys, | ||
| schedTypes)) | ||
| .parse(); | ||
| tidKVMap.put(threadId, sample); | ||
|
|
||
| calculateSchedLatency(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us not repeat code, can we refactor this to:
private static final ALL_THREADS = "ALL_THREADS";
public synchronized void addSampleForThread(String threadId) {
addSample(threadId);
}
public synchronized void addSample(String threadId = ALL_THREADS) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I am afraid we can't provide default value for the method parameter in Java (like we can do in Kotlin for example).
| public static synchronized void addSample() { | ||
| tids = OSGlobals.getTids(); | ||
| oldtidKVMap.clear(); | ||
| oldtidKVMap.putAll(tidKVMap); | ||
|
|
||
| tidKVMap.clear(); | ||
| oldkvTimestamp = kvTimestamp; | ||
| kvTimestamp = System.currentTimeMillis(); | ||
| for (String tid : tids) { | ||
| addSampleTid(tid); | ||
| } | ||
| } | ||
|
|
||
| public static synchronized void addSample(String threadId) { | ||
| tids = OSGlobals.getTids(); | ||
| oldtidKVMap.clear(); | ||
| oldtidKVMap.putAll(tidKVMap); | ||
|
|
||
| tidKVMap.clear(); | ||
| oldkvTimestamp = kvTimestamp; | ||
| kvTimestamp = System.currentTimeMillis(); | ||
| addSampleTid(threadId); | ||
| for (String tid : tids) { | ||
| addSampleTid(tid); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as other place, instead of replicating code, let us refactor this to use method overloading.
Also, move the Map clear and load part, timestamp update to the private static void addSampleTid(String tid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah - I just copy pasted the methods without too much thinking since my focus was mostly on the other side of the app - to make it workable and to be able to log the metrics for the given threadId. In this case, instead of adding samples for all the threads this method should add the sample for the given thread id:
public static synchronized void addSample(String threadId) {
tids = OSGlobals.getTids();
oldtidKVMap.clear();
oldtidKVMap.putAll(tidKVMap);
tidKVMap.clear();
oldkvTimestamp = kvTimestamp;
kvTimestamp = System.currentTimeMillis();
addSampleTid(threadId);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this method was just copy paste it should be something like:
public static synchronized void addSample(String threadId) {
tids = OSGlobals.getTids();
oldtidKVMap.clear();
oldtidKVMap.putAll(tidKVMap);
tidKVMap.clear();
oldkvTimestamp = kvTimestamp;
kvTimestamp = System.currentTimeMillis();
addSampleTid(threadId);
}| private Map<String, Double> cpu; | ||
| private Map<String, Double[]> pagingActivities; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this made part of the interface CPUPagingActivityGenerator ? A more appropriate name for CPUPagingActivityGenerator is CPUPagingActivityStore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re the first question I didn't get that. If you can give me some more context it would be good. Tnx.
Re the second - I was thinking, maybe you are right. But the thing is that metrics generators are part of the the metrics_generator package and also, beside this, we have DiskIOMetricsGenerator, SchedMetricsGenerator etc. so if we decide to rename this class I have a feeling that we should be consistent for all other classes meaning - we should rename all of the ***Generators (since they are doing similar things - gathering the metrics and storing them in some data structures), or just keep them as they are.
What do you think? Tnx in advance!
|
Couple of high level comments:
|
| oldtidKVMap.clear(); | ||
| oldtidKVMap.putAll(tidKVMap); | ||
|
|
||
| tidKVMap.clear(); | ||
| oldkvTimestamp = kvTimestamp; | ||
| kvTimestamp = System.currentTimeMillis(); | ||
| Map<String, Object> sample = | ||
| // (new SchemaFileParser("/proc/"+tid+"/stat", | ||
| (new SchemaFileParser( | ||
| "/proc/" + pid + "/task/" + threadId + "/stat", | ||
| statKeys, | ||
| statTypes, | ||
| true)) | ||
| .parse(); | ||
| tidKVMap.put(threadId, sample); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us not clear the whole map when adding sample single threadID
…PU and DiskIO samples Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Stevan Buzejic <[email protected]>
|
Closing the PR in favor of We decided not to go with adding the sample per one thread. Instead, we decided to have re-usable units of code that will be responsible for getting the metrics for the threads |
Is your feature request related to a problem? Please provide an existing Issue # , or describe.
Added cpu/disk related metrics from performance-analyzer-rca project needed for distributed performance tracing.
Client (user of the commons lib) in order to be able to use the metrics, will have to add the permissions (described in src/main/resources/plugin-security.policy).
Copy-pasted code base for getting the native thread id, code for getting the diskIO, cpu and sched metrics.
Publishing to local maven is useful once you want to test the usage of the lib:
.
./gradlew clean build publishToMavenLocaland then usage the lib as a dependency (if there is a need - exclude the clashing the lib's or maybe we should align the dependencies in this project according to the versions defined in Open search - check it out here):
Edited a gradle task for publishing - since we had 2 tasks - one was publishing the jar to local mvn while the second one published only javadoc and sources jar.
Describe the solution you are proposing
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.