~jamalta/unity/687956-tooltip-timeout

« back to all changes in this revision

Viewing changes to libunity/perf-logger.vala

  • Committer: Gord Allott
  • Date: 2010-12-09 13:30:35 UTC
  • mfrom: (636.8.2 unity-perf)
  • mto: This revision was merged to the branch mainline in revision 687.
  • Revision ID: gord.allott@canonical.com-20101209133035-suje7kmkld6ocvy6
adds boot perf logging to unity and libunity

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2009 Canonical Ltd
 
2
 * Copyright (C) 2009-2010 Canonical Ltd
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License version 3 as
17
17
 *
18
18
 */
19
19
 
20
 
namespace Unity
 
20
namespace Perf
21
21
{
22
 
  
23
22
  public class ProcessInfo
24
23
  {
25
24
    public ProcessInfo (string name)
32
31
    public double start;
33
32
    public double end;
34
33
  }
35
 
  
 
34
 
36
35
  public static TimelineLogger? timeline_singleton;
37
 
  public static bool is_logging; 
38
 
  
 
36
  public static bool is_logging;
 
37
 
39
38
  public class TimelineLogger : Object
40
39
  {
41
40
    private Timer global_timer;
42
41
    private Gee.HashMap<string, ProcessInfo> process_map;
43
 
    
44
 
    public static unowned Unity.TimelineLogger get_default ()
 
42
 
 
43
    public static unowned Perf.TimelineLogger get_default ()
45
44
    {
46
 
      if (Unity.timeline_singleton == null)
 
45
      if (Perf.timeline_singleton == null)
47
46
      {
48
 
        Unity.timeline_singleton = new Unity.TimelineLogger ();
 
47
        Perf.timeline_singleton = new Perf.TimelineLogger ();
49
48
      }
50
 
      
51
 
      return Unity.timeline_singleton;
 
49
 
 
50
      return Perf.timeline_singleton;
52
51
    }
53
 
    
 
52
 
54
53
    construct
55
54
    {
56
55
      this.process_map = new Gee.HashMap<string, ProcessInfo> ();
57
 
      this.global_timer = new Timer ();      
 
56
      this.global_timer = new Timer ();
58
57
      this.global_timer.start ();
59
58
    }
60
 
    
 
59
 
61
60
    public void start_process (string name)
62
61
    {
 
62
      debug ("shoop de whoop");
63
63
      if (name in this.process_map.keys)
64
64
      {
65
65
        warning ("already started process: %s", name);
66
66
        return;
67
67
      }
68
 
      
 
68
 
69
69
      var info = new ProcessInfo (name);
70
70
      this.process_map[name] = info;
71
71
      info.start = this.global_timer.elapsed ();
72
72
    }
73
 
    
 
73
 
74
74
    public void end_process (string name)
75
75
    {
 
76
      debug ("shonk le donk");
76
77
      double end_time = this.global_timer.elapsed ();
77
 
      
 
78
      print ("the end time is %f", end_time);
 
79
 
78
80
      if (name in this.process_map.keys)
79
81
      {
80
82
        this.process_map[name].end = end_time;
81
83
      }
82
 
      else 
 
84
      else
83
85
      {
84
86
        warning ("process %s not started", name);
85
87
      }
86
88
    }
87
 
    
 
89
 
88
90
    public void write_log (string filename)
89
91
    {
90
92
      debug ("Writing performance log file: %s...", filename);
91
93
      var log_file = File.new_for_path (filename);
92
94
      FileOutputStream file_stream;
93
 
      try 
 
95
      try
94
96
      {
95
97
        if (!log_file.query_exists (null)) {
96
98
          file_stream = log_file.create (FileCreateFlags.NONE, null);
97
99
        }
98
 
        else 
 
100
        else
99
101
        {
100
102
          file_stream = log_file.replace (null, false, FileCreateFlags.NONE, null);
101
103
        }
102
 
        
 
104
 
103
105
        var output_stream = new DataOutputStream (file_stream);
104
 
        
 
106
 
105
107
        foreach (ProcessInfo info in this.process_map.values)
106
108
        {
107
 
          string outline = "%s, %f, %f\n".printf(info.name, info.start, info.end);
108
 
            output_stream.put_string (outline, null); 
 
109
          string name = info.name.replace (",", ";");
 
110
          string outline = "%s, %f, %f\n".printf(name, info.start, info.end);
 
111
            output_stream.put_string (outline, null);
109
112
        }
110
 
        
 
113
 
111
114
        file_stream.close (null);
112
115
      } catch (Error e)
113
116
      {