How to make graph from perf4j log file? - java

I have used perf4j to calculate the performance of the process. Now I want to make the graph for that file. Is it possible to make it without using Google API or any other method that can be used?

You have a couple of options:
When you use the org.perf4j.LogParser to parse your log, you can use the "--format csv" option to generate CSV output, open this up in Excel, then create a graph in Excel.
As the other poster said, I'm not sure why you're against using the Google Chart API, but if you are dead set against using it, note that the JFreeChart guys provide an implementation of the Google Chart APIs called Eastwood Charts: http://www.jfree.org/eastwood/. You could just set up an eastwood server and then proxy (or just set up in a hosts file) chart.apis.google . com to your eastwood server. Alternatively, if you look at the org.perf4j.LogParser class, you can override the newMeanTimeChartGenerator and newTpsChartGenerator methods to call the GoogleChartGenerator constructor that takes the base URL.
You can always create another implementation of the StatisticsChartGenerator interface and use this instead. Obviously this is the most involved option.

Can you explain a bit more as to why you want to avoid Google Charting APIs (I ask since I am intrigued as to why someone would not want to do something that is very simple, elegant and FREE)?
Also there is a GraphingServlet section "Exposing Performance Graphs in a Web Application" which I think internally does the same thing.
If you still want you can take the graph data (in raw csv format) and write some helper classes to create charts using libraries like jfreechart (rich client)

follow the following steps;
Go to the location where your perf4j log file exits and open command prompt there.
Hit the following command in cmd, make sure you have java(jdk) path set as environment variable and perf4j jar on this location:
java -jar perf4j-0.9.16.jar --graph perfGraphs.html perfLogFile.log
this will generate perfGraphs.html file in this location, which consists of graphs.

Related

Sonarqube - How to exchange data with Compute Engine MeasureComputer implementation from Sensor

I am working on implementing SonarQube plugin for a custom platform specific language. The documentation is very limited and any code examples I see are outdated - usage of Decorators instead of MeasureComputer etc. I went through the sample plugin but it does not have the context I am looking for. My question is - how do I exchange the data between the Sensor and MeasureComputer implementation. The plugin invokes a command-line (vendor specific and I cannot change) that writes the data to a file. I would like the data from this file displayed in the General Metrics screen. In Sensor execute method, I am able to parse the file but I cannot save the Measure as the API has changed now and requires me to save the Measure with .on method that requires an InputFile, but this data is on the entire project and not on a file. I am not able to do a simple save of Metric on the project. I tried using MeasureComputer implementation, but I understand that this runs in Background task on server side, so I thought of setting the property under context.settings.setString("propName", "value") and tried retriving it using (MeasureComputerContext) context.getSettings().getString("propName"). This is not working either.
Can I save a Metric on the context that can be displayed in General inside a Sensor on the project and not the resource in 5.6.6 version. If so how?
If above is not possible, how can I store the file content to exchange with MeasureComputer, either add to list of files or set the property or object to be retrieved in MeasureComputer.
Thanks in Advance for your help. I have spent considerable time on this and the documentation leaves a lot to figure out.
For anyone else ending up here, looking for an answer, see the answer posted by Julien Henry on Google Groups here - https://groups.google.com/d/msg/sonarqube/yWsp7vuIsSo/ZugXMkp8CwAJ. Essentially, you can set the property at module level using .on(context.module()) and use it in Compute Engine.

C++ or Java Library for automated code editing?

I am writing/planning to write a program that takes in a java file (or multiple java files), and edits and adds functions/classes/variables and then outputs a new java file (or multiple files).
Is there a C++ or Java library that
Can recognize and output names of classes/functions within a text file
Can recognize and output the names of the input arguments for said classes/functions
Can allow me to insert code at specific lines or within specific functions
Can search for a given variable name/value
Maintains original file formatting
I would prefer not having to manually code something to do the above, so any help would be appreciated.
Thank you in advance!
EDIT: I currently use Eclipse, and am unsure of how to proceed. So to further explain my question:
In eclipse, if I write a program that opens another .java file, How would I go about 'asking' eclipse to output, say, all the class names of the .java file I just opened?
Also I will explain the 'purpose' of this project to further clarify. I want to write a program that can take in any java file, and turn it into a class that can implemented remotely via RMI. To do this I will need to add an execute() function, have the file implement Task and Serializable and add a few variables, etc... Based on my knowledge, doing this in Eclipse would require manual editing of the program, but I would like to completely automate this process.
Thank you, again.
Much of what you need can be found in a modern IDE; and some very good IDEs are open source (eclipse and Intellij IDEA Community Edition for Java). You might look there to see if there are modules that suite your needs.
Looks like you are talking of a tool like eclipse. You might not be looking for a full fledged IDE, but the requirements that you have mentioned are fulfilled by any basic IDE.
If you wish to make one of your own, you can do that using eclipse rich client platform.
All that you would need from Java is the reflection API.

Method of extracting data from a website?

I want to grab data from a website (for example, the names, identification number, and list of resources someone is using) and post it to another website.
What I was thinking of doing was using cURL to grab the information from an existing REST api on one website. Then, what I wanted to do is write a program or an api to post that information onto another website.
Upon using a cURL, how/where can I store that information so that I can use it via another program? Would it be easier to write one single program that extracts the information from the first website and posts it to the other? If so would it be possible to do so using Java/give an idea on how to do so? I'm not asking for code, just a method to do this. I'm using the Eclipse for Java Web EE developer's IDE.
I'd write it as 2-3 programs. One that extracts the data, one that formats the data (if necessary), one that posts the data.
My gut tells me the easiest way to do this is a pure bash script. But if you want to use Java for this you can.
I would save the output in a file for the post-er to read from. This has the benefit of letting you write/test the poster without the 2 other programs working. That said, I recommend you write the get-er program first. That way you know what data you're really dealing with.
Now, if you happen to write both the formatter and the post-er in java, I would write this as one program instead of "piping" files between them. The formatter will read in the file, turn it into a data structure/class, and the post-er will read this data structure/class.
This is only superficially different from my previous paragraph. The point is each "part" is independent from each other. This allows you to test a part without running the whole thing. That's the important thing.
As for how/where to store the information from the get-er, just redirect it to a file. Here's a tutorial on how.
Truth be told, I can't tell if you're using the linux cURL program or a java implementation like this one. My answer would be very different depending on this.

Analyse SWF-Files with Java

I stumbled upon the need to find out (inside Java code) which files are dynamically loaded by an SWF-file. Is there any possibility to get a list of paths of every object referenced inside?
I tried out some libraries without proper documentation and gave up. Although I ran out of Google Search Phrases... ;)
Maybe there is an external tool which can be accessed by Java via command line?
Ggreat thanks in advance
Maybe you can get to the information you need using the dump tool which is part of Apparat.
I use actionscript more than Java, so I also recommend having a look at AS3SWF which is a great library you could use to load and analyze the swf you need. Think of it as decompiling at runtime.
Either way, the SWF Format Specifications will come in handy.
I'm not sure there's something that does exactly what you want, but I imagine you could collect all the strings (DefineText tags), loop through them and run an URL RegEx against them.
I think even if you could analyze a SWF file, you can't be sure to get this information. I have Flex Project (finally a swf file) which dynamically loads some modules, but the names (URLs) of the available modules are requested from the server. So there is no chance to retrieve this information from the main swf file.

How to make a program that automatically synchronizes

Hey i am hoping to write a program where the program automatically just copy pastes all my dad's documents from D:\office folder. So whenever I plug-in my pen-drive , the program silently copies all documents inside my pen-drive. Also all files should be pasted to a hidden folder in the pen-drive (so it remains private) . Synchronization capability also required ...So which language should be easy and where to get started ...any idea ??.
Seems to me that some spyin' is about to be goin' on here. :P
I'd recommend C++. Not extremely easy as .Net's tillyvally but fast, framework independent, convenient to manipulate Windows API. You wanna do advanced stealth app, you can't pick the easy way.
Why use the clipboard when you could just use shell commands???
Maybe write an autostart batch file on your pen drive that copies files to/from your flash drive as needed.
I infer you are on Windows. Window has a plethora of functions to manipulate files. A few functions are below.
CopyFile Copies an existing file to a new file.
FindFirstFile Searches a directory for a file or subdirectory name that matches a specified name.
FindFirstFileEx Searches a directory for a file or subdirectory name and attributes that match those that are specified.
FindNextFile Continues a file search.
MoveFile Moves an existing file or directory and its children.
On and on. These and many more functions are documented here.
File Management Functions
Copy or move the files to the pen drive.
HTH
I hate to be the person who suggests this (I don't like .NET that much):
Make a C# (or VB if you must) Console app, or Forms app (if you want to get fancy). The .NET framework will make this kind of program VERY easy and it might be fun. Unless you want to increase your proficiency in C/C++, i would suggest NOT doing it in those languages since there is a learning curve and it is a little complex to do some simple things.
"Just paste" or "synchronize"?
For synchronization, unison is a good bet, see http://en.wikipedia.org/wiki/Unison_(file_synchronizer). For "just paste", you could code a call to a batch calling XCOPY from with the Windows Autoplay mechanism.
Sounds like a secret covert operation you're talking about, though...
I think that you will need to do a lot of work to get a less than satisfactory result.
I would suggestion you instead have a look at DropBox, which is free up to 2Gb of storage which automatically synchronizes between all registered computers, plus has a special folder which allows for web access. Very nice.
I would suggest to use Camel framework of Java, there you can easily run service which will for example automatically copy data from your flash disk after plug in, to folder which you specify etc.
Good tutorial how to start is here:
https://www.youtube.com/watch?v=dmtXkA7FlwA

Categories

Resources