does anyone know of a good profiling tool or library for Clojure?
I would prefer something that could be used from the REPL, along the lines of (with-profiling ...) in Allegro Common Lisp back in the day.
Is there anything along those lines?
Or do you have any experience with (non-commercial) Java profilers that work well with Clojure?
I found VisualVM (see here and here) to be very convenient. Its use with Clojure has been described about a year ago in this blog post; as far as I can see, it's not outdated in any way.
Note that the GUI from which one starts the VisualVM profiler has a prominent text area where one can enter classes / packages to be excluded from profiling -- I find the results rather more useful when clojure.* is on that list.
There's a newish Clojure library which offers profiling: https://github.com/ptaoussanis/timbre
Just found profile in Clojure contrib.
It doesn't work for large amounts of code (it blew up with OutOfMemoryError on a Project Euler solution which VisualVM handled just fine) and it requires you to insert profiling calls in the functions you want to profile.
Still, it's a better alternative to VisualVM in the cases where you just want to profile a couple of functions.
Quick heads-up that I've deprecated Timbre's profiling for a new dedicated Clojure + ClojureScript profiling lib at https://github.com/ptaoussanis/tufte.
That's basically a refinement of the stuff from Timbre, plus dedicated docs.
The README includes a comparison with JVM tools like VisualVM, YourKit, etc.
Related
I have been learning Clojure a bit recently. Is there such a thing in Clojure world as Scala-like worksheets, into which I can put any code and get it evaluated as soon as I save it? Or maybe there's a similar solution for Clojure?
I am now working with lein repl and, sadly, can't say it's the most usable tool ever.
In Lisp development in general (and Clojure in particular) the preferred programming style is what's usually dubbed interactive programming - the developer keeps an image of the app loaded at all times and interacts with it via a REPL. You can easily modify the loaded code on the fly and test changes immediately in the REPL (that's not easy at all with Scala - one has to resort to something like JRebel to do it). I find the Scala worksheets a pretty primitive solution in comparison...
The workflow that I follow in Clojure is:
I open nREPL.el in Emacs - this loads my lein2 project with all of its dependencies and gives me a REPL which I can use the try out stuff
I write some code in source code and load the changed functions (maybe by evaluating a top level form with C-M-x
Afterwards I'd press C-x C-z to jump back to the REPL and I try out the new code in it
I go back to step 2
Basically the Clojure REPL is much more powerful than the Scala REPL and I personally consider it hugely superior to the Scala IDE worksheets. Once you get used to the interactive incremental style of programming Lisp offers everything else starts to look strangely complex by comparison. I'm not familiar with Eclipse's CounterClockWise Clojure plugin, but I'm pretty sure it offers similar functionality to Emacs's nREPL.el.
You might want to take a look at the autoexpect plugin for Leiningen. Every time you save any file in the working directory, the plugin compiles and runs your code; as a bonus, it will evaluate any "expect" function calls which can serve as tests. This is very helpful for test driven development and is a nice compliment to working with the REPL as described in the other answer (I often use one or the other or both together depending on how many test cases I have in place).
I should note that running autoexpect is far faster than running "lein test" or "lein run" repeatedly, due to the startup cost of the JVM and Leiningen.
It sounds like what you are looking for is the Clojure Koan plugin. This a worksheet-style problem-solving exercise tool that watches your edits and provides instant feedback on the correctness of your work.
For actual development workflow I second the advice others here have provided on tooling and interactive environment setup, but since you specifically said you are learning Clojure, this can be a fun approach. There is also a web application called 4Clojure that you might have fun playing with.
However you will eventually (or right away) want to get a smooth and convenient development environment set up, and I haven't seen any mention so far of a few important tools. One person mentioned Nrepl. If you like Emacs, there's a slime/swank-like interaction mode that jacks into nrepl called nrepl.el that provides very nice integration between editing files and messing around in the repl. Similarly there is VimClojure, and you can find plugins for IntelliJ (LaClojure) and Eclipse (Counterclockwise) that are also popular and well-maintained.
Someone mentioned autoexpect. If you are looking for a good TDD setup, I would recommend midje. If you are using a 2.0 preview release of leiningen there are a few issues with the lazytest integration being in flux, and lazytest itself is or should be deprecated. But I prefer midje over expectations, personally, and these problems will surely be worked out in the 2.0 release of lein-midje. The stable version of lein-midje that works with the non-preview (1.x) leiningen has autotest-like functionality using lazytest.
As nobody has mentioned it, cursive is really nice these days, although I was sad to move back to a full blown IDE. You can easily do the same thing as Emacs with the built in repl, just move into the namespace that you are working with and synchronise every time you make changes. It's a really nice way of working.
can someone be kind enough to direct me to emacs tutorials for large C++ project using gdb as debugger, the project does contain make file.
I did search for emacs tutorials but some are too advanced for beginners and some only target one single file tutorial. I did read the previous posts too but did not find an answer suitable for large projects. Also I am not used to using 'git', one of the answers in previous posts.
Actually, learning Emacs is a thing that just can't be easy. You'll have to learn the basics before you will be able to read "advanced" tutorials.
The first thing you should do is to work through the builtin tutorial (C-h t). It's really good.
Then you should try to familiarize yourself with Emacs configuration basics. The easy way suggested by many users is to get a ready-for-use configuration (such as Emacs Starter Kit) and try to understand it and then tailor to your own needs and preferences. The advantages of using a ready-made configuration kit are:
It's a working code useful for learning the basics of Elisp. This learning path is way faster than reading Elisp manuals and gathering configuration code one small piece at a time.
It demonstrates a lot of useful Emacs features which otherwise might require you long time (sometimes years) to discover.
It offers a framework which you can base on writing your own configuration.
Still you should undoubtedly get rid of whatever parts of configuration you don't need.
Then (or along with the previous step) read some tutorial about using Emacs as a development platform. You can easily find a lot of tutorials via "emacs for [c] development" queries to Google. Here is one of many.
Then install Cedet (Alex Ott has written a great tutorial about it) and start feeling the power.
After that you'll know what to do next.
By the way, there is a great collection of Emacs resources maintained by Bozhidar Batsov.
Start simple. Launch Emacs without any customisations and start editing your source files. The only "tutorial" you'll need to do basic editing is the inbuilt one you'll get by hitting Control H followed by t (Referred to as C-h t in Emacs speak).
Compiling can be done by typing M-x (Alt x) compile and hitting enter. It will prompt you for the compile command which is by default make. Change it to whatever suits you.
Running gdb is done using M-x gdb and hitting enter. The interface is similar to the M-x make.
Don't use things like the Emacs starter kit which makes assumptions on your behalf. While useful as a starting point for newbies, it suppresses curiosity and that's the key to learning Emacs. The above things should be enough for you to start. Once you hit problems and are not satisfied with the ways of doing things, you can search for resources and things. Emacs is not an "IDE" and so you won't have the tight integration which many custom editors have. Don't expect it.
I was wondering what autotest tools exists for clojure. In Ruby I have ZenTest, redgreeen etc to continuously keep on testing my code. I would like to have something similar for Clojure
So far I have found this simple script https://github.com/devn/clojure-autotest on the github. A bit crude for my taste. All tests run when a change occurrs. Also it may blurt out a long stacktrace in case of syntax errors, obscuring what goes wrong.
Take a look at the Testing section on the Leiningen plugin page.
Notably there's lein-autotest for Stuart Sierras lazytest framework and speclj.
If you are using clojure.test there are a few options available. lein-test-refresh is what I use (I'm also the author). Other options include quickie and prism.
If you use expectations then there is lein-autoexpect. I'm also the author of that.
Midje has built in support for autotesting. I'm not sure what the options are for Speclj.
Search on Google shows some results for clojure profiling. Profiling tool for Clojure?
This link shows that profiling will blow up if large code is there. http://richhickey.github.com/clojure-contrib/profile-api.html. Is there any stable profiling tool for clojure?
I need to profile huge library made in clojure with some clojure functions of upto 400 lines.
We've used YourKit successfully. No special steps - just set it up like any other JVM app. Of course, interpreting the results is a bit of an art form. You can play with the filters to sometimes get it to ignore clojure core.
I found it useful to set it up on a swank server which let me profile parts of the app in the REPL (and turn things on and off between runs).
Which do you need to do - profile? or speed up the code?
If the latter, check out random pausing.
I have a bat script which calls out to an exe and starts this off - I dont know what language it is written in (Probably C++)
I want to find a profiler that allows me to run a command a few times and gathers IO/CPU and other stats
It needs to be open source where possible
Any suggestions
You may try Performance Analysis of Logs (PAL) - http://pal.codeplex.com
It has predefined templates for major system metrics (see System Overview template).
It may automatically create quite impressive report including graphs and brief explanations on detected 'hotspots'.
I have used Glowcode (www.glowcode.com) in the past. It's not open source, but quite easy to use, can profile an executable, and is available on an evaluation basis as well.
I recall it was quite cheap as well.
For Windows, XPERF is your friend, and is a free download.
Check out the Windows Performace Analysis Tools site for more information on this and other tools.
Have fun!