Announcing: Coffee-Trace -- easy execution tracing


#1

The readme file …

coffee-trace Atom editor package

Add detailed trace output to the console for functions and assignment statements in coffee files with one keypress for each line of source code traced. See project at GitHub.

Usage

Pressing ctrl-alt-t (coffee-trace:toggle) when -> or => is selected in your coffee source file will add a debug call that wraps the function and logs that function to the console along with argument values. Pressing that key combo when the = of an assignment statement is selected will add a debug call that logs each assignment along with the value assigned.

Note that you don’t actually have to select all of ->, =>, or =. Clicking on them, or in the space around them, will work as well. If you aren’t in a coffee file, or you have not clicked in a proper place, then pressing the key combo will do nothing.

Multiple source files can have trace statements at the same time. In the sample console output below you can see that the file name is shown in each trace line along with the line number.

After adding the trace calls you must reload Atom to run your package and see the trace output.

The Trace Calls Inserted

The function trace calls and assignment trace calls inserted look like …

compressedText: (text, len, pos) ->                                    # before
compressedText: cT("dText:text,len,pos->~78fcT") (text, len, pos) ->   # after

@text = @buffer.getText()                      # before
@text = cT("@text=~32acT") @buffer.getText()   # after

Each call is to the trace function cT(). The string argument for that call contains three parts. There is a shortened version of the code, e.g. dText:text,len,pos->, the line number 78, and the type of call (fcT for functions and acT for assignments).

The Trace Function Added

The trace function cT() is added to the bottom of the source file. It is in javascript so that it can be a named function and called from above. It is always the same (per version of coffee-trace). This function prints the line in the console and then calls the wrapped function or returns the asigned value so that the code execution is unchanged by the tracing.

The Console Output

43.76 coffee-trace:18 (toggle:             ) [] 
48.63 coffee-trace:31 (@buffer=            ) [TextBuffer]
48.63 coffee-trace:32 (@text=              ) ["hello world"]
49.76 coffee-trace:78 (dText:text,len,pos->) ["more text", 20, 10] 

Each trace line in the console has these parts aligned in columns.

  • Time (43.76). The seconds and hundredth’s of a second of wall time.
  • File name (possibly truncated) and line number (coffee-trace:31).
  • Abbreviated source code (@text=). This helps remember the line and usually shows variable names.
  • Trace values ([“more text”, 20, 10]). An array of function argument values or one assignment value.

Restoring Your Source Code

The key combo ctrl-alt-t (coffee-trace:toggle) toggles the trace calls and the trace function on and off.

  • Click in one of the existing trace calls and press the key combo to remove that call. If you remove the last trace call then the trace function at the bottom of the file will also be removed.
  • If you click in the trace function itself and press the key combo then all trace calls in the file and that trace function will be removed. This is the easy way to restore your file to it’s original condition.

License

Coffee-trace is copyrighted with the MIT license.


#2

Dude - may I call you dude? - I ask this with all due respect, but… do you have no day job?
You’re cranking out packages like they pay you for it. :bee:

…they don’t, do they?


#3

I’d be honored.

I retired a few months ago. Well, I’m old and unemployed which is the same thing.

Nope, but I’d be happy if someone did. Anyone looking for a contractor?

I’ve been programming since well before terminals existed. From the beginning I’ve had daydreams about editor feature ideas I’d like. Things like going back in time while staring at a single piece of code. I thought I’d write an editor just to get what I wanted. I couldn’t do it with limited plug-in capabilities.

Atom coming along when it did is an awesome opportunity for me. I’ve been programming with node and coffeescript on the server and client for the last 3 or 4 years. I was blown away when I saw Atom. I am like a fish in water. I’ve got a long list of features I’m going to implement.

I don’t care much if others use my packages. I’m building up the tricked-out editor of my dreams. My workflow is already a dream.

I’ve noticed you and Leedohm spend a lot of time here. I was surprised when I found out Leedohm doesn’t work for GitHub. How do you two find the time? Obviously you two also have a thing for Atom.


#4

Same feeling here! It so much fun to hack an editor like that.


#5

It’s great to see the passion you, and many other developers, are continuously putting into this project - all basically for the fun of it.
And it’s great, absolutely love it.

For me, as a non-developer, this is the first open source project I am involved with, and from where I stand it’s a perfect example for what open source can do for a project and for the people involved.
So the reason I spend a lot of time on here and on the repository, is really just because it’s so enjoyable and a great opportunity for me to learn.

Also, it’s all very aesthetically pleasing. I’m a sucker for nice UI and general UX sugar. Atom and Discourse, as well as Github itself, are pretty good in that department.

Anyway, another very interesting package here. Well done, dude!


#6

I’m impressed.

(garbage to meet the stupid 20-char limit).


#7

For me, it is lots of little bits of time spread throughout the day. That and I’m in front of a computer the majority of the day for one reason or another. I just keep the board open in a separate tab and the rest just falls out of that. The occasional night time or early morning sleep interruption helps with the illusion of being here all the time too :wink:


#8

I think maybe one reason it seems like I have introduced so many packages is that I actually pitch them here with the “announcing” posts like this one. I find one or two new packages a day on atom.io and I don’t know why they don’t announce them here.

Is it possible they don’t visit this forum? I doubt it because developers often need help here. Maybe everyone is more shy than I am.

I think it would be good for everyone if new packages were posted. Especially because it provides an opportunity to discuss them.


#9

Some people just do packages for themselves or feel like they’ll announce them “when they’re ready” :grinning: I know I’ve published a couple packages (including my themes) that I really don’t intend anyone but myself to use or I’m not yet ready to support, so I haven’t announced them.

I do agree though that packages that people intend for others to use should be announced.