2

Within, for instance, /sys/kernel/debug/tracing, the kernel makes many settings available as files, whose contents should be read in order to see what that setting is. Of course, typing cat /sys/kernel/debug/tracing/... each time to see the setting is kind of tedious; so right now I'm using this function to traverse and inspect that part of the filesystem (needs to be called under sudo):

#!/usr/bin/env bash

function recourse_print() {
  local LVL=$2
  local IND="$(printf ' %.0s' $(seq 1 $LVL) )-"
  for ix in $(ls --group-directories-first --reverse "$1" | tac); do
    local FP="$1/$ix"
    if [ -f "$FP" ]; then
      echo "$IND $ix: $(timeout -s SIGALRM 1 cat $FP 2>&1 | awk 1 ORS=' ; ' | head -c 50) ... "
    elif [ -d "$FP" ]; then
      echo "$IND $ix [d]"
      local NL=$((LVL+1))
      if [ $((LVL < 3)) = 1 ] ; then
        recourse_print "$FP" $NL
      fi
    fi
  done
}

recourse_print /sys/kernel/debug/tracing 1

This is sort of OK, in the first run:

 - available_events: i915:i915_gem_object_create ; i915:i915_gem_object ... 
 - available_filter_functions: cpumask_weight ; run_init_process ; init_post ; in ... 
 - available_tracers: blk function_graph mmiotrace wakeup_rt wakeup func ... 
 - buffer_size_kb: 8192 ;  ... 
 - current_tracer: function ;  ... 
...
 - per_cpu [d]
  - cpu0 [d]
   - stats: entries: 0 ; overrun: 0 ; commit overrun: 0 ;  ... 
   - trace: # tracer: function ; # ; #           TASK-PID    C ... 
   - trace_pipe:  ... 
   - trace_pipe_raw:  ... 
  - cpu1 [d]
   - stats: entries: 0 ; overrun: 0 ; commit overrun: 0 ;  ... 
   - trace: # tracer: function ; # ; #           TASK-PID    C ... 
   - trace_pipe:  ... 
   - trace_pipe_raw:  ... 
...

The problem is - there are so many entries, it becomes difficult to keep track and focus within this list in a terminal.

One thing I wish for this, was that there was a filesystem GUI, that would do the same - that is, recursively traverse a directory, and open any files and display a one-line summary of the contents (timing out in case of pipes) - such that the directory hierarchy is displayed as GUI tree nodes, that can be expanded/compacted; examples for this are dconf-editor:

dconf-editor

... or gconf-editor:

gconf-editor

In this case, I imagine the left pane would show subfolders tree, and the "Name" in "Name/Value" would be the filename, and the "Value" would be one-line summary (truncated start) of the file's contents (where I'd expect the typical characters like .�.�j�,�,{... rendered in case the file has binary contents). I wouldn't expect such an app to render, say, checkboxes (even if a particular file has contents that can be set to either 0 or 1); but it would be awesome if it could open the entire file contents (for text-only files) in a new window upon doubleclick.

Is there a standalone app that can do something like this - and if not, is there a plugin for, say, Nautilus, that could add an extra column in List View, that could be scripted to extract a one-line summary from the file contents?

1 Answer 1

2

Well, seems I could get old Nautilus to do this, but I'd rather know if there is a standalone app that can behave like this. Thanks to Music And EXIF Metadata Information In Nautilus List View [Nautilus Columns Extension - PPA] ~ Web Upd8: Ubuntu / Linux blog, I learned about the "Nautilus Columns" Python plugin, and it was relatively easy to modify it to show a "summary" field from the first few bytes in a file.

Code is below, as coltextsummary.py - follow the instructions in the comments, then after Nautilus is restarted, in Nautilus / Edit / Preferences ... / List Columns tab, put a check mark on "Summary" column (should be last); then close "File Management Preferences" window. Now, when you switch to List View, there should be a "Summary" column, with first 50 characters of each file shown. Note: tested on Nautilus 2.32.2.1, Ubuntu 11.04.

Note, first, that you need superuser permission to browse /sys/kernel/debug, and indeed:

sudo nautilus /sys/kernel/debug

... seems to work fine, also in List View. However, if you try to open the tracing directory here, either by double-click or by expanding the node in List View, Nautilus will just do an "empty spin" saying "Loading":

nautilus-empty-spin

The only way I could get it to work in that directory - was when I tried to run gdb on it, to inspect what the problem could be:

$ sudo gdb --args nautilus /sys/kernel/debug
...
Reading symbols from /usr/bin/nautilus...(no debugging symbols found)...done.
(gdb) r
...

nautilus-plugin-works

Note that, even with the gdb approach, Nautilus will do "empty" "loading" if you try to open /sys/kernel/debug/tracing directly from the command line and switch it to List View; or if you try to open tracing by doubleclicking its entry in /sys/kernel/debug. Only way to get tree items with expansion, is to run it as noted above, and to use List View for /sys/kernel/debug, and expand the tracing node (and its children) there.

Well - anyways, that is why I wish there was a standalone GUI for this (not having to run nautilus in gdb :)); but even this will help me for now...

The code for the plugin:

coltextsummary.py:

#!/usr/bin/python

# based on bsc-v2.py from "nautilus-columns",
# https://launchpad.net/~nilarimogard/+archive/webupd8/+packages?batch=75&memo=225&start=225

# this script can installed to the current user account by running the following commands:

# mkdir ~/.nautilus/python-extensions
# cp coltextsummary.py ~/.nautilus/python-extensions
# chmod a+x ~/.nautilus/python-extensions/coltextsummary.py

# alternatively, you can be able to place the script in:
# /usr/lib/nautilus/extensions-2.0/python/
# (here to make it available to all users - also superuser)

# nautilus -q   # to refresh

__author__ = "sdaau"
__version__ = "0.0.1"
__appname__ = "nautilus-coltextsummary"


import os
import urllib
import nautilus
import select

class ColumnExtension(nautilus.ColumnProvider, nautilus.InfoProvider):
  __dbg = 0
  def __init__(self):
    print "Initializing" , __appname__ , __version__
    pass

  def get_columns(self):
    return (
      nautilus.Column("NautilusPython::summary_column","summary","Summary","Text Content Summary"),
    )

  def update_file_info(self, file):
    # set defaults to blank
    file.add_string_attribute('summary', '[none]')

    if file.get_uri_scheme() != 'file':
      return

    # strip file:// to get absolute path
    filename = urllib.unquote(file.get_uri()[7:])

    # for some reason, even here we can end up with directories!
    if self.__dbg==1: print filename
    # so try another check to skip them:
    if not(os.path.isfile(filename)):
      if self.__dbg==1: print "Not a file: " + filename + " ; skipping..."
      return

    # http://stackoverflow.com/questions/21429369/read-file-with-timeout-in-python
    # get summary, for all files # if file.is_mime_type('image/jpeg'):
    timeout = 0.5
    maxbytes = 50
    f = open(filename, "r")
    rrdy, wrdy, xrdy = select.select([f], [], [], timeout);
    summary="."
    if rrdy == []:
      summary = "[n/a]"
    else:
      summary = os.read(f.fileno(), maxbytes)
      summary = summary.replace('\n', ' ; ')
    file.add_string_attribute('summary', summary)
    f.close()

    self.get_columns()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .