SQLite4
Check-in [33cc91541c]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Display the 'age' of each level in lsmview.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 33cc91541c039e108ad0781f7cee16725c94c3a4
User & Date: dan 2013-01-18 15:58:28
Context
2013-01-18
20:28
Bring the command-line shell up-to-date with recent changes in SQLite3. Add test cases for the command-line shell. check-in: 918553d16e user: drh tags: trunk
15:58
Display the 'age' of each level in lsmview. check-in: 33cc91541c user: dan tags: trunk
10:46
Truncate the database file when the number of connections drops from one to zero. check-in: dc4fa92596 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/lsm_main.c.

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
  if( rc!=LSM_OK ) return rc;

  /* Format the contents of the snapshot as text */
  pTopLevel = lsmDbSnapshotLevel(pWorker);
  lsmStringInit(&s, pDb->pEnv);
  for(p=pTopLevel; rc==LSM_OK && p; p=p->pNext){
    int i;
    lsmStringAppendf(&s, "%s{", (s.n ? " " : ""));
    lsmAppendSegmentList(&s, "", &p->lhs);
    for(i=0; rc==LSM_OK && i<p->nRight; i++){
      lsmAppendSegmentList(&s, " ", &p->aRhs[i]);
    }
    lsmStringAppend(&s, "}", 1);
  }
  rc = s.n>=0 ? LSM_OK : LSM_NOMEM;








|
|







402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
  if( rc!=LSM_OK ) return rc;

  /* Format the contents of the snapshot as text */
  pTopLevel = lsmDbSnapshotLevel(pWorker);
  lsmStringInit(&s, pDb->pEnv);
  for(p=pTopLevel; rc==LSM_OK && p; p=p->pNext){
    int i;
    lsmStringAppendf(&s, "%s{%d", (s.n ? " " : ""), (int)p->iAge);
    lsmAppendSegmentList(&s, " ", &p->lhs);
    for(i=0; rc==LSM_OK && i<p->nRight; i++){
      lsmAppendSegmentList(&s, " ", &p->aRhs[i]);
    }
    lsmStringAppend(&s, "}", 1);
  }
  rc = s.n>=0 ? LSM_OK : LSM_NOMEM;

Changes to tool/lsmview.tcl.

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
...
244
245
246
247
248
249
250



251
252
253
254
255
256
257
258
259
...
262
263
264
265
266
267
268



269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
  set mySelected $tag
  $C itemconfigure $mySelected -fill grey

  eval $myScript [list $segment]
}

proc draw_level {C level tags} {
  set lhs [lindex $level 0]

  set l [lindex $tags end]
  draw_segment $C $lhs [concat $tags "$l.s0"]
  foreach {x1 y1 x2 y2} [$C bbox "$l.s0"] {}

  set i 0
  set y 0
  set x [expr $x2+10]
  foreach seg [lrange $level 1 end] {
    set tag "$l.s[incr i]"
    draw_segment $C $seg [concat $tags $tag]

    $C move $tag $x $y
    foreach {x1 y1 x2 y2} [$C bbox $tag] {}
    set y [expr $y2+$::G(vertical_padding)]
  }
................................................................................
  set W [winfo width $C]

  # Figure out the scale to use.
  # 
  set nMaxWidth 0.0
  foreach level $structure {
    set nRight 0
    foreach seg [lrange $level 1 end] {
      set sz [lindex $seg 3]
      if {$sz > $nRight} { set nRight $sz }
    }
    set nLeft [lindex $level 0 3]
    set nTotal [log2 [expr max($nLeft, 2)]]
    if {$nRight} {set nTotal [expr $nTotal + [log2 [expr max($nRight, 2)]]]}
    if {$nTotal > $nMaxWidth} { set nMaxWidth $nTotal }
  }

  if { $nMaxWidth==0.0 } { set nMaxWidth 1.0 }
  set ::G(scale) [expr (($W-100) / $nMaxWidth)]
................................................................................
    set tag "l[incr l]"

    draw_level $C $level $tag
    foreach {x1 y1 x2 y2} [$C bbox $tag] {}
    $C move $tag [expr ($W-$x2)/2] $y
    incr y [expr $y2 + $::G(vertical_padding)]


    foreach {x1 y1 x2 y2} [$C bbox $tag.text] {}
    $C create text 10 $y1 -anchor nw -text [string toupper "${tag}:"]
  }

  if {[info exists myVertShift]} {
    set H [winfo height $C]
    set region [$C bbox all]
    if {$y < $H} { $C move all 0 [expr $H-$y] }
  }
................................................................................
  foreach {xt1 yt1 xt2 yt2} [$C bbox $to] {}

  set line [$C create line [expr ($xf1+$xf2)/2] $yf2 [expr ($xt1+$xt2)/2] $yt1]
  $C itemconfigure $line -arrow last 
}

proc draw_internal_pointers {C iLevel level} {



  for {set j 2} {$j < [llength $level]} {incr j} {
    if {[lindex $level $j 2]==0} {
      draw_one_pointer $C "l$iLevel.s[expr $j-1]" "l$iLevel.s$j"
    }
  }
}

proc draw_pointers {C structure} {
  for {set i 0} {$i < [llength $structure]} {incr i} {
................................................................................

  for {set i 0} {$i < ([llength $structure]-1)} {incr i} {
    set i2 [expr $i+1]

    set l1 [lindex $structure $i]
    set l2 [lindex $structure $i2]




    set bMerge1 [expr [llength $l1]>1]
    set bMerge2 [expr [llength $l2]>1]

    if {$bMerge2} {
      if {[lindex $l2 1 2]==0} {
        draw_one_pointer $C "l$i.s0" "l$i2.s1"
        if {$bMerge1} {
          draw_one_pointer $C "l$i.s[expr [llength $l1]-1]" "l$i2.s1"
        }
      }
    } else {

      set bBtree [expr [lindex $l2 0 2]!=0]

      if {$bBtree==0 || $bMerge1} {
        draw_one_pointer $C "l$i.s0" "l$i2.s0"
      }
      if {$bBtree==0} {
        draw_one_pointer $C "l$i.s[expr [llength $l1]-1]" "l$i2.s0"
      }
    }
  }
}

# Argument $canvas is a canvas widget. Argument $db is the Tcl data 
# structure returned by an LSM_INFO_DB_STRUCTURE call. This procedure
................................................................................
  pack .pan -fill both -expand 1

  set mySelected "l0.s0.main"
  static_redraw $C
  bind $C <Configure>  [list static_redraw $C]
  bind $myTree <<TreeviewSelect>> [list static_treeview_select $C]

  static_select_callback $C [lindex $myData 0 0]
}

if {[llength $argv] > 2} {
  puts stderr "Usage: $argv0 ?CONFIG? ?DATABASE?"
  exit -1
}
if {[llength $argv]>0} {







|








|







 







|



|







 







>

|







 







>
>
>
|
|







 







>
>
>
|
|


|


|



>
|





|







 







|







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
  set mySelected $tag
  $C itemconfigure $mySelected -fill grey

  eval $myScript [list $segment]
}

proc draw_level {C level tags} {
  set lhs [lindex $level 1]

  set l [lindex $tags end]
  draw_segment $C $lhs [concat $tags "$l.s0"]
  foreach {x1 y1 x2 y2} [$C bbox "$l.s0"] {}

  set i 0
  set y 0
  set x [expr $x2+10]
  foreach seg [lrange $level 2 end] {
    set tag "$l.s[incr i]"
    draw_segment $C $seg [concat $tags $tag]

    $C move $tag $x $y
    foreach {x1 y1 x2 y2} [$C bbox $tag] {}
    set y [expr $y2+$::G(vertical_padding)]
  }
................................................................................
  set W [winfo width $C]

  # Figure out the scale to use.
  # 
  set nMaxWidth 0.0
  foreach level $structure {
    set nRight 0
    foreach seg [lrange $level 2 end] {
      set sz [lindex $seg 3]
      if {$sz > $nRight} { set nRight $sz }
    }
    set nLeft [lindex $level 1 3]
    set nTotal [log2 [expr max($nLeft, 2)]]
    if {$nRight} {set nTotal [expr $nTotal + [log2 [expr max($nRight, 2)]]]}
    if {$nTotal > $nMaxWidth} { set nMaxWidth $nTotal }
  }

  if { $nMaxWidth==0.0 } { set nMaxWidth 1.0 }
  set ::G(scale) [expr (($W-100) / $nMaxWidth)]
................................................................................
    set tag "l[incr l]"

    draw_level $C $level $tag
    foreach {x1 y1 x2 y2} [$C bbox $tag] {}
    $C move $tag [expr ($W-$x2)/2] $y
    incr y [expr $y2 + $::G(vertical_padding)]

    set age [lindex $level 0]
    foreach {x1 y1 x2 y2} [$C bbox $tag.text] {}
    $C create text 5 $y1 -anchor nw -text [string toupper "${tag} ($age):"]
  }

  if {[info exists myVertShift]} {
    set H [winfo height $C]
    set region [$C bbox all]
    if {$y < $H} { $C move all 0 [expr $H-$y] }
  }
................................................................................
  foreach {xt1 yt1 xt2 yt2} [$C bbox $to] {}

  set line [$C create line [expr ($xf1+$xf2)/2] $yf2 [expr ($xt1+$xt2)/2] $yt1]
  $C itemconfigure $line -arrow last 
}

proc draw_internal_pointers {C iLevel level} {
  set iAge [lindex $level 0]      ;# Age of this level
  set lSeg [lrange $level 1 end]  ;# List of segments that make up this level

  for {set j 2} {$j < [llength $lSeg]} {incr j} {
    if {[lindex $lSeg $j 2]==0} {
      draw_one_pointer $C "l$iLevel.s[expr $j-1]" "l$iLevel.s$j"
    }
  }
}

proc draw_pointers {C structure} {
  for {set i 0} {$i < [llength $structure]} {incr i} {
................................................................................

  for {set i 0} {$i < ([llength $structure]-1)} {incr i} {
    set i2 [expr $i+1]

    set l1 [lindex $structure $i]
    set l2 [lindex $structure $i2]

    # Set to true if levels $i and $i2 are currently undergoing a merge
    # (have one or more rhs segments), respectively.
    #
    set bMerge1 [expr [llength $l1]>2]
    set bMerge2 [expr [llength $l2]>2]

    if {$bMerge2} {
      if {[lindex $l2 2 2]==0} {
        draw_one_pointer $C "l$i.s0" "l$i2.s1"
        if {$bMerge1} {
          draw_one_pointer $C "l$i.s[expr [llength $l1]-2]" "l$i2.s1"
        }
      }
    } else {

      set bBtree [expr [lindex $l2 1 2]!=0]

      if {$bBtree==0 || $bMerge1} {
        draw_one_pointer $C "l$i.s0" "l$i2.s0"
      }
      if {$bBtree==0} {
        draw_one_pointer $C "l$i.s[expr [llength $l1]-2]" "l$i2.s0"
      }
    }
  }
}

# Argument $canvas is a canvas widget. Argument $db is the Tcl data 
# structure returned by an LSM_INFO_DB_STRUCTURE call. This procedure
................................................................................
  pack .pan -fill both -expand 1

  set mySelected "l0.s0.main"
  static_redraw $C
  bind $C <Configure>  [list static_redraw $C]
  bind $myTree <<TreeviewSelect>> [list static_treeview_select $C]

  static_select_callback $C [lindex $myData 0 1]
}

if {[llength $argv] > 2} {
  puts stderr "Usage: $argv0 ?CONFIG? ?DATABASE?"
  exit -1
}
if {[llength $argv]>0} {