~ubuntuone-support/+junk/syncdaemon-perftest

« back to all changes in this revision

Viewing changes to dropbox-perftest.py

  • Committer: Roman Yepishev
  • Date: 2012-04-02 10:28:38 UTC
  • Revision ID: roman.yepishev@canonical.com-20120402102838-cftyw8c8754a1rrj
Latest version of the scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
            raise Exception("Timeout")
74
74
 
75
75
    def run(self, options):
76
 
        self.file_count = int(options.file_count)
77
 
        self.file_size_randomize = False
78
 
 
79
 
        if options.file_size.startswith('..'):
80
 
            self.file_size = int(options.file_size[2:])
81
 
            self.file_size_randomize = True
82
 
        else:
83
 
            self.file_size = int(options.file_size)
84
 
 
85
 
        self.track_speed = options.track_speed
86
 
        self.track_queues = options.track_queues
87
 
 
88
 
        self.logger = setup_logging(options.log)
89
 
 
90
 
        statsd_info = options.statsd
91
 
        self._setup_metrics(statsd_info, options.graph_prefix)
92
 
 
93
 
        if options.timeout:
94
 
            self.timeout = int(options.timeout)
 
76
        self._parse_common_options(options)
95
77
 
96
78
        path_to_file = TESTDIR
97
79
        self.root = os.path.join(os.getenv('HOME'), 'Dropbox')
112
94
 
113
95
        self.logger.info("Dropbox is idle")
114
96
 
115
 
        current_path = self.root
116
 
 
117
97
        time_created = time.time()
118
98
 
119
 
        for node in path_to_file.split('/'):
120
 
            current_path = os.path.join(current_path, node)
121
 
            os.mkdir(current_path)
122
 
 
123
 
        rnd = open("/dev/urandom", "r")
124
 
 
125
 
        for file_id in range(self.file_count):
126
 
            path = os.path.join(current_path, u"file%d.bin" % (file_id, ))
127
 
            if self.file_size_randomize:
128
 
                size = randint(0, self.file_size)
129
 
            else:
130
 
                size = self.file_size
131
 
 
132
 
            fh = open(path, "w")
133
 
 
134
 
            while size > 0:
135
 
                result = rnd.read(1024)
136
 
                fh.write(result)
137
 
                size = size - len(result)
138
 
 
139
 
            fh.close()
140
 
 
141
 
        rnd.close()
142
 
 
143
 
        self.logger.info("Waiting for dropbox to stop being idle")
144
 
        while self.client.status()[1] != 'Idle':
145
 
            self._check_timeout()
146
 
            time.sleep(1)
 
99
        # ensuring that dropbox is disconnected before generating the files to
 
100
        # avoid unlimited speed readings
 
101
        self.client.stop()
 
102
 
 
103
        self._generate_files(TESTDIR)
 
104
 
 
105
        self.client.start()
147
106
 
148
107
        self.logger.info("Dropbox is working, waiting to become idle")
149
108