<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_stats_action(cachespec, interval):
 """Action for getting bcache statistics for a given cachespec. Cachespec can either be a device name, eg. 'sdb', which will retrieve cache stats for the given device, or 'global', which will retrieve stats for all cachesets """

    if cachespec == 'global':
        caches = get_bcache_fs()
    else:
        caches = [Bcache.fromdevice(cachespec)]
    res = dict((c.cachepath, c.get_stats(interval)) for c in caches)
    return json.dumps(res, indent=4, separators=(',', ': '))