Skip to contentSkip to conversation

cgroup: print pretty format in /proc/cgroups

PATCH In review Jianyu Zhan 4 participants 5 messages Apr 15, 2014 1 message not in the archive cgroup

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup: print pretty format in /proc/cgroups

I found that /proc/cgroups printed format has ugly alignment(see below).

This patch confines every field in fixed-width(16 actually) range. Though MAX_CGROUP_TYPE_NAMELEN is 32, but currently no subsystem has name width more than 10, so 16 is a moderate width; besides, 16 figures could accomandate enormous huge number, so no need to worry that these fields would clobber each other.

Before:
#subsys_name hierarchy num_cgroups enabled
cpuset 2 1 1
cpu 3 1 1
cpuacct 3 1 1
memory 4 1 1
devices 5 1 1
freezer 6 1 1
net_cls 7 1 1
blkio 8 1 1
perf_event 9 1 1
hugetlb 10 1 1

Patch applied:
#subsys_name hierarchy num_cgroups enabled

  cpuset          2               1               1
  cpu             3               1               1
  cpuacct         3               1               1
  memory          4               1               1
  devices         5               1               1
  freezer         6               1               1
  net_cls         7               1               1
  blkio           8               1               1
  perf_event      9               1               1
  hugetlb         10              1               1
---
 kernel/cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup.c +1 -1
index 9fcdaa7..d981697 100644
@@ -4347,7 +4347,7 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v)
 	mutex_lock(&cgroup_mutex);
 
 	for_each_subsys(ss, i)
-		seq_printf(m, "%s\t%d\t%d\t%d\n",
+		seq_printf(m, "%-16s%-16d%-16d%-16d\n",
 			   ss->name, ss->root->hierarchy_id,
 			   atomic_read(&ss->root->nr_cgrps), !ss->disabled);
 
Signature · 1 line
1.9.0.GIT
maintainer
#1 lore raw
Quoted 7 lines · Jianyu Zhan

I found that /proc/cgroups printed format has ugly alignment(see below).

This patch confines every field in fixed-width(16 actually) range. Though MAX_CGROUP_TYPE_NAMELEN is 32, but currently no subsystem has name width more than 10, so 16 is a moderate width; besides, 16 figures could accomandate enormous huge number, so no need to worry that these fields would clobber each other.

The problem there is that there could be programs / scripts parsing it assuming single tab between entries. It surely is ugly but do we care?

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 3 lines · Tejun Heo

The problem there is that there could be programs / scripts parsing it assuming single tab between entries. It surely is ugly but do we care?

Oh, you are right. It is an exposed user interface. This will make lots of administrator unhappy ;-(

Thanks,
Jianyu Zhan

A message that is not in the archive (sent off-list or not yet received): 20140415125111.GG1863-Gd/HAXX7CRxy/[email protected]

#4 lore raw
Quoted 3 lines · Tejun Heo

The problem there is that there could be programs / scripts parsing it assuming single tab between entries. It surely is ugly but do we care?

Oh, you are right. It is an exposed user interface. This will make lots of administrator unhappy ;-(

Thanks,
Jianyu Zhan

#5 lore raw
In reply to Jianyu Zhan
Quoted 1 line · Jianyu Zhan

I found that /proc/cgroups printed format has ugly alignment(see below).

[snip]

kernel/cgroup.c static int proc_cgroupstats_show(struct seq_file *m, void *v) · line 4352

Quoted 12 lines
kernel/cgroup.c +1 -1
index 9fcdaa7..d981697 100644
@@ -4347,7 +4347,7 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v)
 	mutex_lock(&cgroup_mutex);
 
 	for_each_subsys(ss, i)
-		seq_printf(m, "%s\t%d\t%d\t%d\n",
+		seq_printf(m, "%-16s%-16d%-16d%-16d\n",
 			   ss->name, ss->root->hierarchy_id,
 			   atomic_read(&ss->root->nr_cgrps), !ss->disabled);

This is liable to break userspace apps which might currently parse the file by splitting on '\t'

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|