Eddies in the Space-Time Continuum
Peter Harvey's blog
Recent entries
Archives
« November 2009
MonTueWedThuFriSatSun
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      
Today
Click me to subscribe
Search

Twitter

follow peteh at http://twitter.com
Google Reader
Technorati
My tags
aliases announcement birth book brompton children cloud computer croudsourcing damage datamining decision dtrace ethics family fun futurology gapminder geros goalfree goals happiness home human incentives intel internet ipod junk kepner-tregoe knowledge life loft losug mail making management mdb meme methodologies metro mice modelling morals mrgum network nfs nis+ nis_cachemgr nscd opensolaris performance philosophy photo pizza poverty process programming psychology rands review rodents rules security seedcamp sgrt sigbus signals sigsegv smart smf solaris sprcfb squirrels sun sunray superhero system ted teleworking terminal terminfo thinking troubleshooting trust wisdom
Flickr
www.flickr.com
This is a Flickr badge showing public photos from peteh. Make your own badge here.
del.icio.us links
del.icio.us tags
Bookmarks
RSS Feeds
XML
All
/Family
/General
/Internet
/Links
/Mac
/Management
/Palm
/Security
/Solaris
/Sun
Links
 
Licence
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.

Today's Page Hits: 57

Wednesday Oct 27, 2004
Finally worked out how to use ::grep
The mdb(1) man page has this terse entry for ::grep:


     ::grep command

         Evaluate the specified command string,  and  then  print
         the  old  value  of  dot if the new value of dot is non-
         zero. If the command contains whitespace or  metacharac-
         ters,  it must be quoted. The ::grep dcmd can be used in
         pipelines to filter a list of addresses.

I've struggled to work out how to use it till now. Take a look at this:


> ::walk umem_log | ::grep '*(.+4) == 37ac048' | ::bufctl_audit 

The libumem umem_log walker extracts all the entries from the transaction log but I only want to see those that refer to a particular buffer (0x37ac048).

To do this we pipe the walker to ::grep which runs a command and then evaluates the value of '.', the command in this case is just an expression. From the mdb(1) man page:


     expression [! word ...] [ ; ]

         A command can consist only of an arithmetic  expression.
         The  expression is evaluated and the dot variable is set
         to its value, and then the previous dcmd  and  arguments
         are executed using the new value of dot.

The expression tests the value of the contents of '.+4'. Why? well...


typedef struct umem_bufctl_audit {
        struct umem_bufctl      *bc_next;       /* next bufctl struct */
        void                    *bc_addr;       /* address of buffer */
        struct umem_slab        *bc_slab;       /* controlling slab */
        umem_cache_t            *bc_cache;      /* controlling cache */
        hrtime_t                bc_timestamp;   /* transaction time */
        thread_t                bc_thread;      /* thread doing transaction */
        struct umem_bufctl      *bc_lastlog;    /* last log entry */
        void                    *bc_contents;   /* contents at last free */
        int                     bc_depth;       /* stack depth */
        uintptr_t               bc_stack[1];    /* pc stack */
} umem_bufctl_audit_t;

"/usr/include/umem_impl.h" [Read only] line 138 of 381 --36%-- 

If the contents match the expression evaluates to '1' which means ::grep prints the old value of '.'. Hurrah.

Jan 24th 2007 - I now know what was confusing me here:

There's still an outstanding question about why "the previous dcmd and arguments are executed using the new value of dot" doesn't appear to apply in the ::grep line. eg:


> 1234=Y
                1970 Jan  1 02:17:40    
> ::grep .
1234
> ::grep '.=Y' 
                1970 Jan  1 02:17:40    
1234
> .
                1970 Jan  1 02:17:40    
1234
> =Y
                1970 Jan  1 02:17:40    

I'm not going to worry about it.

The man page excerpt I quoted refers to using an expression on its own with no pipeline. In other words, if you just have an expression on the line it repeats the last dcmd with the new value of dot. Within a ::grep dcmd this doesn't apply.


Posted at 05:30PM Oct 27, 2004 by Peter Harvey in Solaris  |  Comments[0]  |  del.icio.us technorati digg