~ubuntu-branches/ubuntu/gutsy/gnome-system-monitor/gutsy-proposed

« back to all changes in this revision

Viewing changes to src/proctable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-15 17:36:39 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20070515173639-84tmijl8avfp33b6
Tags: 2.19.2-0ubuntu1
* New upstream version:
  - New Solaris mode.
  - Fixed crash on startup with dependencies+myprocesses.
  - pcre is back for good.
* debian/control.in:
  - Build-Depends on libpcre3-dev
* debian/patches/02_lpi.patch:
  - updated
* debian/patches/03_autoconf.patch:
  - updated
* debian/patches/90_from_svn_fix_crash.patch:
  - dropped, fixed with the new version

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
        g_assert(infob);
86
86
 
87
87
        switch (col) {
88
 
        case COL_VMSIZE:
89
 
                return PROCMAN_RCMP(infoa->vmsize, infob->vmsize);
90
 
 
91
 
        case COL_MEMRES:
92
 
                return PROCMAN_RCMP(infoa->memres, infob->memres);
93
 
 
94
 
        case COL_MEMWRITABLE:
95
 
                return PROCMAN_RCMP(infoa->memwritable, infob->memwritable);
96
 
 
97
 
        case COL_MEMSHARED:
98
 
                return PROCMAN_RCMP(infoa->memshared, infob->memshared);
99
 
 
100
 
        case COL_MEMXSERVER:
101
 
                return PROCMAN_RCMP(infoa->memxserver, infob->memxserver);
102
 
 
103
88
        case COL_CPU_TIME:
104
89
                return PROCMAN_RCMP(infoa->cpu_time_last, infob->cpu_time_last);
105
90
 
108
93
 
109
94
        case COL_CPU:
110
95
                return PROCMAN_RCMP(infoa->pcpu, infob->pcpu);
111
 
 
112
 
        case COL_MEM:
113
 
                return PROCMAN_RCMP(infoa->mem, infob->mem);
114
 
 
115
96
        default:
116
97
                g_assert_not_reached();
117
98
                return 0;
319
300
                                    G_TYPE_STRING,      /* Process Name */
320
301
                                    G_TYPE_STRING,      /* User         */
321
302
                                    G_TYPE_STRING,      /* Status       */
322
 
                                    G_TYPE_STRING,      /* VM Size      */
323
 
                                    G_TYPE_STRING,      /* Resident Memory */
324
 
                                    G_TYPE_STRING,      /* Writable Memory */
325
 
                                    G_TYPE_STRING,      /* Shared Memory */
326
 
                                    G_TYPE_STRING,      /* X Server Memory */
 
303
                                    G_TYPE_ULONG,       /* VM Size      */
 
304
                                    G_TYPE_ULONG,       /* Resident Memory */
 
305
                                    G_TYPE_ULONG,       /* Writable Memory */
 
306
                                    G_TYPE_ULONG,       /* Shared Memory */
 
307
                                    G_TYPE_ULONG,       /* X Server Memory */
327
308
                                    G_TYPE_UINT,        /* % CPU        */
328
309
                                    G_TYPE_STRING,      /* CPU time     */
329
310
                                    G_TYPE_STRING,      /* Started      */
331
312
                                    G_TYPE_UINT,        /* ID           */
332
313
                                    G_TYPE_STRING,      /* Security Context */
333
314
                                    G_TYPE_STRING,      /* Arguments    */
334
 
                                    G_TYPE_STRING,      /* Memory       */
 
315
                                    G_TYPE_ULONG,       /* Memory       */
335
316
                                    GDK_TYPE_PIXBUF,    /* Icon         */
336
317
                                    G_TYPE_POINTER,     /* ProcInfo     */
337
318
                                    G_TYPE_STRING       /* Sexy tooltip */
371
352
 
372
353
 
373
354
        for (i = COL_USER; i <= COL_MEM; i++) {
374
 
                cell_renderer = gtk_cell_renderer_text_new ();
375
 
 
 
355
 
 
356
                GtkCellRenderer *cell;
 
357
                GtkTreeViewColumn *col;
 
358
 
 
359
                cell = gtk_cell_renderer_text_new();
 
360
                col = gtk_tree_view_column_new();
 
361
                gtk_tree_view_column_pack_start(col, cell, TRUE);
 
362
                gtk_tree_view_column_set_title(col, _(titles[i]));
 
363
                gtk_tree_view_column_set_resizable(col, TRUE);
 
364
                gtk_tree_view_column_set_sort_column_id(col, i);
 
365
                gtk_tree_view_column_set_reorderable(col, TRUE);
 
366
                gtk_tree_view_append_column(GTK_TREE_VIEW(proctree), col);
 
367
 
 
368
                // type
 
369
                switch (i) {
 
370
                case COL_VMSIZE:
 
371
                case COL_MEMRES:
 
372
                case COL_MEMWRITABLE:
 
373
                case COL_MEMSHARED:
 
374
                case COL_MEMXSERVER:
 
375
                case COL_MEM:
 
376
                  gtk_tree_view_column_set_cell_data_func(col, cell,
 
377
                                                          &procman::size_cell_data_func,
 
378
                                                          GUINT_TO_POINTER(i),
 
379
                                                          NULL);
 
380
                  break;
 
381
 
 
382
                default:
 
383
                  gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
 
384
                  break;
 
385
                }
 
386
 
 
387
                // xaling
376
388
                switch(i)
377
389
                {
378
390
                case COL_VMSIZE:
385
397
                case COL_PID:
386
398
                case COL_CPU_TIME:
387
399
                case COL_MEM:
388
 
                        g_object_set(G_OBJECT(cell_renderer),
389
 
                                     "xalign", 1.0f,
390
 
                                     NULL);
 
400
                        g_object_set(G_OBJECT(cell), "xalign", 1.0f, NULL);
 
401
                        break;
391
402
                }
392
403
 
393
 
                column = gtk_tree_view_column_new ();
394
 
                gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
395
 
                gtk_tree_view_column_set_attributes (column, cell_renderer,
396
 
                                                     "text", i,
397
 
                                                     NULL);
398
 
                gtk_tree_view_column_set_title (column, _(titles[i]));
399
 
                gtk_tree_view_column_set_sort_column_id (column, i);
400
 
                gtk_tree_view_column_set_resizable (column, TRUE);
401
 
 
 
404
                // sizing
402
405
                switch (i) {
403
406
                case COL_ARGS:
404
 
                        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
405
 
                        gtk_tree_view_column_set_min_width(column, 150);
406
 
                        break;
 
407
                  gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
 
408
                  gtk_tree_view_column_set_min_width(col, 150);
 
409
                  break;
407
410
                default:
408
411
                  gtk_tree_view_column_set_min_width(column, 20);
409
412
                  break;
410
413
                }
411
 
 
412
 
                gtk_tree_view_append_column (GTK_TREE_VIEW (proctree), column);
413
414
        }
414
415
 
415
416
        gtk_container_add (GTK_CONTAINER (scrolled), proctree);
419
420
        {
420
421
                switch(i)
421
422
                {
422
 
                case COL_VMSIZE:
423
 
                case COL_MEMRES:
424
 
                case COL_MEMWRITABLE:
425
 
                case COL_MEMSHARED:
426
 
                case COL_MEMXSERVER:
427
423
                case COL_CPU_TIME:
428
424
                case COL_START_TIME:
429
425
                case COL_CPU:
430
 
                case COL_MEM:
431
426
                        gtk_tree_sortable_set_sort_func (
432
427
                                GTK_TREE_SORTABLE (model),
433
428
                                i,
650
645
        GtkTreeModel *model;
651
646
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(procdata->tree));
652
647
 
653
 
        gchar *vmsize, *memres, *memwritable, *memshared, *memxserver,
654
 
                *cpu_time, *start_time, *mem;
655
 
 
656
 
        vmsize     = SI_gnome_vfs_format_file_size_for_display (info->vmsize);
657
 
        memres     = SI_gnome_vfs_format_file_size_for_display (info->memres);
658
 
        memwritable = SI_gnome_vfs_format_file_size_for_display (info->memwritable);
659
 
        memshared  = SI_gnome_vfs_format_file_size_for_display (info->memshared);
660
 
        memxserver = SI_gnome_vfs_format_file_size_for_display (info->memxserver);
661
 
        mem = SI_gnome_vfs_format_file_size_for_display(info->mem);
 
648
        gchar *cpu_time, *start_time;
662
649
 
663
650
        // expects centiseconds
664
651
        cpu_time = format_duration_for_display(100 * info->cpu_time_last / procdata->frequency);
670
657
        gtk_tree_store_set(GTK_TREE_STORE(model), &info->node,
671
658
                            COL_STATUS, info->status,
672
659
                            COL_USER, info->user,
673
 
                            COL_VMSIZE, vmsize,
674
 
                            COL_MEMRES, memres,
675
 
                            COL_MEMWRITABLE, memwritable,
676
 
                            COL_MEMSHARED, memshared,
677
 
                            COL_MEMXSERVER, memxserver,
 
660
                            COL_VMSIZE, info->vmsize,
 
661
                            COL_MEMRES, info->memres,
 
662
                            COL_MEMWRITABLE, info->memwritable,
 
663
                            COL_MEMSHARED, info->memshared,
 
664
                            COL_MEMXSERVER, info->memxserver,
678
665
                            COL_CPU, guint(info->pcpu),
679
666
                            COL_CPU_TIME, cpu_time,
680
667
                            COL_START_TIME, start_time,
681
668
                            COL_NICE, gint(info->nice),
682
 
                            COL_MEM, mem,
 
669
                            COL_MEM, info->mem,
683
670
                            -1);
684
671
 
685
672
        /* FIXME: We don't bother updating COL_SECURITYCONTEXT as it can never change.
686
673
           even on fork ? */
687
 
        g_free (vmsize);
688
 
        g_free (memres);
689
 
        g_free (memwritable);
690
 
        g_free (memshared);
691
 
        g_free (memxserver);
692
674
        g_free (cpu_time);
693
675
        g_free(start_time);
694
 
        g_free(mem);
695
676
}
696
677
 
697
678
 
698
679
 
699
680
static void
700
 
insert_info_to_tree (ProcInfo *info, ProcData *procdata)
 
681
insert_info_to_tree (ProcInfo *info, ProcData *procdata, bool forced = false)
701
682
{
702
683
        GtkTreeModel *model;
703
684
 
705
686
 
706
687
        if (procdata->config.show_tree) {
707
688
 
708
 
          ProcInfo *parent = ProcInfo::find(info->ppid);
 
689
          ProcInfo *parent = 0;
 
690
 
 
691
          if (not forced)
 
692
            parent = ProcInfo::find(info->ppid);
709
693
 
710
694
          if (parent) {
711
695
            GtkTreePath *parent_node = gtk_tree_model_get_path(model, &parent->node);
734
718
                            COL_PID, info->pid,
735
719
                            COL_SECURITYCONTEXT, info->security_context,
736
720
                            -1);
 
721
 
 
722
        procman_debug("inserted %d%s", info->pid, (forced ? " (forced)" : ""));
737
723
}
738
724
 
739
725
 
797
783
        info->pcpu = (proctime.rtime - info->cpu_time_last) * 100 / total_time;
798
784
        info->pcpu = MIN(info->pcpu, 100);
799
785
 
 
786
        if (procdata->config.solaris_mode)
 
787
          info->pcpu /= procdata->config.num_cpus;
 
788
 
800
789
        info->cpu_time_last = proctime.rtime;
801
790
        info->nice = procuid.nice;
802
791
        info->ppid = procuid.ppid;
889
878
          it = next;
890
879
        }
891
880
 
 
881
        // INVARIANT
 
882
        // pid_list == ProcInfo::all + addition
 
883
 
 
884
 
 
885
        if (procdata->config.show_tree) {
 
886
 
892
887
        // insert process in the tree. walk through the addition list
893
888
        // (new process + process that have a new parent). This loop
894
889
        // handles the dependencies because we cannot insert a process
899
894
        for (ProcList::iterator it(addition.begin()); it != addition.end(); ++it)
900
895
          in_tree.erase((*it)->pid);
901
896
 
902
 
        unsigned rounds = 0;
903
897
 
904
898
        while (not addition.empty()) {
905
899
          procman_debug("looking for %d parents", int(addition.size()));
906
900
          ProcList::iterator it(addition.begin());
907
901
 
908
902
          while (it != addition.end()) {
909
 
            procman_debug("looking for %d's parent", int((*it)->pid));
 
903
            procman_debug("looking for %d's parent with ppid %d",
 
904
                          int((*it)->pid), int((*it)->ppid));
 
905
 
 
906
 
 
907
            // inserts the process in the treeview if :
 
908
            // - it is init
 
909
            // - its parent is already in tree
 
910
            // - its parent is unreachable
 
911
            //
 
912
            // rounds == 2 means that addition contains processes with
 
913
            // unreachable parents
 
914
            //
 
915
            // FIXME: this is broken if the unreachable parent becomes active
 
916
            // i.e. it gets active or changes ower
 
917
            // so we just clear the tree on __each__ update
 
918
            // see proctable_update_list (ProcData * const procdata)
 
919
 
 
920
 
910
921
            if ((*it)->ppid == 0 or in_tree.find((*it)->ppid) != in_tree.end()) {
911
922
              insert_info_to_tree(*it, procdata);
912
923
              in_tree.insert((*it)->pid);
913
924
              it = addition.erase(it);
914
 
              rounds = 0;
915
 
            } else
916
 
              ++it;
 
925
              continue;
 
926
            }
 
927
 
 
928
            ProcInfo *parent = ProcInfo::find((*it)->ppid);
 
929
            // if the parent is unreachable
 
930
            if (not parent) {
 
931
                // or std::find(addition.begin(), addition.end(), parent) == addition.end()) {
 
932
                insert_info_to_tree(*it, procdata, true);
 
933
                in_tree.insert((*it)->pid);
 
934
                it = addition.erase(it);
 
935
                continue;
 
936
            }
 
937
 
 
938
            ++it;
917
939
          }
918
 
 
919
 
          rounds++;
920
 
 
921
 
          // dead loop
922
 
          g_assert(rounds <= 2);
923
 
        }
 
940
        }
 
941
        }
 
942
        else { 
 
943
          // don't care of the tree
 
944
          for (ProcList::iterator it(addition.begin()); it != addition.end(); ++it)
 
945
            insert_info_to_tree(*it, procdata);
 
946
        }
 
947
 
924
948
 
925
949
        for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it)
926
950
                update_info_mutable_cols(it->second);
944
968
        case ACTIVE_PROCESSES:
945
969
                which = GLIBTOP_KERN_PROC_ALL | GLIBTOP_EXCLUDE_IDLE;
946
970
                arg = 0;
 
971
                proctable_clear_tree(procdata);
947
972
                break;
948
973
 
949
974
        default:
950
975
                which = GLIBTOP_KERN_PROC_UID;
951
976
                arg = getuid ();
 
977
                proctable_clear_tree(procdata);
952
978
                break;
953
979
        }
954
980